diff options
author | Lorenz Diener <[email protected]> | 2017-11-29 17:48:56 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2017-11-29 17:48:56 +0100 |
commit | 961425e2abc91d693004f2c0d073e387de64e58c (patch) | |
tree | 8b1512daf97ab63b54f4edebc83b35f524571c53 /tests/test_auth.py | |
parent | 5b811b719d379be06ed256da2ee806a051461795 (diff) | |
parent | e79987df2410ee32302abed9e486a72b2dfc9707 (diff) | |
download | mastodon.py-961425e2abc91d693004f2c0d073e387de64e58c.tar.gz |
Merge pull request #109 from codl/test-suite
Test suite
Diffstat (limited to 'tests/test_auth.py')
-rw-r--r-- | tests/test_auth.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/test_auth.py b/tests/test_auth.py new file mode 100644 index 0000000..2b27d5b --- /dev/null +++ b/tests/test_auth.py | |||
@@ -0,0 +1,63 @@ | |||
1 | import pytest | ||
2 | from mastodon.Mastodon import MastodonIllegalArgumentError | ||
3 | from mastodon import Mastodon | ||
4 | try: | ||
5 | from urllib.parse import urlparse, parse_qs | ||
6 | except ImportError: | ||
7 | from urlparse import urlparse, parse_qs | ||
8 | |||
9 | |||
10 | def test_auth_request_url(api): | ||
11 | url = api.auth_request_url() | ||
12 | parse = urlparse(url) | ||
13 | assert parse.path == '/oauth/authorize' | ||
14 | query = parse_qs(parse.query) | ||
15 | assert query['client_id'][0] == api.client_id | ||
16 | assert query['response_type'][0] == 'code' | ||
17 | assert query['redirect_uri'][0] == 'urn:ietf:wg:oauth:2.0:oob' | ||
18 | assert set(query['scope'][0].split()) == set(('read', 'write', 'follow')) | ||
19 | |||
20 | |||
21 | def test_log_in_none(api_anonymous): | ||
22 | with pytest.raises(MastodonIllegalArgumentError): | ||
23 | api_anonymous.log_in() | ||
24 | |||
25 | |||
26 | @pytest.mark.vcr() | ||
27 | def test_log_in_password(api_anonymous): | ||
28 | token = api_anonymous.log_in( | ||
29 | username='admin@localhost:3000', | ||
30 | password='mastodonadmin') | ||
31 | assert token | ||
32 | |||
33 | |||
34 | @pytest.mark.vcr() | ||
35 | def test_log_in_password_incorrect(api_anonymous): | ||
36 | with pytest.raises(MastodonIllegalArgumentError): | ||
37 | api_anonymous.log_in( | ||
38 | username='admin@localhost:3000', | ||
39 | password='hunter2') | ||
40 | |||
41 | |||
42 | @pytest.mark.vcr() | ||
43 | def test_log_in_password_to_file(api_anonymous, tmpdir): | ||
44 | filepath = tmpdir.join('token') | ||
45 | api_anonymous.log_in( | ||
46 | username='admin@localhost:3000', | ||
47 | password='mastodonadmin', | ||
48 | to_file=str(filepath)) | ||
49 | token = filepath.read_text('UTF-8').rstrip() | ||
50 | assert token | ||
51 | api = api_anonymous | ||
52 | api.access_token = token | ||
53 | assert api.account_verify_credentials() | ||
54 | |||
55 | |||
56 | @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") | ||
57 | def test_log_in_code(api_anonymous): | ||
58 | pass | ||
59 | |||
60 | |||
61 | @pytest.mark.skip(reason="Not supported by Mastodon >:@ (yet?)") | ||
62 | def test_log_in_refresh(api_anonymous): | ||
63 | pass | ||