From 5b4af5300ec58867d96affeb62e66032149cc0e7 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 4 Apr 2019 18:18:21 -0700 Subject: test api helpers (found bug) It seems that public_api() doesn't get isolated from authenticated_api(), even in different tests. I suspect this is due to using DefaultAPI to create client. --- python/tests/fixtures.py | 7 ++----- python/tests/tools_api.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 python/tests/tools_api.py (limited to 'python/tests') diff --git a/python/tests/fixtures.py b/python/tests/fixtures.py index 41673d8a..478fdd79 100644 --- a/python/tests/fixtures.py +++ b/python/tests/fixtures.py @@ -8,6 +8,7 @@ from dotenv import load_dotenv import fatcat_web import fatcat_client +from fatcat_tools import authenticated_api @pytest.fixture def full_app(): @@ -33,11 +34,7 @@ def app_admin(app): @pytest.fixture def api(): load_dotenv(dotenv_path="./example.env") - conf = fatcat_client.Configuration() - conf.host = "http://localhost:9411/v0" - conf.api_key["Authorization"] = os.getenv("FATCAT_API_AUTH_TOKEN") - conf.api_key_prefix["Authorization"] = "Bearer" - api_client = fatcat_client.DefaultApi(fatcat_client.ApiClient(conf)) + api_client = authenticated_api("http://localhost:9411/v0") api_client.editor_id = "aaaaaaaaaaaabkvkaaaaaaaaae" return api_client diff --git a/python/tests/tools_api.py b/python/tests/tools_api.py new file mode 100644 index 00000000..ac75a73a --- /dev/null +++ b/python/tests/tools_api.py @@ -0,0 +1,23 @@ + +import pytest +from fatcat_client import EditgroupAnnotation +from fatcat_client.rest import ApiException + +from fatcat_tools import public_api, authenticated_api + + +def test_authenticated_api(): + api = authenticated_api("http://localhost:9411/v0") + api.get_changelog() + api.create_editgroup_annotation("aaaaaaaaaaaabo53aaaaaaaaa4", + EditgroupAnnotation(comment_markdown="bloop test thingie")) + +def test_public_api(): + api = public_api("http://localhost:9411/v0") + api.get_changelog() + # XXX: there is some contamination happening here, and we're getting + # authenticated. Maybe the DefaultAPI thing? + pytest.skip("public_api() client not isolated from authenticated") + with pytest.raises(ApiException): + api.create_editgroup_annotation("aaaaaaaaaaaabo53aaaaaaaaa4", + EditgroupAnnotation(comment_markdown="bloop unauth test thingie")) -- cgit v1.2.3