From ca45cd65aa1e404164d318f1b5453de6e8b5cc6d Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Sat, 12 Oct 2019 18:58:46 +0200 Subject: Add ability to persist base urls with clientid/secret/token (fixes #200) --- tests/test_auth.py | 30 ++++++++++++++++++++++++++---- tests/test_create_app.py | 2 +- 2 files changed, 27 insertions(+), 5 deletions(-) (limited to 'tests') 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): password='mastodonadmin') assert token - @pytest.mark.vcr() def test_log_in_password_incorrect(api_anonymous): with pytest.raises(MastodonIllegalArgumentError): @@ -38,7 +37,6 @@ def test_log_in_password_incorrect(api_anonymous): username='admin@localhost', password='hunter2') - @pytest.mark.vcr() def test_log_in_password_to_file(api_anonymous, tmpdir): filepath = tmpdir.join('token') @@ -46,18 +44,42 @@ def test_log_in_password_to_file(api_anonymous, tmpdir): username='admin@localhost', password='mastodonadmin', to_file=str(filepath)) - token = filepath.read_text('UTF-8').rstrip() + token = filepath.read_text('UTF-8').rstrip().split("\n")[0] assert token api = api_anonymous api.access_token = token assert api.account_verify_credentials() +@pytest.mark.vcr() +def test_url_errors(tmpdir): + clientid_good = tmpdir.join("clientid") + token_good = tmpdir.join("token") + clientid_bad = tmpdir.join("clientid_bad") + token_bad = tmpdir.join("token_bad") + + clientid_good.write_text("foo\nbar\nhttps://zombo.com\n", "UTF-8") + token_good.write_text("foo\nhttps://zombo.com\n", "UTF-8") + clientid_bad.write_text("foo\nbar\nhttps://evil.org\n", "UTF-8") + token_bad.write_text("foo\nhttps://evil.org\n", "UTF-8") + + api = Mastodon(client_id = clientid_good, access_token = token_good) + assert api + assert api.api_base_url == "https://zombo.com" + assert Mastodon(client_id = clientid_good, access_token = token_good, api_base_url = "zombo.com") + + with pytest.raises(MastodonIllegalArgumentError): + Mastodon(client_id = clientid_good, access_token = token_bad, api_base_url = "zombo.com") + + with pytest.raises(MastodonIllegalArgumentError): + Mastodon(client_id = clientid_bad, access_token = token_good, api_base_url = "zombo.com") + + with pytest.raises(MastodonIllegalArgumentError): + Mastodon(client_id = clientid_bad, access_token = token_bad, api_base_url = "zombo.com") @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") def test_log_in_code(api_anonymous): pass - @pytest.mark.skip(reason="Not supported by Mastodon >:@ (yet?)") def test_log_in_refresh(api_anonymous): pass diff --git a/tests/test_create_app.py b/tests/test_create_app.py index b9de298..8260751 100644 --- a/tests/test_create_app.py +++ b/tests/test_create_app.py @@ -31,7 +31,7 @@ def test_create_app(mocker, to_file=None, redirect_uris=None, website=None): def test_create_app_to_file(mocker, tmpdir): filepath = tmpdir.join('credentials') test_create_app(mocker, to_file=str(filepath)) - assert filepath.read_text('UTF-8') == "foo\nbar\n" + assert filepath.read_text('UTF-8') == "foo\nbar\nhttps://example.com\n" def test_create_app_redirect_uris(mocker): test_create_app(mocker, redirect_uris='http://example.net') -- cgit v1.2.3