aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/cassettes/test_unauthed_home_tl_throws.yaml82
-rw-r--r--tests/test_status.py5
-rw-r--r--tests/test_timeline.py9
3 files changed, 92 insertions, 4 deletions
diff --git a/tests/cassettes/test_unauthed_home_tl_throws.yaml b/tests/cassettes/test_unauthed_home_tl_throws.yaml
new file mode 100644
index 0000000..b63d840
--- /dev/null
+++ b/tests/cassettes/test_unauthed_home_tl_throws.yaml
@@ -0,0 +1,82 @@
1interactions:
2- request:
3 body: visibility=&status=Toot%21
4 headers:
5 Accept: ['*/*']
6 Accept-Encoding: ['gzip, deflate']
7 Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
8 Connection: [keep-alive]
9 Content-Length: ['26']
10 Content-Type: [application/x-www-form-urlencoded]
11 User-Agent: [python-requests/2.18.4]
12 method: POST
13 uri: http://localhost:3000/api/v1/statuses
14 response:
15 body: {string: '{"id":"99285482671609362","created_at":"2018-01-03T10:43:57.160Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"private","language":"ja","uri":"http://localhost:3000/users/mastodonpy_test/statuses/99285482671609362","content":"\u003cp\u003eToot!\u003c/p\u003e","url":"http://localhost:3000/@mastodonpy_test/99285482671609362","reblogs_count":0,"favourites_count":0,"favourited":false,"reblogged":false,"muted":false,"reblog":null,"application":{"name":"Mastodon.py
16 test suite","website":null},"account":{"id":"1234567890123456","username":"mastodonpy_test","acct":"mastodonpy_test","display_name":"","locked":true,"created_at":"2018-01-03T11:24:32.957Z","note":"\u003cp\u003e\u003c/p\u003e","url":"http://localhost:3000/@mastodonpy_test","avatar":"http://localhost:3000/avatars/original/missing.png","avatar_static":"http://localhost:3000/avatars/original/missing.png","header":"http://localhost:3000/headers/original/missing.png","header_static":"http://localhost:3000/headers/original/missing.png","followers_count":0,"following_count":0,"statuses_count":1},"media_attachments":[],"mentions":[],"tags":[],"emojis":[]}'}
17 headers:
18 Cache-Control: ['max-age=0, private, must-revalidate']
19 Content-Type: [application/json; charset=utf-8]
20 ETag: [W/"d9b57bb0592371b00e98fbc0f44a8fc9"]
21 Transfer-Encoding: [chunked]
22 Vary: ['Accept-Encoding, Origin']
23 X-Content-Type-Options: [nosniff]
24 X-Frame-Options: [SAMEORIGIN]
25 X-Request-Id: [d7a9df07-1a3c-4784-adc5-b67bd6347614]
26 X-Runtime: ['0.301984']
27 X-XSS-Protection: [1; mode=block]
28 content-length: ['1175']
29 status: {code: 200, message: OK}
30- request:
31 body: null
32 headers:
33 Accept: ['*/*']
34 Accept-Encoding: ['gzip, deflate']
35 Connection: [keep-alive]
36 User-Agent: [python-requests/2.18.4]
37 method: GET
38 uri: http://localhost:3000/api/v1/timelines/home
39 response:
40 body: {string: '{"error":"The access token is invalid"}'}
41 headers:
42 Cache-Control: [no-store]
43 Content-Type: [application/json; charset=utf-8]
44 Pragma: [no-cache]
45 Transfer-Encoding: [chunked]
46 Vary: ['Accept-Encoding, Origin']
47 WWW-Authenticate: ['Bearer realm="Doorkeeper", error="invalid_token", error_description="The
48 access token is invalid"']
49 X-Content-Type-Options: [nosniff]
50 X-Frame-Options: [SAMEORIGIN]
51 X-Request-Id: [dc45d4f4-c203-4b28-ad27-f0db32912a16]
52 X-Runtime: ['0.010224']
53 X-XSS-Protection: [1; mode=block]
54 content-length: ['39']
55 status: {code: 401, message: Unauthorized}
56- request:
57 body: null
58 headers:
59 Accept: ['*/*']
60 Accept-Encoding: ['gzip, deflate']
61 Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
62 Connection: [keep-alive]
63 Content-Length: ['0']
64 User-Agent: [python-requests/2.18.4]
65 method: DELETE
66 uri: http://localhost:3000/api/v1/statuses/99285482671609362
67 response:
68 body: {string: '{}'}
69 headers:
70 Cache-Control: ['max-age=0, private, must-revalidate']
71 Content-Type: [application/json; charset=utf-8]
72 ETag: [W/"8ca371aea536ee2c56c8d13b43824703"]
73 Transfer-Encoding: [chunked]
74 Vary: ['Accept-Encoding, Origin']
75 X-Content-Type-Options: [nosniff]
76 X-Frame-Options: [SAMEORIGIN]
77 X-Request-Id: [ddbd4335-1aeb-42af-8dea-fa78a787609f]
78 X-Runtime: ['0.017701']
79 X-XSS-Protection: [1; mode=block]
80 content-length: ['2']
81 status: {code: 200, message: OK}
82version: 1
diff --git a/tests/test_status.py b/tests/test_status.py
index b177517..2e129ac 100644
--- a/tests/test_status.py
+++ b/tests/test_status.py
@@ -1,6 +1,5 @@
1import pytest 1import pytest
2from mastodon.Mastodon import MastodonAPIError 2from mastodon.Mastodon import MastodonAPIError, MastodonNotFoundError
3from time import sleep
4 3
5@pytest.mark.vcr() 4@pytest.mark.vcr()
6def test_status(status, api): 5def test_status(status, api):
@@ -14,7 +13,7 @@ def test_status_empty(api):
14 13
15@pytest.mark.vcr() 14@pytest.mark.vcr()
16def test_status_missing(api): 15def test_status_missing(api):
17 with pytest.raises(MastodonAPIError): 16 with pytest.raises(MastodonNotFoundError):
18 api.status(0) 17 api.status(0)
19 18
20@pytest.mark.skip(reason="Doesn't look like mastodon will make a card for an url that doesn't have a TLD, and relying on some external website being reachable to make a card of is messy :/") 19@pytest.mark.skip(reason="Doesn't look like mastodon will make a card for an url that doesn't have a TLD, and relying on some external website being reachable to make a card of is messy :/")
diff --git a/tests/test_timeline.py b/tests/test_timeline.py
index 6a27be3..5108b63 100644
--- a/tests/test_timeline.py
+++ b/tests/test_timeline.py
@@ -1,5 +1,7 @@
1import pytest 1import pytest
2from mastodon.Mastodon import MastodonAPIError, MastodonIllegalArgumentError 2from mastodon.Mastodon import MastodonAPIError,\
3 MastodonIllegalArgumentError,\
4 MastodonUnauthorizedError
3 5
4@pytest.mark.vcr() 6@pytest.mark.vcr()
5def test_public_tl_anonymous(api_anonymous, status): 7def test_public_tl_anonymous(api_anonymous, status):
@@ -18,6 +20,11 @@ def test_public_tl(api, status):
18 assert status['id'] in map(lambda st: st['id'], local) 20 assert status['id'] in map(lambda st: st['id'], local)
19 21
20@pytest.mark.vcr() 22@pytest.mark.vcr()
23def test_unauthed_home_tl_throws(api_anonymous, status):
24 with pytest.raises(MastodonUnauthorizedError):
25 api_anonymous.timeline_home()
26
27@pytest.mark.vcr()
21def test_home_tl(api, status): 28def test_home_tl(api, status):
22 tl = api.timeline_home() 29 tl = api.timeline_home()
23 assert status['id'] in map(lambda st: st['id'], tl) 30 assert status['id'] in map(lambda st: st['id'], tl)
Powered by cgit v1.2.3 (git 2.41.0)