From 3194b1295e8f4a6d151d18ad4f23174c63408c05 Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Sat, 12 Oct 2019 21:02:39 +0200 Subject: [PATCH] Re-add and test trends API --- docs/index.rst | 5 +++++ mastodon/Mastodon.py | 22 ++++++++++++++++++++++ tests/cassettes/test_trends.yaml | 29 +++++++++++++++++++++++++++++ tests/test_instance.py | 5 +++++ 4 files changed, 61 insertions(+) create mode 100644 tests/cassettes/test_trends.yaml diff --git a/docs/index.rst b/docs/index.rst index 0ec0f75..c0aebb7 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -949,6 +949,11 @@ Reading data: Searching .. automethod:: Mastodon.search .. automethod:: Mastodon.search_v2 +Reading data: Trends +-------------------- + +.. automethod:: Mastodon.trends + Reading data: Mutes and blocks ------------------------------ These functions allow you to get information about accounts that are diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 1561fa1..899aae4 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -1312,6 +1312,28 @@ class Mastodon: return self.__api_request('GET', '/api/v2/search', params) + ### + # Reading data: Trends + ### + @api_version("2.4.3", "3.0.0", __DICT_VERSION_HASHTAG) + def trends(self, limit = None): + """ + Fetch trending-hashtag information, if the instance provides such information. + + Specify `limit` to limit how many results are returned (the maximum number + of results is 10, the endpoint is not paginated). + + Does not require authentication unless locked down by the administrator. + + Important versioning note: This endpoint does not exist for Mastodon versions + between 2.8.0 (inclusive) and 3.0.0 (exclusive). + + Returns a list of `hashtag dicts`_, sorted by the instances trending algorithm, + descending. + """ + params = self.__generate_params(locals()) + return self.__api_request('GET', '/api/v1/trends', params) + ### # Reading data: Lists ### diff --git a/tests/cassettes/test_trends.yaml b/tests/cassettes/test_trends.yaml new file mode 100644 index 0000000..15cfd9b --- /dev/null +++ b/tests/cassettes/test_trends.yaml @@ -0,0 +1,29 @@ +interactions: +- request: + body: null + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN] + Connection: [keep-alive] + User-Agent: [python-requests/2.18.4] + method: GET + uri: http://localhost:3000/api/v1/trends + response: + body: {string: '[]'} + headers: + Cache-Control: ['no-cache, no-store'] + Content-Type: [application/json; charset=utf-8] + Referrer-Policy: [strict-origin-when-cross-origin] + Transfer-Encoding: [chunked] + Vary: ['Accept-Encoding, Origin'] + X-Content-Type-Options: [nosniff] + X-Download-Options: [noopen] + X-Frame-Options: [SAMEORIGIN] + X-Permitted-Cross-Domain-Policies: [none] + X-Request-Id: [cd891bac-8b4d-476e-b767-2346ff6f498e] + X-Runtime: ['0.074803'] + X-XSS-Protection: [1; mode=block] + content-length: ['2'] + status: {code: 200, message: OK} +version: 1 diff --git a/tests/test_instance.py b/tests/test_instance.py index 343af18..e7dee1f 100644 --- a/tests/test_instance.py +++ b/tests/test_instance.py @@ -43,3 +43,8 @@ def test_nodeinfo(api): assert nodeinfo assert nodeinfo.version == '2.0' + +@pytest.mark.vcr() +def test_trends(api): + assert isinstance(api.trends(), list) +