Skip to content

Commit 79e32d4

Browse files
committed
path & tidy
1 parent a0c6301 commit 79e32d4

File tree

9 files changed

+22
-19
lines changed

9 files changed

+22
-19
lines changed

.github/workflows/sonarcloud.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ jobs:
9090
9191
- name: Run unittest with coverage-fhir-api
9292
working-directory: backend
93+
env:
94+
PYTHONPATH: ${{ github.workspace }}/backend/src:${{ github.workspace }}/backend/tests
9395
id: fhirapi
9496
continue-on-error: true
9597
run: |

backend/tests/test_fhir_batch_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from models.fhir_immunization import ImmunizationValidator
88
from fhir_batch_repository import ImmunizationBatchRepository
99
from fhir_batch_service import ImmunizationBatchService
10-
from sample_data.mock_redis_cache import fake_hget
10+
from utils.mock_redis import mock_redis_hget
1111

1212

1313
class TestFhirBatchServiceBase(unittest.TestCase):
@@ -17,7 +17,7 @@ def setUp(self):
1717
super().setUp()
1818
self.redis_patcher = patch("models.utils.validation_utils.redis_client")
1919
self.mock_redis_client = self.redis_patcher.start()
20-
self.mock_redis_client.hget.side_effect = fake_hget
20+
self.mock_redis_client.hget.side_effect = mock_redis_hget
2121
self.logger_info_patcher = patch("logging.Logger.info")
2222
self.mock_logger_info = self.logger_info_patcher.start()
2323

backend/tests/test_fhir_controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from tests.utils.immunization_utils import create_covid_19_immunization
2929
from parameter_parser import patient_identifier_system, process_search_params
3030
from tests.utils.generic_utils import load_json_data
31-
from sample_data.mock_redis_cache import fake_hkeys
31+
from utils.mock_redis import mock_redis_hkeys
3232

3333

3434
class TestFhirControllerBase(unittest.TestCase):
@@ -38,7 +38,7 @@ def setUp(self):
3838
super().setUp()
3939
self.redis_patcher = patch("parameter_parser.redis_client")
4040
self.mock_redis_client = self.redis_patcher.start()
41-
self.mock_redis_client.hkeys.side_effect = fake_hkeys
41+
self.mock_redis_client.hkeys.side_effect = mock_redis_hkeys
4242
self.logger_info_patcher = patch("logging.Logger.info")
4343
self.mock_logger_info = self.logger_info_patcher.start()
4444

backend/tests/test_fhir_repository.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
)
1717
from tests.utils.generic_utils import update_target_disease_code
1818
from tests.utils.immunization_utils import create_covid_19_immunization_dict
19-
from sample_data.mock_redis_cache import fake_hget
19+
from utils.mock_redis import mock_redis_hget
2020

2121
def _make_immunization_pk(_id):
2222
return f"Immunization#{_id}"
@@ -32,7 +32,7 @@ def setUp(self):
3232
super().setUp()
3333
self.redis_patcher = patch("models.utils.validation_utils.redis_client")
3434
self.mock_redis_client = self.redis_patcher.start()
35-
self.mock_redis_client.hget.side_effect = fake_hget
35+
self.mock_redis_client.hget.side_effect = mock_redis_hget
3636
self.logger_info_patcher = patch("logging.Logger.info")
3737
self.mock_logger_info = self.logger_info_patcher.start()
3838

backend/tests/test_fhir_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
)
2424
from utils.generic_utils import load_json_data
2525
from constants import NHS_NUMBER_USED_IN_SAMPLE_DATA
26-
from sample_data.mock_redis_cache import fake_hget
26+
from utils.mock_redis import mock_redis_hget
2727

2828
class TestFhirServiceBase(unittest.TestCase):
2929
"""Base class for all tests to set up common fixtures"""
@@ -32,7 +32,7 @@ def setUp(self):
3232
super().setUp()
3333
self.redis_patcher = patch("models.utils.validation_utils.redis_client")
3434
self.mock_redis_client = self.redis_patcher.start()
35-
self.mock_redis_client.hget.side_effect = fake_hget
35+
self.mock_redis_client.hget.side_effect = mock_redis_hget
3636
self.logger_info_patcher = patch("logging.Logger.info")
3737
self.mock_logger_info = self.logger_info_patcher.start()
3838

backend/tests/test_immunization_post_validator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from copy import deepcopy
77
from pydantic import ValidationError
88
from jsonpath_ng.ext import parse
9-
from sample_data.mock_redis_cache import fake_hget
9+
from utils.mock_redis import mock_redis_hget
1010

1111

1212
from models.fhir_immunization import ImmunizationValidator
@@ -18,7 +18,7 @@
1818
from tests.utils.mandation_test_utils import MandationTests
1919
from tests.utils.values_for_tests import NameInstances
2020
from tests.utils.generic_utils import update_contained_resource_field
21-
from sample_data.mock_redis_cache import MOCK_REDIS_D2V_RESPONSE, MOCK_REDIS_V2D_RESPONSE
21+
from utils.mock_redis import MOCK_REDIS_D2V_RESPONSE, MOCK_REDIS_V2D_RESPONSE
2222

