diff options
-rw-r--r-- | tests/cassettes/test_log_in_password.yaml | 27 | ||||
-rw-r--r-- | tests/cassettes/test_log_in_password_incorrect.yaml | 31 | ||||
-rw-r--r-- | tests/cassettes/test_log_in_password_to_file.yaml | 52 | ||||
-rw-r--r-- | tests/test_auth.py | 44 |
4 files changed, 153 insertions, 1 deletions
diff --git a/tests/cassettes/test_log_in_password.yaml b/tests/cassettes/test_log_in_password.yaml new file mode 100644 index 0000000..c44bed6 --- /dev/null +++ b/tests/cassettes/test_log_in_password.yaml | |||
@@ -0,0 +1,27 @@ | |||
1 | interactions: | ||
2 | - request: | ||
3 | body: redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&password=mastodonadmin&username=admin%40localhost%3A3000&grant_type=password&client_id=__MASTODON_PY_TEST_ID&client_secret=__MASTODON_PY_TEST_SECRET&scope=read+write+follow | ||
4 | headers: | ||
5 | Accept: ['*/*'] | ||
6 | Accept-Encoding: ['gzip, deflate'] | ||
7 | Connection: [keep-alive] | ||
8 | Content-Length: ['221'] | ||
9 | Content-Type: [application/x-www-form-urlencoded] | ||
10 | User-Agent: [python-requests/2.18.4] | ||
11 | method: POST | ||
12 | uri: http://localhost:3000/oauth/token | ||
13 | response: | ||
14 | body: {string: '{"access_token":"__MASTODON_PY_TEST_TOKEN","token_type":"bearer","scope":"read | ||
15 | write follow","created_at":1511814180}'} | ||
16 | headers: | ||
17 | Cache-Control: [no-store] | ||
18 | Content-Type: [application/json; charset=utf-8] | ||
19 | ETag: [W/"f6a22ef91276cdcde8f09c8186d2d41d"] | ||
20 | Pragma: [no-cache] | ||
21 | Transfer-Encoding: [chunked] | ||
22 | Vary: ['Accept-Encoding, Origin'] | ||
23 | X-Request-Id: [85cb59f1-b92a-4ff8-8a49-c09bed55eb98] | ||
24 | X-Runtime: ['0.077197'] | ||
25 | content-length: ['117'] | ||
26 | status: {code: 200, message: OK} | ||
27 | version: 1 | ||
diff --git a/tests/cassettes/test_log_in_password_incorrect.yaml b/tests/cassettes/test_log_in_password_incorrect.yaml new file mode 100644 index 0000000..a66fe07 --- /dev/null +++ b/tests/cassettes/test_log_in_password_incorrect.yaml | |||
@@ -0,0 +1,31 @@ | |||
1 | interactions: | ||
2 | - request: | ||
3 | body: redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&password=hunter2&username=admin%40localhost%3A3000&grant_type=password&client_id=__MASTODON_PY_TEST_ID&client_secret=__MASTODON_PY_TEST_SECRET&scope=read+write+follow | ||
4 | headers: | ||
5 | Accept: ['*/*'] | ||
6 | Accept-Encoding: ['gzip, deflate'] | ||
7 | Connection: [keep-alive] | ||
8 | Content-Length: ['215'] | ||
9 | Content-Type: [application/x-www-form-urlencoded] | ||
10 | User-Agent: [python-requests/2.18.4] | ||
11 | method: POST | ||
12 | uri: http://localhost:3000/oauth/token | ||
13 | response: | ||
14 | body: {string: '{"error":"invalid_grant","error_description":"The provided authorization | ||
15 | grant is invalid, expired, revoked, does not match the redirection URI used | ||
16 | in the authorization request, or was issued to another client."}'} | ||
17 | headers: | ||
18 | Cache-Control: [no-store] | ||
19 | Content-Type: [application/json; charset=utf-8] | ||
20 | Pragma: [no-cache] | ||
21 | Transfer-Encoding: [chunked] | ||
22 | Vary: ['Accept-Encoding, Origin'] | ||
23 | WWW-Authenticate: ['Bearer realm="Doorkeeper", error="invalid_grant", error_description="The | ||
24 | provided authorization grant is invalid, expired, revoked, does not match | ||
25 | the redirection URI used in the authorization request, or was issued to | ||
26 | another client."'] | ||
27 | X-Request-Id: [ece30cd8-c6c1-4bc7-af1a-19bbd997745e] | ||
28 | X-Runtime: ['0.077864'] | ||
29 | content-length: ['213'] | ||
30 | status: {code: 401, message: Unauthorized} | ||
31 | version: 1 | ||
diff --git a/tests/cassettes/test_log_in_password_to_file.yaml b/tests/cassettes/test_log_in_password_to_file.yaml new file mode 100644 index 0000000..f26590c --- /dev/null +++ b/tests/cassettes/test_log_in_password_to_file.yaml | |||
@@ -0,0 +1,52 @@ | |||
1 | interactions: | ||
2 | - request: | ||
3 | body: redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&password=mastodonadmin&username=admin%40localhost%3A3000&grant_type=password&client_id=__MASTODON_PY_TEST_ID&client_secret=__MASTODON_PY_TEST_SECRET&scope=read+write+follow | ||
4 | headers: | ||
5 | Accept: ['*/*'] | ||
6 | Accept-Encoding: ['gzip, deflate'] | ||
7 | Connection: [keep-alive] | ||
8 | Content-Length: ['221'] | ||
9 | Content-Type: [application/x-www-form-urlencoded] | ||
10 | User-Agent: [python-requests/2.18.4] | ||
11 | method: POST | ||
12 | uri: http://localhost:3000/oauth/token | ||
13 | response: | ||
14 | body: {string: '{"access_token":"__MASTODON_PY_TEST_TOKEN","token_type":"bearer","scope":"read | ||
15 | write follow","created_at":1511814180}'} | ||
16 | headers: | ||
17 | Cache-Control: [no-store] | ||
18 | Content-Type: [application/json; charset=utf-8] | ||
19 | ETag: [W/"f77400f50590c94b55a861fb6d432464"] | ||
20 | Pragma: [no-cache] | ||
21 | Transfer-Encoding: [chunked] | ||
22 | Vary: ['Accept-Encoding, Origin'] | ||
23 | X-Request-Id: [b6168343-dd9e-4a0f-9ec4-69a1de8f879a] | ||
24 | X-Runtime: ['0.080069'] | ||
25 | content-length: ['117'] | ||
26 | status: {code: 200, message: OK} | ||
27 | - request: | ||
28 | body: null | ||
29 | headers: | ||
30 | Accept: ['*/*'] | ||
31 | Accept-Encoding: ['gzip, deflate'] | ||
32 | Authorization: [Bearer __MASTODON_PY_TEST_TOKEN] | ||
33 | Connection: [keep-alive] | ||
34 | User-Agent: [python-requests/2.18.4] | ||
35 | method: GET | ||
36 | uri: http://localhost:3000/api/v1/accounts/verify_credentials | ||
37 | response: | ||
38 | body: {string: '{"id":"1","username":"admin","acct":"admin","display_name":"admin","locked":false,"created_at":"2017-08-02T04:15:27.248Z","note":"\u003cp\u003e\u003c/p\u003e","url":"http://localhost:3000/@admin","avatar":"http://localhost:3000/system/accounts/avatars/000/000/001/original/69910b47243ddb47.png","avatar_static":"http://localhost:3000/system/accounts/avatars/000/000/001/original/69910b47243ddb47.png","header":"http://localhost:3000/headers/original/missing.png","header_static":"http://localhost:3000/headers/original/missing.png","followers_count":2,"following_count":1,"statuses_count":16,"source":{"privacy":"public","sensitive":false,"note":""}}'} | ||
39 | headers: | ||
40 | Cache-Control: ['max-age=0, private, must-revalidate'] | ||
41 | Content-Type: [application/json; charset=utf-8] | ||
42 | ETag: [W/"622f72a29f8398775e2abff7cd51dbac"] | ||
43 | Transfer-Encoding: [chunked] | ||
44 | Vary: ['Accept-Encoding, Origin'] | ||
45 | X-Content-Type-Options: [nosniff] | ||
46 | X-Frame-Options: [SAMEORIGIN] | ||
47 | X-Request-Id: [3852d894-50be-4342-a0e6-f9df2ddf5926] | ||
48 | X-Runtime: ['0.029510'] | ||
49 | X-XSS-Protection: [1; mode=block] | ||
50 | content-length: ['650'] | ||
51 | status: {code: 200, message: OK} | ||
52 | version: 1 | ||
diff --git a/tests/test_auth.py b/tests/test_auth.py index 3b62a2f..502d825 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py | |||
@@ -1,7 +1,11 @@ | |||
1 | import pytest | ||
2 | from mastodon.Mastodon import MastodonIllegalArgumentError | ||
3 | from mastodon import Mastodon | ||
1 | try: | 4 | try: |
2 | from urllib.parse import urlparse, parse_qs | 5 | from urllib.parse import urlparse, parse_qs |
3 | except ImportError: | 6 | except ImportError: |
4 | from urlparse import urlparse, parse_qs | 7 | from urlparse import urlparse, parse_qs |
8 | |||
5 | 9 | ||
6 | def test_auth_request_url(api): | 10 | def test_auth_request_url(api): |
7 | url = api.auth_request_url() | 11 | url = api.auth_request_url() |
@@ -14,3 +18,41 @@ def test_auth_request_url(api): | |||
14 | assert set(query['scope'][0].split()) == set(('read', 'write', 'follow')) | 18 | assert set(query['scope'][0].split()) == set(('read', 'write', 'follow')) |
15 | 19 | ||
16 | 20 | ||
21 | @pytest.mark.vcr() | ||
22 | def test_log_in_password(api_anonymous): | ||
23 | token = api_anonymous.log_in( | ||
24 | username='admin@localhost:3000', | ||
25 | password='mastodonadmin') | ||
26 | assert token | ||
27 | |||
28 | |||
29 | @pytest.mark.vcr() | ||
30 | def test_log_in_password_incorrect(api_anonymous): | ||
31 | with pytest.raises(MastodonIllegalArgumentError): | ||
32 | api_anonymous.log_in( | ||
33 | username='admin@localhost:3000', | ||
34 | password='hunter2') | ||
35 | |||
36 | |||
37 | @pytest.mark.vcr() | ||
38 | def test_log_in_password_to_file(api_anonymous, tmpdir): | ||
39 | filepath = tmpdir.join('token') | ||
40 | api_anonymous.log_in( | ||
41 | username='admin@localhost:3000', | ||
42 | password='mastodonadmin', | ||
43 | to_file=str(filepath)) | ||
44 | token = filepath.read_text('UTF-8').rstrip() | ||
45 | assert token | ||
46 | api = api_anonymous | ||
47 | api.access_token = token | ||
48 | assert api.account_verify_credentials() | ||
49 | |||
50 | |||
51 | @pytest.mark.skip(reason="Not sure how to test this without setting up selenium or a similar browser automation suite to click on the allow button") | ||
52 | def test_log_in_code(api_anonymous): | ||
53 | pass | ||
54 | |||
55 | |||
56 | @pytest.mark.skip(reason="Not supported by Mastodon 😬 (yet?)") | ||
57 | def test_log_in_refresh(api_anonymous): | ||
58 | pass | ||