From b82630213fd8a4b4c84c71fbecdc22597768abcc Mon Sep 17 00:00:00 2001 From: Vadim Melnik Date: Thu, 28 Sep 2023 18:33:59 +0300 Subject: [PATCH] Testing with pytest, router/api_v1 package tests, work in progress. --- repromon_app/tests/router/test_api_v1.py | 154 +++++++++++++++++++++++ 1 file changed, 154 insertions(+) diff --git a/repromon_app/tests/router/test_api_v1.py b/repromon_app/tests/router/test_api_v1.py index 467b1c5..fc5a9e5 100644 --- a/repromon_app/tests/router/test_api_v1.py +++ b/repromon_app/tests/router/test_api_v1.py @@ -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"