From 73c1e9e2d99bc76ffe4320b0a9045562613789ac Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Sat, 12 Oct 2019 19:05:46 +0200 Subject: Add me()-function to return user account. Fixes #184 --- docs/index.rst | 1 + mastodon/Mastodon.py | 9 +++++ tests/cassettes/test_verify_credentials.yaml | 56 ++++++++++++++++++++++++++++ tests/test_account.py | 8 +++- 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 tests/cassettes/test_verify_credentials.yaml diff --git a/docs/index.rst b/docs/index.rst index 399927c..183f271 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -895,6 +895,7 @@ their relationships. .. automethod:: Mastodon.account .. automethod:: Mastodon.account_verify_credentials +.. automethod:: Mastodon.me .. automethod:: Mastodon.account_statuses .. automethod:: Mastodon.account_following .. automethod:: Mastodon.account_followers diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index c84ac6a..4551cbf 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -966,6 +966,15 @@ class Mastodon: """ 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) def account_statuses(self, id, only_media=False, pinned=False, exclude_replies=False, max_id=None, min_id=None, since_id=None, limit=None): """ diff --git a/tests/cassettes/test_verify_credentials.yaml b/tests/cassettes/test_verify_credentials.yaml new file mode 100644 index 0000000..b694c7f --- /dev/null +++ b/tests/cassettes/test_verify_credentials.yaml @@ -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 diff --git a/tests/test_account.py b/tests/test_account.py index 9821c13..55f766f 100644 --- a/tests/test_account.py +++ b/tests/test_account.py @@ -7,7 +7,13 @@ def test_account(api): account = api.account(1) 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() def test_account_following(api): following = api.account_following(1) -- cgit v1.2.3