-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(database): add database unit tests
- Loading branch information
1 parent
0ddea90
commit 055039b
Showing
3 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
import pytest | ||
|
||
from eligibility_server.app import app as server | ||
from app import Database as Database | ||
|
||
|
||
@pytest.fixture | ||
def app(): | ||
yield server | ||
|
||
|
||
@pytest.fixture | ||
def database(): | ||
db = Database() | ||
return db | ||
|
||
|
||
@pytest.fixture | ||
def client(app): | ||
return app.test_client() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
def test_healthcheck(app, client): | ||
response = client.get("/healthcheck") | ||
""" | ||
Test API | ||
""" | ||
|
||
|
||
def test_healthcheck(client): | ||
response = client.get("healthcheck") | ||
assert response.status_code == 200 | ||
assert response.data == b"Healthy" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
""" | ||
Test database class and methods | ||
""" | ||
|
||
import json | ||
|
||
with open("data/server.json", encoding="utf8") as file: | ||
DATA = json.load(file) | ||
|
||
|
||
def test_database_init(database): | ||
assert database._config | ||
assert database._merchants | ||
assert database._users | ||
|
||
|
||
def test_database_properties(database): | ||
assert database.auth_header | ||
assert database.auth_token | ||
assert database.token_header | ||
assert database.jwe_cek_enc | ||
assert database.jwe_encryption_alg | ||
assert database.jws_signing_alg | ||
assert database.request_access | ||
|
||
|
||
def test_database_check_merchant_in_database(database): | ||
merchant_id = DATA["merchants"][1] | ||
response = database.check_merchant(merchant_id) | ||
assert response is True | ||
|
||
|
||
def test_database_check_merchant_not_in_database(database): | ||
merchant_id_not_in_database = "123" | ||
response = database.check_merchant(merchant_id_not_in_database) | ||
assert response is False | ||
|
||
|
||
def test_database_check_user_in_database(database): | ||
key = min(DATA["users"]) | ||
user = DATA["users"][key][0] | ||
types = DATA["users"][key][1] | ||
response = database.check_user(key, user, types) | ||
assert response == types | ||
|
||
|
||
def test_database_check_user_in_database_not_eligible(database): | ||
key = min(DATA["users"]) | ||
user = DATA["users"][key][0] | ||
types = ["type2"] | ||
response = database.check_user(key, user, types) | ||
assert response == [] | ||
|
||
|
||
def test_database_check_user_not_in_database(database): | ||
response = database.check_user("G7778889", "Thomas", ["type1"]) | ||
assert response == [] |