diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cassettes/test_conversations.yaml | 143 | ||||
-rw-r--r-- | tests/test_timeline.py | 14 |
2 files changed, 156 insertions, 1 deletions
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 | |||