Skip to content

Commit a0c6301

Browse files
committed
tests pass
1 parent 698a7ca commit a0c6301

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

backend/tests/sample_data/mock_redis_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ def fake_hget(name, key):
4444
def fake_hkeys(name):
4545
ret = get_data(name)
4646
# return all keys
47-
if ret != {}:
47+
if isinstance(ret, dict) and ret:
4848
return list(ret.keys())
4949
return []

backend/tests/test_fhir_controller.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,30 @@
2222
InvalidPatientId,
2323
CustomValidationError,
2424
ParameterException,
25-
InconsistentIdError,
2625
UnauthorizedVaxError,
27-
UnauthorizedError,
2826
IdentifierDuplicationError,
2927
)
3028
from tests.utils.immunization_utils import create_covid_19_immunization
3129
from parameter_parser import patient_identifier_system, process_search_params
3230
from tests.utils.generic_utils import load_json_data
33-
from tests.utils.values_for_tests import ValidValues
31+
from sample_data.mock_redis_cache import fake_hkeys
3432

35-
"test"
33+
34+
class TestFhirControllerBase(unittest.TestCase):
35+
"""Base class for all tests to set up common fixtures"""
36+
37+
def setUp(self):
38+
super().setUp()
39+
self.redis_patcher = patch("parameter_parser.redis_client")
40+
self.mock_redis_client = self.redis_patcher.start()
41+
self.mock_redis_client.hkeys.side_effect = fake_hkeys
42+
self.logger_info_patcher = patch("logging.Logger.info")
43+
self.mock_logger_info = self.logger_info_patcher.start()
44+
45+
def tearDown(self):
46+
self.redis_patcher.stop()
47+
self.logger_info_patcher.stop()
48+
super().tearDown()
3649

3750

3851
class TestFhirController(unittest.TestCase):
@@ -1561,8 +1574,9 @@ def test_immunization_unhandled_error(self, mock_get_supplier_permissions):
15611574
self.assertEqual(body["resourceType"], "OperationOutcome")
15621575
self.assertEqual(body["issue"][0]["code"], "exception")
15631576

1564-
class TestSearchImmunizations(unittest.TestCase):
1577+
class TestSearchImmunizations(TestFhirControllerBase):
15651578
def setUp(self):
1579+
super().setUp()
15661580
self.service = create_autospec(FhirService)
15671581
self.authorizer = create_autospec(Authorization)
15681582
self.controller = FhirController(self.authorizer, self.service)
@@ -1573,6 +1587,9 @@ def setUp(self):
15731587
self.nhs_number_valid_value = "9000000009"
15741588
self.patient_identifier_valid_value = f"{patient_identifier_system}|{self.nhs_number_valid_value}"
15751589

1590+
def tearDown(self):
1591+
return super().tearDown()
1592+
15761593
@patch("fhir_controller.get_supplier_permissions")
15771594
def test_get_search_immunizations(self, mock_get_supplier_permissions):
15781595
"""it should search based on patient_identifier and immunization_target"""

0 commit comments

Comments
 (0)