From f643b91a8b906a3e643ba73045b85ae72e34a2b1 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 8 May 2020 20:36:45 +0200 Subject: [PATCH] test_initial_commit --- consumer_api/tests/__init__.py | 6 +++++ consumer_api/tests/consumers_view_test.py | 29 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 consumer_api/tests/__init__.py create mode 100644 consumer_api/tests/consumers_view_test.py diff --git a/consumer_api/tests/__init__.py b/consumer_api/tests/__init__.py new file mode 100644 index 0000000..883d9c7 --- /dev/null +++ b/consumer_api/tests/__init__.py @@ -0,0 +1,6 @@ +import os + +# Setup environment variables for testing +os.environ["INITIAL_SERVERS"] = "192.168.111.22" +os.environ["LOCAL_UUID"] = "d8b2e5e2-f675-4194-9324-af58e4b70c54" +os.environ["REDIS_URL"] = "redis://192.168.111.121/0" diff --git a/consumer_api/tests/consumers_view_test.py b/consumer_api/tests/consumers_view_test.py new file mode 100644 index 0000000..f713074 --- /dev/null +++ b/consumer_api/tests/consumers_view_test.py @@ -0,0 +1,29 @@ +import pytest + +from flask import current_app + + +@pytest.fixture +def client(): + current_app.config["TESTING"] = True + + with current_app.test_client() as client: + yield client + + +def test_access_denied(client): + r = client.get('/api/user') + + assert r.status_code == 401 + + +def test_access_denied2(client): + r = client.get('/api/user', headers = { "Authorization": "invalidkey" }) + + assert r.status_code == 401 + + +def test_empty_database(client): + r = client.get('/api/user', headers = { "Authorization": "testkey" }) + + assert len(r.json) == 0