Skip to content

Commit

Permalink
test(database): add database unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
machikoyasuda committed Oct 5, 2021
1 parent 0ddea90 commit 055039b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
7 changes: 7 additions & 0 deletions tests/conftest.py
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()
9 changes: 7 additions & 2 deletions tests/test_app.py
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"
57 changes: 57 additions & 0 deletions tests/test_database.py
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 == []

0 comments on commit 055039b

Please sign in to comment.