aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2019-10-12 18:58:46 +0200
committerLorenz Diener <[email protected]>2019-10-12 18:58:46 +0200
commitca45cd65aa1e404164d318f1b5453de6e8b5cc6d (patch)
tree606a65e4b5585a778d9d1a4df9118dc02b403f11 /tests/test_auth.py
parent5c4916bd813e205d7fc5cd7f44324b0cecdc4940 (diff)
downloadmastodon.py-ca45cd65aa1e404164d318f1b5453de6e8b5cc6d.tar.gz
Add ability to persist base urls with clientid/secret/token (fixes #200)
Diffstat (limited to 'tests/test_auth.py')
-rw-r--r--tests/test_auth.py30
1 files changed, 26 insertions, 4 deletions
diff --git a/tests/test_auth.py b/tests/test_auth.py
index b4a004e..fbf8974 100644
--- a/tests/test_auth.py
+++ b/tests/test_auth.py
@@ -30,7 +30,6 @@ def test_log_in_password(api_anonymous):
30 password='mastodonadmin') 30 password='mastodonadmin')
31 assert token 31 assert token
32 32
33
34@pytest.mark.vcr() 33@pytest.mark.vcr()
35def test_log_in_password_incorrect(api_anonymous): 34def test_log_in_password_incorrect(api_anonymous):
36 with pytest.raises(MastodonIllegalArgumentError): 35 with pytest.raises(MastodonIllegalArgumentError):
@@ -38,7 +37,6 @@ def test_log_in_password_incorrect(api_anonymous):
38 username='admin@localhost', 37 username='admin@localhost',
39 password='hunter2') 38 password='hunter2')
40 39
41
42@pytest.mark.vcr() 40@pytest.mark.vcr()
43def test_log_in_password_to_file(api_anonymous, tmpdir): 41def test_log_in_password_to_file(api_anonymous, tmpdir):
44 filepath = tmpdir.join('token') 42 filepath = tmpdir.join('token')
@@ -46,18 +44,42 @@ def test_log_in_password_to_file(api_anonymous, tmpdir):
46 username='admin@localhost', 44 username='admin@localhost',
47 password='mastodonadmin', 45 password='mastodonadmin',
48 to_file=str(filepath)) 46 to_file=str(filepath))
49 token = filepath.read_text('UTF-8').rstrip() 47 token = filepath.read_text('UTF-8').rstrip().split("\n")[0]
50 assert token 48 assert token
51 api = api_anonymous 49 api = api_anonymous
52 api.access_token = token 50 api.access_token = token
53 assert api.account_verify_credentials() 51 assert api.account_verify_credentials()
54 52
53@pytest.mark.vcr()
54def test_url_errors(tmpdir):
55 clientid_good = tmpdir.join("clientid")
56 token_good = tmpdir.join("token")
57 clientid_bad = tmpdir.join("clientid_bad")
58 token_bad = tmpdir.join("token_bad")
59
60 clientid_good.write_text("foo\nbar\nhttps://zombo.com\n", "UTF-8")
61 token_good.write_text("foo\nhttps://zombo.com\n", "UTF-8")
62 clientid_bad.write_text("foo\nbar\nhttps://evil.org\n", "UTF-8")
63 token_bad.write_text("foo\nhttps://evil.org\n", "UTF-8")
64
65 api = Mastodon(client_id = clientid_good, access_token = token_good)
66 assert api
67 assert api.api_base_url == "https://zombo.com"
68 assert Mastodon(client_id = clientid_good, access_token = token_good, api_base_url = "zombo.com")
69
70 with pytest.raises(MastodonIllegalArgumentError):
71 Mastodon(client_id = clientid_good, access_token = token_bad, api_base_url = "zombo.com")
72
73 with pytest.raises(MastodonIllegalArgumentError):
74 Mastodon(client_id = clientid_bad, access_token = token_good, api_base_url = "zombo.com")
75
76 with pytest.raises(MastodonIllegalArgumentError):
77 Mastodon(client_id = clientid_bad, access_token = token_bad, api_base_url = "zombo.com")
55 78
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") 79@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")
57def test_log_in_code(api_anonymous): 80def test_log_in_code(api_anonymous):
58 pass 81 pass
59 82
60
61@pytest.mark.skip(reason="Not supported by Mastodon >:@ (yet?)") 83@pytest.mark.skip(reason="Not supported by Mastodon >:@ (yet?)")
62def test_log_in_refresh(api_anonymous): 84def test_log_in_refresh(api_anonymous):
63 pass 85 pass
Powered by cgit v1.2.3 (git 2.41.0)