diff options
author | Lorenz Diener <[email protected]> | 2019-10-12 19:05:46 +0200 |
---|---|---|
committer | Lorenz Diener <[email protected]> | 2019-10-12 19:05:46 +0200 |
commit | 73c1e9e2d99bc76ffe4320b0a9045562613789ac (patch) | |
tree | a3d7dbe357988748ea3c795d949ab155052ed01c | |
parent | 425fd29f153b812e92eaf1649275685e52dc7c66 (diff) | |
download | mastodon.py-73c1e9e2d99bc76ffe4320b0a9045562613789ac.tar.gz |
Add me()-function to return user account. Fixes #184
-rw-r--r-- | docs/index.rst | 1 | ||||
-rw-r--r-- | mastodon/Mastodon.py | 9 | ||||
-rw-r--r-- | tests/cassettes/test_verify_credentials.yaml | 56 | ||||
-rw-r--r-- | tests/test_account.py | 8 |
4 files changed, 73 insertions, 1 deletions
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. | |||
895 | 895 | ||
896 | .. automethod:: Mastodon.account | 896 | .. automethod:: Mastodon.account |
897 | .. automethod:: Mastodon.account_verify_credentials | 897 | .. automethod:: Mastodon.account_verify_credentials |
898 | .. automethod:: Mastodon.me | ||
898 | .. automethod:: Mastodon.account_statuses | 899 | .. automethod:: Mastodon.account_statuses |
899 | .. automethod:: Mastodon.account_following | 900 | .. automethod:: Mastodon.account_following |
900 | .. automethod:: Mastodon.account_followers | 901 | .. 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: | |||
966 | """ | 966 | """ |
967 | return self.__api_request('GET', '/api/v1/accounts/verify_credentials') | 967 | return self.__api_request('GET', '/api/v1/accounts/verify_credentials') |
968 | 968 | ||
969 | @api_version("1.0.0", "2.1.0", __DICT_VERSION_ACCOUNT) | ||
970 | def me(self): | ||
971 | """ | ||
972 | Get this users account. Symonym for `account_verify_credentials()`, does exactly | ||
973 | the same thing, just exists becase `account_verify_credentials()` has a confusing | ||
974 | name. | ||
975 | """ | ||
976 | return self.account_verify_credentials() | ||
977 | |||
969 | @api_version("1.0.0", "2.7.0", __DICT_VERSION_STATUS) | 978 | @api_version("1.0.0", "2.7.0", __DICT_VERSION_STATUS) |
970 | def account_statuses(self, id, only_media=False, pinned=False, exclude_replies=False, max_id=None, min_id=None, since_id=None, limit=None): | 979 | def account_statuses(self, id, only_media=False, pinned=False, exclude_replies=False, max_id=None, min_id=None, since_id=None, limit=None): |
971 | """ | 980 | """ |
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 @@ | |||
1 | interactions: | ||
2 | - request: | ||
3 | body: null | ||
4 | headers: | ||
5 | Accept: ['*/*'] | ||
6 | Accept-Encoding: ['gzip, deflate'] | ||
7 | Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN] | ||
8 | Connection: [keep-alive] | ||
9 | User-Agent: [python-requests/2.18.4] | ||
10 | method: GET | ||
11 | uri: http://localhost:3000/api/v1/accounts/verify_credentials | ||
12 | response: | ||
13 | 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":[]}'} | ||
14 | headers: | ||
15 | Cache-Control: ['no-cache, no-store'] | ||
16 | Content-Type: [application/json; charset=utf-8] | ||
17 | Referrer-Policy: [strict-origin-when-cross-origin] | ||
18 | Transfer-Encoding: [chunked] | ||
19 | Vary: ['Accept-Encoding, Origin'] | ||
20 | X-Content-Type-Options: [nosniff] | ||
21 | X-Download-Options: [noopen] | ||
22 | X-Frame-Options: [SAMEORIGIN] | ||
23 | X-Permitted-Cross-Domain-Policies: [none] | ||
24 | X-Request-Id: [8827e9e0-5d9c-4a85-a171-ac8e07b78716] | ||
25 | X-Runtime: ['0.075559'] | ||
26 | X-XSS-Protection: [1; mode=block] | ||
27 | content-length: ['724'] | ||
28 | status: {code: 200, message: OK} | ||
29 | - request: | ||
30 | body: null | ||
31 | headers: | ||
32 | Accept: ['*/*'] | ||
33 | Accept-Encoding: ['gzip, deflate'] | ||
34 | Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN] | ||
35 | Connection: [keep-alive] | ||
36 | User-Agent: [python-requests/2.18.4] | ||
37 | method: GET | ||
38 | uri: http://localhost:3000/api/v1/accounts/verify_credentials | ||
39 | response: | ||
40 | 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":[]}'} | ||
41 | headers: | ||
42 | Cache-Control: ['no-cache, no-store'] | ||
43 | Content-Type: [application/json; charset=utf-8] | ||
44 | Referrer-Policy: [strict-origin-when-cross-origin] | ||
45 | Transfer-Encoding: [chunked] | ||
46 | Vary: ['Accept-Encoding, Origin'] | ||
47 | X-Content-Type-Options: [nosniff] | ||
48 | X-Download-Options: [noopen] | ||
49 | X-Frame-Options: [SAMEORIGIN] | ||
50 | X-Permitted-Cross-Domain-Policies: [none] | ||
51 | X-Request-Id: [7b015ff5-ebbe-4cfe-a7a2-4ebfc946a566] | ||
52 | X-Runtime: ['0.024838'] | ||
53 | X-XSS-Protection: [1; mode=block] | ||
54 | content-length: ['724'] | ||
55 | status: {code: 200, message: OK} | ||
56 | 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): | |||
7 | account = api.account(1) | 7 | account = api.account(1) |
8 | assert account | 8 | assert account |
9 | 9 | ||
10 | 10 | @pytest.mark.vcr() | |
11 | def test_verify_credentials(api): | ||
12 | account_a = api.account_verify_credentials() | ||
13 | account_b = api.me() | ||
14 | |||
15 | assert account_a.id == account_b.id | ||
16 | |||
11 | @pytest.mark.vcr() | 17 | @pytest.mark.vcr() |
12 | def test_account_following(api): | 18 | def test_account_following(api): |
13 | following = api.account_following(1) | 19 | following = api.account_following(1) |