Skip to content

Commit

Permalink
Testing with pytest, router/api_v1 package tests, work in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmdocua committed Sep 28, 2023
1 parent d3a83c8 commit b826302
Showing 1 changed file with 154 additions and 0 deletions.
154 changes: 154 additions & 0 deletions repromon_app/tests/router/test_api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,157 @@ def test_message_send_message(
data = response.json()
msg2 = DAO.message.get_message_log_info(data["id"])
assert msg2


def test_secsys_calculate_apikey(
test_client: TestClient,
oauth2_admin_headers
):
response = test_client.get(
"/api/1/secsys/calculate_apikey",
params={"apikey_data": "data321987655667132a"},
headers=oauth2_admin_headers)
assert response.status_code == 200
assert response.text


def test_secsys_create_access_token(
test_client: TestClient,
oauth2_admin_headers
):
response = test_client.get(
"/api/1/secsys/create_access_token",
params={"username": "tester1", "expire_sec": 1},
headers=oauth2_admin_headers)
assert response.status_code == 200
assert response.json()["access_token"]


def test_secsys_create_apikey(
test_client: TestClient,
oauth2_admin_headers
):
response = test_client.get(
"/api/1/secsys/create_apikey",
headers=oauth2_admin_headers)
assert response.status_code == 200
assert response.json()["key"]


def test_secsys_get_all_apikeys(
test_client: TestClient,
oauth2_admin_headers
):
response = test_client.get(
"/api/1/secsys/get_all_apikeys",
headers=oauth2_admin_headers)
assert response.status_code == 200
data = response.json()
assert isinstance(data, list)
assert len(data) > 0


def test_secsys_get_apikey_hash(
test_client: TestClient,
oauth2_admin_headers
):
response = test_client.get(
"/api/1/secsys/get_apikey_hash",
params={"apikey": "Axsdsd.as455t65fbcZXZXzxzxsvfvgffd"},
headers=oauth2_admin_headers)
assert response.status_code == 200
h = response.json()["apikey_hash"]
assert h == "Axsdsd_nzwpPMm2EV9G6hNZuj3R49G4Wrj0y8BsAmuMUHTi1mE="


def test_secsys_get_password_hash(
test_client: TestClient,
oauth2_admin_headers
):
response = test_client.get(
"/api/1/secsys/get_password_hash",
params={"password": "sfegfvvfd&%6s"},
headers=oauth2_admin_headers)
assert response.status_code == 200
assert response.json()["password_hash"]


def test_secsys_get_user_apikey(
test_client: TestClient,
apikey_tester1,
oauth2_admin_headers
):
response = test_client.get(
"/api/1/secsys/get_user_apikey",
params={"username": "tester1"},
headers=oauth2_admin_headers)
assert response.status_code == 200
assert response.json()["apikey"] == apikey_tester1


def test_secsys_get_user_devices(
test_client: TestClient,
oauth2_admin_headers
):
response = test_client.get(
"/api/1/secsys/get_user_devices",
params={"username": "tester1"},
headers=oauth2_admin_headers)
assert response.status_code == 200
data = response.json()
assert isinstance(data, list)
assert len(data) > 0


def test_secsys_get_user_roles(
test_client: TestClient,
oauth2_admin_headers
):
response = test_client.get(
"/api/1/secsys/get_user_roles",
params={"username": "tester1"},
headers=oauth2_admin_headers)
assert response.status_code == 200
data = response.json()
assert isinstance(data, list)
assert len(data) > 0


def test_secsys_get_users_by_role(
test_client: TestClient,
oauth2_admin_headers
):
response = test_client.get(
"/api/1/secsys/get_users_by_role",
params={"rolename": "admin"},
headers=oauth2_admin_headers)
assert response.status_code == 200
data = response.json()
assert isinstance(data, list)
assert len(data) > 0


def test_secsys_get_username_by_apikey(
test_client: TestClient,
apikey_tester1,
oauth2_admin_headers
):
response = test_client.get(
"/api/1/secsys/get_username_by_apikey",
params={"apikey": apikey_tester1},
headers=oauth2_admin_headers)
assert response.status_code == 200
assert response.json()["username"] == "tester1"


def test_secsys_get_username_by_token(
test_client: TestClient,
token_tester1,
oauth2_admin_headers
):
response = test_client.get(
"/api/1/secsys/get_username_by_token",
params={"token": token_tester1},
headers=oauth2_admin_headers)
assert response.status_code == 200
assert response.json()["username"] == "tester1"

0 comments on commit b826302

Please sign in to comment.