2323
class TestImmunizationModelPostValidationRules(unittest.TestCase):
2424
"""Test immunization post validation rules on the FHIR model"""
@@ -42,7 +42,7 @@ def setUp(self):
4242
]
4343
self.redis_patcher = patch("models.utils.validation_utils.redis_client")
4444
self.mock_redis_client = self.redis_patcher.start()
45-
self.mock_redis_client.hget.side_effect = fake_hget
45+
self.mock_redis_client.hget.side_effect = mock_redis_hget
4646

4747
def test_collected_errors(self):
4848
"""Test that when passed multiple validation errors, it returns a list of all expected errors"""

backend/tests/test_parameter_parser.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
create_query_string,
1515
SearchParams,
1616
)
17-
from sample_data.mock_redis_cache import fake_hkeys
17+
from utils.mock_redis import mock_redis_hkeys
1818

1919
class TestParameterParser(unittest.TestCase):
2020
def setUp(self):
@@ -28,7 +28,6 @@ def setUp(self):
2828
self.mock_logger_info = self.logger_info_patcher.start()
2929
self.redis_patcher = patch("parameter_parser.redis_client")
3030
self.mock_redis_client = self.redis_patcher.start()
31-
self.mock_redis_client.hkeys.side_effect = fake_hkeys
3231

3332
def tearDown(self):
3433
patch.stopall()
@@ -103,7 +102,7 @@ def test_process_search_params_checks_patient_identifier_format(self):
103102
'"https://fhir.nhs.uk/Id/nhs-number|{NHS number}" '
104103
'e.g. "https://fhir.nhs.uk/Id/nhs-number|9000000009"',
105104
)
106-
105+
self.mock_redis_client.hkeys.return_value = ["RSV"]
107106
params = process_search_params(
108107
{
109108
self.patient_identifier_key: ["https://fhir.nhs.uk/Id/nhs-number|9000000009"],
@@ -113,6 +112,7 @@ def test_process_search_params_checks_patient_identifier_format(self):
113112
self.assertIsNotNone(params)
114113

115114
def test_process_search_params_whitelists_immunization_target(self):
115+
self.mock_redis_client.hkeys.return_value = ["RSV"]
116116
with self.assertRaises(ParameterException) as e:
117117
process_search_params(
118118
{
@@ -135,6 +135,7 @@ def test_process_search_params_whitelists_immunization_target(self):
135135
self.assertIsNotNone(params)
136136

137137
def test_search_params_date_from_must_be_before_date_to(self):
138+
self.mock_redis_client.hkeys.return_value = ["RSV"]
138139
params = process_search_params(
139140
{
140141
self.patient_identifier_key: ["https://fhir.nhs.uk/Id/nhs-number|9000000009"],
@@ -170,6 +171,7 @@ def test_search_params_date_from_must_be_before_date_to(self):
170171
self.assertEqual(str(e.exception), f"Search parameter {date_from_key} must be before {date_to_key}")
171172

172173
def test_process_search_params_immunization_target_is_mandatory(self):
174+
self.mock_redis_client.hkeys.return_value = ["RSV"]
173175
with self.assertRaises(ParameterException) as e:
174176
_ = process_search_params(
175177
{

backend/tests/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import json
55
from unittest.mock import patch, MagicMock
66
from copy import deepcopy
7-
from sample_data.mock_redis_cache import fake_hget
7+
from utils.mock_redis import mock_redis_hget
88

99
from models.utils.validation_utils import convert_disease_codes_to_vaccine_type, get_vaccine_type
1010
from utils.generic_utils import load_json_data, update_target_disease_code
@@ -17,7 +17,7 @@ def setUp(self):
1717
self.json_data = load_json_data(filename="completed_mmr_immunization_event.json")
1818
self.redis_patcher = patch("models.utils.validation_utils.redis_client")
1919
self.mock_redis_client = self.redis_patcher.start()
20-
self.mock_redis_client.hget.side_effect = fake_hget
20+
self.mock_redis_client.hget.side_effect = mock_redis_hget
2121

2222
def tearDown(self):
2323
"""Tear down after each test. This runs after every test"""

backend/tests/sample_data/mock_redis_cache.py renamed to backend/tests/utils/mock_redis.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
MOCK_REDIS_D2V_RESPONSE = {
32
"4740000": "SHINGLES",
43
"6142004": "FLU",
@@ -35,13 +34,13 @@ def get_data(name):
3534
return MOCK_REDIS_V2D_RESPONSE
3635
return {}
3736

38-
def fake_hget(name, key):
37+
def mock_redis_hget(name, key):
3938
ret = get_data(name)
4039
if key in ret:
4140
return ret[key]
4241
return {}
4342

44-
def fake_hkeys(name):
43+
def mock_redis_hkeys(name):
4544
ret = get_data(name)
4645
# return all keys
4746
if isinstance(ret, dict) and ret:

0 commit comments

Comments
 (0)