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 44da189 commit d3a83c8
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 1 deletion.
2 changes: 1 addition & 1 deletion repromon_app/router/api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def feedback_get_message_log(request: Request,

# @security: role=data_collector, auth
@api_v1_router.get("/feedback/get_study_header",
response_model=StudyInfoDTO,
response_model=StudyInfoDTO | None,
tags=["FeedbackService"],
summary="get_study_header",
description="Get study header info")
Expand Down
117 changes: 117 additions & 0 deletions repromon_app/tests/router/test_api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,53 @@

from fastapi.testclient import TestClient

from repromon_app.dao import DAO
from repromon_app.model import (DataProviderId, MessageCategoryId,
MessageLevelId)

logger = logging.getLogger(__name__)
logger.debug(f"name={__name__}")


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


def test_account_get_user(
test_client: TestClient,
oauth2_admin_headers
):
response = test_client.get(
"/api/1/account/get_user",
params={"username": "admin"},
headers=oauth2_admin_headers)
assert response.status_code == 200
data = response.json()
assert data["username"] == "admin"


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


def test_feedback_get_devices(
test_client: TestClient,
oauth2_tester1_headers
Expand All @@ -18,3 +61,77 @@ def test_feedback_get_devices(
assert isinstance(data, list)
assert len(data) > 0
assert data[0]["id"] == 1


def test_feedback_get_message(
test_client: TestClient,
oauth2_tester1_headers
):
response = test_client.get(
"/api/1/feedback/get_message",
params={"message_id": -1},
headers=oauth2_tester1_headers)
assert response.status_code == 200
data = response.json()
assert data is None


def test_feedback_get_message_log(
test_client: TestClient,
oauth2_tester1_headers
):
response = test_client.get(
"/api/1/feedback/get_message_log",
headers=oauth2_tester1_headers)
assert response.status_code == 200
data = response.json()
assert isinstance(data, list)
assert len(data) > 0


def test_feedback_get_study_header(
test_client: TestClient,
oauth2_tester1_headers
):
response = test_client.get(
"/api/1/feedback/get_study_header",
params={"study_id": -1},
headers=oauth2_tester1_headers)
assert response.status_code == 200
data = response.json()
assert data is None


def test_login_get_current_user(
test_client: TestClient,
oauth2_tester1_headers
):
response = test_client.get(
"/api/1/login/get_current_user",
headers=oauth2_tester1_headers)
assert response.status_code == 200
data = response.json()
assert data["username"] == "tester1"


def test_message_send_message(
test_client: TestClient,
apikey_tester2_headers
):
response = test_client.post(
"/api/1/message/send_message",
params={
"study": "Test Study Name",
"category": MessageCategoryId.FEEDBACK,
"level": MessageLevelId.INFO,
"device": 1,
"provider": DataProviderId.MRI,
"description": "Test message from test_api_v1",
"payload": "{'foobar': 111}"

},
headers=apikey_tester2_headers)
assert response.status_code == 200
data = response.json()
msg2 = DAO.message.get_message_log_info(data["id"])
assert msg2

0 comments on commit d3a83c8

Please sign in to comment.