Add me()-function to return user account. Fixes #184

This commit is contained in:
Lorenz Diener 2019-10-12 19:05:46 +02:00
pare 425fd29f15
commit 73c1e9e2d9
S'han modificat 4 arxius amb 73 adicions i 1 eliminacions

Veure arxiu

@ -895,6 +895,7 @@ their relationships.
.. automethod:: Mastodon.account .. automethod:: Mastodon.account
.. automethod:: Mastodon.account_verify_credentials .. automethod:: Mastodon.account_verify_credentials
.. automethod:: Mastodon.me
.. automethod:: Mastodon.account_statuses .. automethod:: Mastodon.account_statuses
.. automethod:: Mastodon.account_following .. automethod:: Mastodon.account_following
.. automethod:: Mastodon.account_followers .. automethod:: Mastodon.account_followers

Veure arxiu

@ -966,6 +966,15 @@ class Mastodon:
""" """
return self.__api_request('GET', '/api/v1/accounts/verify_credentials') return self.__api_request('GET', '/api/v1/accounts/verify_credentials')
@api_version("1.0.0", "2.1.0", __DICT_VERSION_ACCOUNT)
def me(self):
"""
Get this users account. Symonym for `account_verify_credentials()`, does exactly
the same thing, just exists becase `account_verify_credentials()` has a confusing
name.
"""
return self.account_verify_credentials()
@api_version("1.0.0", "2.7.0", __DICT_VERSION_STATUS) @api_version("1.0.0", "2.7.0", __DICT_VERSION_STATUS)
def account_statuses(self, id, only_media=False, pinned=False, exclude_replies=False, max_id=None, min_id=None, since_id=None, limit=None): def account_statuses(self, id, only_media=False, pinned=False, exclude_replies=False, max_id=None, min_id=None, since_id=None, limit=None):
""" """

Veure arxiu

@ -0,0 +1,56 @@
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/accounts/verify_credentials
response:
body: {string: '{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":false,"bot":false,"created_at":"2019-06-22T23:11:52.441Z","note":"\u003cp\u003e\u003c/p\u003e","url":"http://localhost/@mastodonpy_test","avatar":"http://localhost/avatars/original/missing.png","avatar_static":"http://localhost/avatars/original/missing.png","header":"http://localhost/headers/original/missing.png","header_static":"http://localhost/headers/original/missing.png","followers_count":0,"following_count":1,"statuses_count":2,"last_status_at":"2019-10-11T21:50:54.637Z","source":{"privacy":"public","sensitive":false,"language":null,"note":"","fields":[],"follow_requests_count":0},"emojis":[],"fields":[]}'}
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: [8827e9e0-5d9c-4a85-a171-ac8e07b78716]
X-Runtime: ['0.075559']
X-XSS-Protection: [1; mode=block]
content-length: ['724']
status: {code: 200, message: OK}
- 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/accounts/verify_credentials
response:
body: {string: '{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":false,"bot":false,"created_at":"2019-06-22T23:11:52.441Z","note":"\u003cp\u003e\u003c/p\u003e","url":"http://localhost/@mastodonpy_test","avatar":"http://localhost/avatars/original/missing.png","avatar_static":"http://localhost/avatars/original/missing.png","header":"http://localhost/headers/original/missing.png","header_static":"http://localhost/headers/original/missing.png","followers_count":0,"following_count":1,"statuses_count":2,"last_status_at":"2019-10-11T21:50:54.637Z","source":{"privacy":"public","sensitive":false,"language":null,"note":"","fields":[],"follow_requests_count":0},"emojis":[],"fields":[]}'}
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: [7b015ff5-ebbe-4cfe-a7a2-4ebfc946a566]
X-Runtime: ['0.024838']
X-XSS-Protection: [1; mode=block]
content-length: ['724']
status: {code: 200, message: OK}
version: 1

Veure arxiu

@ -7,6 +7,12 @@ def test_account(api):
account = api.account(1) account = api.account(1)
assert account assert account
@pytest.mark.vcr()
def test_verify_credentials(api):
account_a = api.account_verify_credentials()
account_b = api.me()
assert account_a.id == account_b.id
@pytest.mark.vcr() @pytest.mark.vcr()
def test_account_following(api): def test_account_following(api):