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