diff options
-rw-r--r-- | docs/index.rst | 18 | ||||
-rw-r--r-- | mastodon/Mastodon.py | 39 | ||||
-rw-r--r-- | mastodon/__init__.py | 3 | ||||
-rw-r--r-- | tests/cassettes/test_conversations.yaml | 143 | ||||
-rw-r--r-- | tests/test_timeline.py | 14 |
5 files changed, 209 insertions, 8 deletions
diff --git a/docs/index.rst b/docs/index.rst index 4efebc6..9bbd6f7 100644 --- a/docs/index.rst +++ b/docs/index.rst | |||
@@ -329,6 +329,23 @@ Mention dicts | |||
329 | 'id': # Mentioned users (local) account ID | 329 | 'id': # Mentioned users (local) account ID |
330 | } | 330 | } |
331 | 331 | ||
332 | Conversation dicts | ||
333 | ~~~~~~~~~~~~~~~~~~ | ||
334 | .. _conversation dict: | ||
335 | |||
336 | .. code-block:: python | ||
337 | |||
338 | mastodon.conversations()[0] | ||
339 | # Returns the following dictionary: | ||
340 | { | ||
341 | 'id': # The ID of this conversation object | ||
342 | 'unread': # Boolean indicating whether this conversation has yet to be | ||
343 | # read by the user | ||
344 | 'accounts': # List of accounts (other than the logged-in account) that | ||
345 | # are part of this conversation | ||
346 | 'last_status': # The newest status in this conversation | ||
347 | } | ||
348 | |||
332 | Hashtag dicts | 349 | Hashtag dicts |
333 | ~~~~~~~~~~~~~ | 350 | ~~~~~~~~~~~~~ |
334 | .. _hashtag dict: | 351 | .. _hashtag dict: |
@@ -718,6 +735,7 @@ and local timelines. | |||
718 | .. _timeline_hashtag(): | 735 | .. _timeline_hashtag(): |
719 | .. automethod:: Mastodon.timeline_hashtag | 736 | .. automethod:: Mastodon.timeline_hashtag |
720 | .. automethod:: Mastodon.timeline_list | 737 | .. automethod:: Mastodon.timeline_list |
738 | .. automethod:: Mastodon.conversations | ||
721 | 739 | ||
722 | Reading data: Statuses | 740 | Reading data: Statuses |
723 | ---------------------- | 741 | ---------------------- |
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 1104028..6897bc6 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -127,7 +127,6 @@ class Mastodon: | |||
127 | 'read:lists', | 127 | 'read:lists', |
128 | 'read:mutes', | 128 | 'read:mutes', |
129 | 'read:notifications', | 129 | 'read:notifications', |
130 | 'read:reports', | ||
131 | 'read:search', | 130 | 'read:search', |
132 | 'read:statuses' | 131 | 'read:statuses' |
133 | ], | 132 | ], |
@@ -179,6 +178,7 @@ class Mastodon: | |||
179 | __DICT_VERSION_PUSH = "2.4.0" | 178 | __DICT_VERSION_PUSH = "2.4.0" |
180 | __DICT_VERSION_PUSH_NOTIF = "2.4.0" | 179 | __DICT_VERSION_PUSH_NOTIF = "2.4.0" |
181 | __DICT_VERSION_FILTER = "2.4.3" | 180 | __DICT_VERSION_FILTER = "2.4.3" |
181 | __DICT_VERSION_CONVERSATION = bigger_version(bigger_version("2.6.0", __DICT_VERSION_ACCOUNT), __DICT_VERSION_STATUS) | ||
182 | 182 | ||
183 | ### | 183 | ### |
184 | # Registering apps | 184 | # Registering apps |
@@ -649,6 +649,25 @@ class Mastodon: | |||
649 | return self.timeline('list/{0}'.format(id), max_id=max_id, | 649 | return self.timeline('list/{0}'.format(id), max_id=max_id, |
650 | min_id=min_id, since_id=since_id, limit=limit) | 650 | min_id=min_id, since_id=since_id, limit=limit) |
651 | 651 | ||
652 | @api_version("2.6.0", "2.6.0", __DICT_VERSION_CONVERSATION) | ||
653 | def conversations(self, max_id=None, min_id=None, since_id=None, limit=None): | ||
654 | """ | ||
655 | Fetches a users conversations. | ||
656 | |||
657 | Returns a list of `conversation dicts`_. | ||
658 | """ | ||
659 | if max_id != None: | ||
660 | max_id = self.__unpack_id(max_id) | ||
661 | |||
662 | if min_id != None: | ||
663 | min_id = self.__unpack_id(min_id) | ||
664 | |||
665 | if since_id != None: | ||
666 | since_id = self.__unpack_id(since_id) | ||
667 | |||
668 | params = self.__generate_params(locals()) | ||
669 | return self.__api_request('GET', "/api/v1/conversations/", params) | ||
670 | |||
652 | ### | 671 | ### |
653 | # Reading data: Statuses | 672 | # Reading data: Statuses |
654 | ### | 673 | ### |
@@ -1782,22 +1801,30 @@ class Mastodon: | |||
1782 | ### | 1801 | ### |
1783 | # Writing data: Reports | 1802 | # Writing data: Reports |
1784 | ### | 1803 | ### |
1785 | @api_version("1.1.0", "1.1.0", __DICT_VERSION_REPORT) | 1804 | @api_version("1.1.0", "2.5.0", __DICT_VERSION_REPORT) |
1786 | def report(self, account_id, status_ids, comment): | 1805 | def report(self, account_id, status_ids = None, comment = None, forward = False): |
1787 | """ | 1806 | """ |
1788 | Report statuses to the instances administrators. | 1807 | Report statuses to the instances administrators. |
1789 | 1808 | ||
1790 | Accepts a list of toot IDs associated with the report, and a comment. | 1809 | Accepts a list of toot IDs associated with the report, and a comment. |
1810 | |||
1811 | Set forward to True to forward a report of a remote user to that users | ||
1812 | instance as well as sending it to the instance local administrators. | ||
1791 | 1813 | ||
1792 | Returns a `report dict`_. | 1814 | Returns a `report dict`_. |
1793 | """ | 1815 | """ |
1794 | account_id = self.__unpack_id(account_id) | 1816 | account_id = self.__unpack_id(account_id) |
1795 | 1817 | ||
1796 | if not isinstance(status_ids, list): | 1818 | if not status_ids is None: |
1797 | status_ids = [status_ids] | 1819 | if not isinstance(status_ids, list): |
1820 | status_ids = [status_ids] | ||
1798 | status_ids = list(map(lambda x: self.__unpack_id(x), status_ids)) | 1821 | status_ids = list(map(lambda x: self.__unpack_id(x), status_ids)) |
1799 | 1822 | ||
1800 | params = self.__generate_params(locals()) | 1823 | params_initial = locals() |
1824 | if forward == False: | ||
1825 | del params_initial['forward'] | ||
1826 | |||
1827 | params = self.__generate_params(params_initial) | ||
1801 | return self.__api_request('POST', '/api/v1/reports/', params) | 1828 | return self.__api_request('POST', '/api/v1/reports/', params) |
1802 | 1829 | ||
1803 | ### | 1830 | ### |
diff --git a/mastodon/__init__.py b/mastodon/__init__.py index 21de9ae..1b2103f 100644 --- a/mastodon/__init__.py +++ b/mastodon/__init__.py | |||
@@ -1,4 +1,5 @@ | |||
1 | from mastodon.Mastodon import Mastodon, AttribAccessDict, MastodonError, MastodonVersionError, MastodonIllegalArgumentError, MastodonIOError, MastodonFileNotFoundError, MastodonNetworkError, MastodonAPIError, MastodonNotFoundError, MastodonUnauthorizedError, MastodonRatelimitError, MastodonMalformedEventError | 1 | from mastodon.Mastodon import Mastodon, AttribAccessDict, MastodonError, MastodonVersionError, MastodonIllegalArgumentError, MastodonIOError, MastodonFileNotFoundError, MastodonNetworkError, MastodonAPIError, MastodonNotFoundError, MastodonUnauthorizedError, MastodonRatelimitError, MastodonMalformedEventError |
2 | from mastodon.streaming import StreamListener, CallbackStreamListener | 2 | from mastodon.streaming import StreamListener, CallbackStreamListener |
3 | 3 | ||
4 | __all__ = ['Mastodon', 'AttribAccessDict', 'StreamListener', 'CallbackStreamListener', 'MastodonError', 'MastodonVersionError', 'MastodonIllegalArgumentError', 'MastodonIOError', 'MastodonFileNotFoundError', 'MastodonNetworkError', 'MastodonAPIError', 'MastodonNotFoundError', 'MastodonUnauthorizedError', 'MastodonRatelimitError', 'MastodonMalformedEventError'] | 4 | __all__ = ['Mastodon', 'AttribAccessDict', 'StreamListener', 'CallbackStreamListener', 'MastodonError', 'MastodonVersionError', 'MastodonIllegalArgumentError', 'MastodonIOError', 'MastodonFileNotFoundError', 'MastodonNetworkError', 'MastodonAPIError', 'MastodonNotFoundError', 'MastodonUnauthorizedError', 'MastodonRatelimitError', 'MastodonMalformedEventError', |
5 | 'MastodonServerError'] | ||
diff --git a/tests/cassettes/test_conversations.yaml b/tests/cassettes/test_conversations.yaml new file mode 100644 index 0000000..f4f0b15 --- /dev/null +++ b/tests/cassettes/test_conversations.yaml | |||
@@ -0,0 +1,143 @@ | |||
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":true,"bot":false,"created_at":"2019-04-27T20:56:20.155Z","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":0,"statuses_count":4,"source":{"privacy":"public","sensitive":false,"language":null,"note":"","fields":[]},"emojis":[],"fields":[]}'} | ||
14 | headers: | ||
15 | Cache-Control: ['max-age=0, private, must-revalidate'] | ||
16 | Content-Type: [application/json; charset=utf-8] | ||
17 | ETag: [W/"22befe12cde5f76de801140c68ff24d7"] | ||
18 | Referrer-Policy: [strict-origin-when-cross-origin] | ||
19 | Transfer-Encoding: [chunked] | ||
20 | Vary: ['Accept-Encoding, Origin'] | ||
21 | X-Content-Type-Options: [nosniff] | ||
22 | X-Download-Options: [noopen] | ||
23 | X-Frame-Options: [SAMEORIGIN] | ||
24 | X-Permitted-Cross-Domain-Policies: [none] | ||
25 | X-Request-Id: [f61f2b83-2a73-4874-a883-70240d83b453] | ||
26 | X-Runtime: ['0.021142'] | ||
27 | X-XSS-Protection: [1; mode=block] | ||
28 | content-length: ['653'] | ||
29 | status: {code: 200, message: OK} | ||
30 | - request: | ||
31 | body: visibility=direct&status=%40admin+ilu+bby+%3B3 | ||
32 | headers: | ||
33 | Accept: ['*/*'] | ||
34 | Accept-Encoding: ['gzip, deflate'] | ||
35 | Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN] | ||
36 | Connection: [keep-alive] | ||
37 | Content-Length: ['46'] | ||
38 | Content-Type: [application/x-www-form-urlencoded] | ||
39 | User-Agent: [python-requests/2.18.4] | ||
40 | method: POST | ||
41 | uri: http://localhost:3000/api/v1/statuses | ||
42 | response: | ||
43 | body: {string: '{"id":"102003581864478788","created_at":"2019-04-28T11:32:19.297Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"direct","language":"ja","uri":"http://localhost/users/mastodonpy_test/statuses/102003581864478788","content":"\u003cp\u003e\u003cspan | ||
44 | class=\"h-card\"\u003e\u003ca href=\"http://localhost/@admin\" class=\"u-url | ||
45 | mention\"\u003e@\u003cspan\u003eadmin\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e | ||
46 | ilu bby ;3\u003c/p\u003e","url":"http://localhost/@mastodonpy_test/102003581864478788","replies_count":0,"reblogs_count":0,"favourites_count":0,"favourited":false,"reblogged":false,"muted":false,"reblog":null,"application":{"name":"Mastodon.py | ||
47 | test suite","website":null},"account":{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"created_at":"2019-04-27T20:56:20.155Z","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":0,"statuses_count":4,"emojis":[],"fields":[]},"media_attachments":[],"mentions":[{"id":"1","username":"admin","url":"http://localhost/@admin","acct":"admin"}],"tags":[],"emojis":[],"card":null,"poll":null}'} | ||
48 | headers: | ||
49 | Cache-Control: ['max-age=0, private, must-revalidate'] | ||
50 | Content-Type: [application/json; charset=utf-8] | ||
51 | ETag: [W/"dc7ff9b9023358ffdcb2a1507e9e77e6"] | ||
52 | Referrer-Policy: [strict-origin-when-cross-origin] | ||
53 | Transfer-Encoding: [chunked] | ||
54 | Vary: ['Accept-Encoding, Origin'] | ||
55 | X-Content-Type-Options: [nosniff] | ||
56 | X-Download-Options: [noopen] | ||
57 | X-Frame-Options: [SAMEORIGIN] | ||
58 | X-Permitted-Cross-Domain-Policies: [none] | ||
59 | X-Request-Id: [de40a9dc-97f0-4805-a24a-8378f8f37de9] | ||
60 | X-Runtime: ['0.160974'] | ||
61 | X-XSS-Protection: [1; mode=block] | ||
62 | content-length: ['1475'] | ||
63 | status: {code: 200, message: OK} | ||
64 | - request: | ||
65 | body: null | ||
66 | headers: | ||
67 | Accept: ['*/*'] | ||
68 | Accept-Encoding: ['gzip, deflate'] | ||
69 | Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN_2] | ||
70 | Connection: [keep-alive] | ||
71 | User-Agent: [python-requests/2.18.4] | ||
72 | method: GET | ||
73 | uri: http://localhost:3000/api/v1/conversations/ | ||
74 | response: | ||
75 | body: {string: '[{"id":"24","unread":true,"accounts":[{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"created_at":"2019-04-27T20:56:20.155Z","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":0,"statuses_count":4,"emojis":[],"fields":[]}],"last_status":{"id":"102003581864478788","created_at":"2019-04-28T11:32:19.297Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"direct","language":"ja","uri":"http://localhost/users/mastodonpy_test/statuses/102003581864478788","content":"\u003cp\u003e\u003cspan | ||
76 | class=\"h-card\"\u003e\u003ca href=\"http://localhost/@admin\" class=\"u-url | ||
77 | mention\"\u003e@\u003cspan\u003eadmin\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e | ||
78 | ilu bby ;3\u003c/p\u003e","url":"http://localhost/@mastodonpy_test/102003581864478788","replies_count":0,"reblogs_count":0,"favourites_count":0,"favourited":false,"reblogged":false,"muted":false,"reblog":null,"application":{"name":"Mastodon.py | ||
79 | test suite","website":null},"account":{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"created_at":"2019-04-27T20:56:20.155Z","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":0,"statuses_count":4,"emojis":[],"fields":[]},"media_attachments":[],"mentions":[{"id":"1","username":"admin","url":"http://localhost/@admin","acct":"admin"}],"tags":[],"emojis":[],"card":null,"poll":null}},{"id":"22","unread":true,"accounts":[{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"created_at":"2019-04-27T20:56:20.155Z","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":0,"statuses_count":4,"emojis":[],"fields":[]}],"last_status":{"id":"102003580476156514","created_at":"2019-04-28T11:31:58.113Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"direct","language":"ja","uri":"http://localhost/users/mastodonpy_test/statuses/102003580476156514","content":"\u003cp\u003e\u003cspan | ||
80 | class=\"h-card\"\u003e\u003ca href=\"http://localhost/@admin\" class=\"u-url | ||
81 | mention\"\u003e@\u003cspan\u003eadmin\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e | ||
82 | ilu bby ;3\u003c/p\u003e","url":"http://localhost/@mastodonpy_test/102003580476156514","replies_count":0,"reblogs_count":0,"favourites_count":0,"favourited":false,"reblogged":false,"muted":false,"reblog":null,"application":{"name":"Mastodon.py | ||
83 | test suite","website":null},"account":{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"created_at":"2019-04-27T20:56:20.155Z","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":0,"statuses_count":4,"emojis":[],"fields":[]},"media_attachments":[],"mentions":[{"id":"1","username":"admin","url":"http://localhost/@admin","acct":"admin"}],"tags":[],"emojis":[],"card":null,"poll":null}},{"id":"18","unread":true,"accounts":[{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"created_at":"2019-04-27T20:56:20.155Z","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":0,"statuses_count":4,"emojis":[],"fields":[]}],"last_status":{"id":"102003573042670077","created_at":"2019-04-28T11:30:04.687Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"direct","language":"ja","uri":"http://localhost/users/mastodonpy_test/statuses/102003573042670077","content":"\u003cp\u003e\u003cspan | ||
84 | class=\"h-card\"\u003e\u003ca href=\"http://localhost/@admin\" class=\"u-url | ||
85 | mention\"\u003e@\u003cspan\u003eadmin\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e | ||
86 | ilu bby ;3\u003c/p\u003e","url":"http://localhost/@mastodonpy_test/102003573042670077","replies_count":0,"reblogs_count":0,"favourites_count":0,"favourited":false,"reblogged":false,"muted":false,"reblog":null,"application":{"name":"Mastodon.py | ||
87 | test suite","website":null},"account":{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"created_at":"2019-04-27T20:56:20.155Z","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":0,"statuses_count":4,"emojis":[],"fields":[]},"media_attachments":[],"mentions":[{"id":"1","username":"admin","url":"http://localhost/@admin","acct":"admin"}],"tags":[],"emojis":[],"card":null,"poll":null}},{"id":"14","unread":false,"accounts":[{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"created_at":"2019-04-27T20:56:20.155Z","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":0,"statuses_count":4,"emojis":[],"fields":[]}],"last_status":{"id":"102003565381731428","created_at":"2019-04-28T11:28:07.791Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"direct","language":"ja","uri":"http://localhost/users/mastodonpy_test/statuses/102003565381731428","content":"\u003cp\u003e\u003cspan | ||
88 | class=\"h-card\"\u003e\u003ca href=\"http://localhost/@admin\" class=\"u-url | ||
89 | mention\"\u003e@\u003cspan\u003eadmin\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e | ||
90 | ilu bby ;3\u003c/p\u003e","url":"http://localhost/@mastodonpy_test/102003565381731428","replies_count":0,"reblogs_count":0,"favourites_count":0,"favourited":false,"reblogged":false,"muted":false,"reblog":null,"application":{"name":"Mastodon.py | ||
91 | test suite","website":null},"account":{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"created_at":"2019-04-27T20:56:20.155Z","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":0,"statuses_count":4,"emojis":[],"fields":[]},"media_attachments":[],"mentions":[{"id":"1","username":"admin","url":"http://localhost/@admin","acct":"admin"}],"tags":[],"emojis":[],"card":null,"poll":null}},{"id":"4","unread":false,"accounts":[{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"created_at":"2019-04-27T20:56:20.155Z","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":0,"statuses_count":4,"emojis":[],"fields":[]}],"last_status":{"id":"102003533707396851","created_at":"2019-04-28T11:20:04.478Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"direct","language":"ja","uri":"http://localhost/users/mastodonpy_test/statuses/102003533707396851","content":"\u003cp\u003e\u003cspan | ||
92 | class=\"h-card\"\u003e\u003ca href=\"http://localhost/@admin\" class=\"u-url | ||
93 | mention\"\u003e@\u003cspan\u003eadmin\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e | ||
94 | test\u003c/p\u003e","url":"http://localhost/@mastodonpy_test/102003533707396851","replies_count":0,"reblogs_count":0,"favourites_count":0,"favourited":false,"reblogged":false,"muted":false,"reblog":null,"application":{"name":"Mastodon.py | ||
95 | test suite","website":null},"account":{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"bot":false,"created_at":"2019-04-27T20:56:20.155Z","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":0,"statuses_count":4,"emojis":[],"fields":[]},"media_attachments":[],"mentions":[{"id":"1","username":"admin","url":"http://localhost/@admin","acct":"admin"}],"tags":[],"emojis":[],"card":null,"poll":null}}]'} | ||
96 | headers: | ||
97 | Cache-Control: ['max-age=0, private, must-revalidate'] | ||
98 | Content-Type: [application/json; charset=utf-8] | ||
99 | ETag: [W/"79b5a64acc37c8440422aa5612672686"] | ||
100 | Link: ['<http://localhost:3000/api/v1/conversations?min_id=102003581864478788>; | ||
101 | rel="prev"'] | ||
102 | Referrer-Policy: [strict-origin-when-cross-origin] | ||
103 | Transfer-Encoding: [chunked] | ||
104 | Vary: ['Accept-Encoding, Origin'] | ||
105 | X-Content-Type-Options: [nosniff] | ||
106 | X-Download-Options: [noopen] | ||
107 | X-Frame-Options: [SAMEORIGIN] | ||
108 | X-Permitted-Cross-Domain-Policies: [none] | ||
109 | X-Request-Id: [b9d855cb-8dcd-4498-ae9c-57a9891c1d19] | ||
110 | X-Runtime: ['0.175062'] | ||
111 | X-XSS-Protection: [1; mode=block] | ||
112 | content-length: ['10481'] | ||
113 | status: {code: 200, message: OK} | ||
114 | - request: | ||
115 | body: null | ||
116 | headers: | ||
117 | Accept: ['*/*'] | ||
118 | Accept-Encoding: ['gzip, deflate'] | ||
119 | Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN] | ||
120 | Connection: [keep-alive] | ||
121 | Content-Length: ['0'] | ||
122 | User-Agent: [python-requests/2.18.4] | ||
123 | method: DELETE | ||
124 | uri: http://localhost:3000/api/v1/statuses/102003581864478788 | ||
125 | response: | ||
126 | body: {string: '{}'} | ||
127 | headers: | ||
128 | Cache-Control: ['max-age=0, private, must-revalidate'] | ||
129 | Content-Type: [application/json; charset=utf-8] | ||
130 | ETag: [W/"0f55e9de51b2e35f7a3eecdfab3e2571"] | ||
131 | Referrer-Policy: [strict-origin-when-cross-origin] | ||
132 | Transfer-Encoding: [chunked] | ||
133 | Vary: ['Accept-Encoding, Origin'] | ||
134 | X-Content-Type-Options: [nosniff] | ||
135 | X-Download-Options: [noopen] | ||
136 | X-Frame-Options: [SAMEORIGIN] | ||
137 | X-Permitted-Cross-Domain-Policies: [none] | ||
138 | X-Request-Id: [e9e9ed92-a1c4-4bc7-ab9e-5e1a2df23660] | ||
139 | X-Runtime: ['0.024581'] | ||
140 | X-XSS-Protection: [1; mode=block] | ||
141 | content-length: ['2'] | ||
142 | status: {code: 200, message: OK} | ||
143 | version: 1 | ||
diff --git a/tests/test_timeline.py b/tests/test_timeline.py index 4e77ff7..3a75029 100644 --- a/tests/test_timeline.py +++ b/tests/test_timeline.py | |||
@@ -1,4 +1,5 @@ | |||
1 | import pytest | 1 | import pytest |
2 | import time | ||
2 | from mastodon.Mastodon import MastodonAPIError,\ | 3 | from mastodon.Mastodon import MastodonAPIError,\ |
3 | MastodonIllegalArgumentError,\ | 4 | MastodonIllegalArgumentError,\ |
4 | MastodonUnauthorizedError | 5 | MastodonUnauthorizedError |
@@ -38,8 +39,19 @@ def test_hashtag_tl_leading_hash(api): | |||
38 | with pytest.raises(MastodonIllegalArgumentError): | 39 | with pytest.raises(MastodonIllegalArgumentError): |
39 | api.timeline_hashtag('#hoot') | 40 | api.timeline_hashtag('#hoot') |
40 | 41 | ||
41 | |||
42 | @pytest.mark.vcr() | 42 | @pytest.mark.vcr() |
43 | def test_home_tl_anonymous_throws(api_anonymous): | 43 | def test_home_tl_anonymous_throws(api_anonymous): |
44 | with pytest.raises(MastodonAPIError): | 44 | with pytest.raises(MastodonAPIError): |
45 | api_anonymous.timeline_home() | 45 | api_anonymous.timeline_home() |
46 | |||
47 | @pytest.mark.vcr() | ||
48 | def test_conversations(api, api2): | ||
49 | account = api.account_verify_credentials() | ||
50 | status = api.status_post("@admin ilu bby ;3", visibility="direct") | ||
51 | time.sleep(2) | ||
52 | conversations = api2.conversations() | ||
53 | api.status_delete(status) | ||
54 | assert conversations | ||
55 | assert status.id in map(lambda x: x.last_status.id, conversations) | ||
56 | assert account.id in map(lambda x: x.accounts[0].id, conversations) | ||
57 | |||