Skip to content

Commit

Permalink
Merge branch 'main' into add-docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
gabezurita authored Dec 19, 2024
2 parents 85d99be + 19c7c74 commit 2cde6a5
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pyproject.toml
[tool.pytest.ini_options]
addopts = "-ra --cov=./src --cov-fail-under=80 --no-cov-on-fail --cov-report=term:skip-covered --cov-report=html:build/reports/coverage --cov-branch"
addopts = "-ra --cov=./src --cov-fail-under=90 --no-cov-on-fail --cov-report=term:skip-covered --cov-report=html:build/reports/coverage --cov-branch"
testpaths = [
"tests"
]
Expand Down
14 changes: 14 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Dict, List
from unittest.mock import patch

from fastapi.testclient import TestClient

Expand Down Expand Up @@ -117,3 +118,16 @@ def test_unprocessable_content_request_array_has_non_int_value(client: TestClien

response = client.post(MAX_RATING, json=json_post_dict)
assert response.status_code == 422


def test_health_check(client: TestClient) -> None:
response = client.get('/health')
assert response.status_code == 200
assert response.json() == {'status': 'ok'}


def test_health_check_with_empty_lookup_table(client: TestClient) -> None:
with patch('src.python_src.api.MAX_RATINGS_BY_CODE', {}):
response = client.get('/health')
assert response.status_code == 500
assert response.json() == {'detail': 'Max Rating by Diagnostic Code Lookup table is empty.'}
84 changes: 84 additions & 0 deletions tests/test_lookup_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import csv
import os
from tempfile import NamedTemporaryFile
from unittest.mock import patch

import pytest

from src.python_src.util.lookup_table import get_max_ratings_by_code


def create_temp_csv(content: list[list[str]]) -> str:
temp_file = NamedTemporaryFile(mode='w', delete=False, suffix='.csv')
writer = csv.writer(temp_file)
for row in content:
writer.writerow(row)
temp_file.close()
return temp_file.name


def test_get_max_ratings_by_code_with_invalid_csv_line() -> None:
content = [
[
'Diagnostic Code',
'Rated Issue Name',
'Max Rating',
'Body System',
'Category',
'Subcategory',
], # Missing CFR Reference
['6260', 'Tinnitus', '10', 'Ear', 'Diseases', 'Inner Ear'],
]
temp_file = create_temp_csv(content)

try:
with patch('src.python_src.util.lookup_table.os.path.join', return_value=temp_file):
with pytest.raises(ValueError, match='Invalid CSV line at index 1'):
get_max_ratings_by_code()
finally:
os.unlink(temp_file)


def test_get_max_ratings_by_code_with_invalid_diagnostic_code() -> None:
content = [
['Diagnostic Code', 'Rated Issue Name', 'Max Rating', 'Body System', 'Category', 'Subcategory', 'CFR Reference'],
['invalid', 'Tinnitus', '10', 'Ear', 'Diseases', 'Inner Ear', '4.87'],
]
temp_file = create_temp_csv(content)

try:
with patch('src.python_src.util.lookup_table.os.path.join', return_value=temp_file):
with pytest.raises(ValueError, match='Invalid diagnostic code or max rating at index 1'):
get_max_ratings_by_code()
finally:
os.unlink(temp_file)


def test_get_max_ratings_by_code_with_invalid_max_rating() -> None:
content = [
['Diagnostic Code', 'Rated Issue Name', 'Max Rating', 'Body System', 'Category', 'Subcategory', 'CFR Reference'],
['6260', 'Tinnitus', 'invalid', 'Ear', 'Diseases', 'Inner Ear', '4.87'],
]
temp_file = create_temp_csv(content)

try:
with patch('src.python_src.util.lookup_table.os.path.join', return_value=temp_file):
with pytest.raises(ValueError, match='Invalid diagnostic code or max rating at index 1'):
get_max_ratings_by_code()
finally:
os.unlink(temp_file)


def test_get_max_ratings_by_code_with_missing_max_rating() -> None:
content = [
['Diagnostic Code', 'Rated Issue Name', 'Max Rating', 'Body System', 'Category', 'Subcategory', 'CFR Reference'],
['6260', 'Tinnitus', '', 'Ear', 'Diseases', 'Inner Ear', '4.87'],
]
temp_file = create_temp_csv(content)

try:
with patch('src.python_src.util.lookup_table.os.path.join', return_value=temp_file):
result = get_max_ratings_by_code()
assert result == {}
finally:
os.unlink(temp_file)

0 comments on commit 2cde6a5

Please sign in to comment.