Re-add and test trends API

This commit is contained in:
Lorenz Diener 2019-10-12 21:02:39 +02:00
pare 2e5095f301
commit 3194b1295e
S'han modificat 4 arxius amb 61 adicions i 0 eliminacions

Veure arxiu

@ -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

Veure arxiu

@ -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
###

Veure arxiu

@ -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

Veure arxiu

@ -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)