Skip to content

Commit 4a08db9

Browse files
committed
Resolve merge tests
1 parent e49362c commit 4a08db9

File tree

6 files changed

+118
-48
lines changed

6 files changed

+118
-48
lines changed

backend/poetry.lock

Lines changed: 75 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/src/models/constants.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ class Constants:
4040

4141
ALLOWED_CONTAINED_RESOURCES = {"Practitioner", "Patient"}
4242

43-
SUPPLIER_PERMISSIONS_KEY = "supplier_permissions"
43+
SUPPLIER_PERMISSIONS_KEY = "supplier_permissions"
44+
VACCINE_TYPE_TO_DISEASES_HASH_KEY = "vacc_to_diseases"
45+
DISEASES_TO_VACCINE_TYPE_HASH_KEY = "diseases_to_vacc"

backend/tests/test_fhir_controller.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,35 @@
3232
from parameter_parser import patient_identifier_system, process_search_params
3333
from tests.utils.generic_utils import load_json_data
3434
from tests.utils.values_for_tests import ValidValues
35+
from utils.mock_redis import MOCK_REDIS_V2D_RESPONSE
3536

36-
"test"
37+
class TestFhirControllerBase(unittest.TestCase):
38+
"""Base class for all tests to set up common fixtures"""
3739

38-
39-
class TestFhirController(unittest.TestCase):
4040
def setUp(self):
41+
super().setUp()
42+
self.redis_patcher = patch("parameter_parser.redis_client")
43+
self.mock_redis_client = self.redis_patcher.start()
44+
self.logger_info_patcher = patch("logging.Logger.info")
45+
self.mock_logger_info = self.logger_info_patcher.start()
46+
47+
def tearDown(self):
48+
self.redis_patcher.stop()
49+
self.logger_info_patcher.stop()
50+
super().tearDown()
51+
52+
class TestFhirController(TestFhirControllerBase):
53+
def setUp(self):
54+
super().setUp()
4155
self.service = create_autospec(FhirService)
4256
self.repository = create_autospec(ImmunizationRepository)
4357
self.authorizer = create_autospec(Authorization)
4458
self.controller = FhirController(self.authorizer, self.service)
4559

60+
def tearDown(self):
61+
self.redis_patcher.stop()
62+
super().tearDown()
63+
4664
def test_create_response(self):
4765
"""it should return application/fhir+json with correct status code"""
4866
body = {"message": "a body"}
@@ -1596,8 +1614,9 @@ def test_immunization_unhandled_error(self, mock_get_supplier_permissions):
15961614
self.assertEqual(body["resourceType"], "OperationOutcome")
15971615
self.assertEqual(body["issue"][0]["code"], "exception")
15981616

1599-
class TestSearchImmunizations(unittest.TestCase):
1617+
class TestSearchImmunizations(TestFhirControllerBase):
16001618
def setUp(self):
1619+
super().setUp()
16011620
self.service = create_autospec(FhirService)
16021621
self.authorizer = create_autospec(Authorization)
16031622
self.controller = FhirController(self.authorizer, self.service)
@@ -1607,11 +1626,15 @@ def setUp(self):
16071626
self.date_to_key = "-date.to"
16081627
self.nhs_number_valid_value = "9000000009"
16091628
self.patient_identifier_valid_value = f"{patient_identifier_system}|{self.nhs_number_valid_value}"
1629+
self.mock_redis_client.hkeys.return_value = MOCK_REDIS_V2D_RESPONSE
1630+
1631+
def tearDown(self):
1632+
return super().tearDown()
16101633

16111634
@patch("fhir_controller.get_supplier_permissions")
16121635
def test_get_search_immunizations(self, mock_get_supplier_permissions):
16131636
"""it should search based on patient_identifier and immunization_target"""
1614-
1637+
16151638
mock_get_supplier_permissions.return_value = ["covid19.s"]
16161639
search_result = Bundle.construct()
16171640
self.service.search_immunizations.return_value = search_result
@@ -1906,6 +1929,7 @@ def test_post_search_immunizations_for_unauthorized_vaccine_type_search_403(self
19061929

19071930
@patch("fhir_controller.process_search_params", wraps=process_search_params)
19081931
def test_uses_parameter_parser(self, process_search_params: Mock):
1932+
self.mock_redis_client.hkeys.return_value = MOCK_REDIS_V2D_RESPONSE
19091933
lambda_event = {
19101934
"multiValueQueryStringParameters": {
19111935
self.patient_identifier_key: ["https://fhir.nhs.uk/Id/nhs-number|9000000009"],

backend/tests/test_fhir_repository.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ def test_create_patient_gsi(self):
351351

352352
def test_create_patient_with_vaccine_type(self):
353353
"""Patient record should have a sort-key based on vaccine-type"""
354+
self.mock_redis_client.hget.return_value = VaccineTypes.flu
354355
imms = create_covid_19_immunization_dict("an-id")
355356

356357
update_target_disease_code(imms, DiseaseCodes.flu)

backend/tests/test_forwarding_batch_lambda.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import os
33
from unittest import TestCase
44
from unittest.mock import patch, MagicMock
5-
import boto3
65
from boto3 import resource as boto3_resource
76
from moto import mock_aws
87
from models.errors import (
@@ -18,12 +17,9 @@
1817
import json
1918

2019
from utils.test_utils_for_batch import ForwarderValues, MockFhirImmsResources
21-
from utils.mock_redis import MOCK_REDIS_D2V_RESPONSE
2220

2321
with patch.dict("os.environ", ForwarderValues.MOCK_ENVIRONMENT_DICT):
2422
from forwarding_batch_lambda import forward_lambda_handler, create_diagnostics_dictionary, forward_request_to_dynamo
25-
26-
2723
@mock_aws
2824
@patch.dict(os.environ, ForwarderValues.MOCK_ENVIRONMENT_DICT)
2925
class TestForwardLambdaHandler(TestCase):
@@ -61,7 +57,6 @@ def setUp(self):
6157
)
6258
self.redis_patcher = patch("models.utils.validation_utils.redis_client")
6359
self.mock_redis_client = self.redis_patcher.start()
64-
self.mock_redis_client.hget.return_value = MOCK_REDIS_D2V_RESPONSE
6560

6661
def tearDown(self):
6762
"""Tear down after each test. This runs after every test"""
@@ -155,6 +150,7 @@ def assert_values_in_sqs_messages(self, mock_send_message, test_cases):
155150
assert message[key][sub_key] == sub_value
156151

157152
else:
153+
print(f"Asserting {key} {message[key]} == {value}")
158154
assert message[key] == value
159155

160156
def assert_dynamo_item(self, expected_dynamo_item):
@@ -188,7 +184,7 @@ def test_forward_lambda_handler_single_operations(self, mock_send_message):
188184
"PatientSK": "RSV#4d2ac1eb-080f-4e54-9598-f2d53334681c",
189185
}
190186
)
191-
self.mock_redis_client.hget.return_value = MOCK_REDIS_D2V_RESPONSE
187+
self.mock_redis_client.hget.return_value = "RSV"
192188

193189
test_cases = [
194190
{
@@ -391,14 +387,17 @@ def test_forward_lambda_handler_multiple_scenarios(self, mock_send_message):
391387
self.table.put_item(
392388
Item={
393389
"PK": "Immunization#4d2ac1eb-080f-4e54-9598-f2d53334681c",
394-
"PatientPK": "Patient#9177036360",
390+
"PatientPK": "Patient#9732928395", # 9177036360",
391+
"PatientSK": "RSV#4d2ac1eb-080f-4e54-9598-f2d53334681c",
395392
"IdentifierPK": "https://www.ravs.england.nhs.uk/#RSV_002",
396393
"Version": 1,
397394
}
398395
)
399396
mock_send_message.reset_mock()
400397
event = self.generate_event(test_cases)
401398

399+
400+
self.mock_redis_client.hget.return_value = "RSV"
402401
forward_lambda_handler(event, {})
403402

404403
self.assert_dynamo_item(table_item)
@@ -412,7 +411,7 @@ def test_forward_lambda_handler_update_scenarios(self, mock_send_message):
412411
input: generates the kinesis row data for the event,
413412
expected_keys (list): expected output dictionary keys,
414413
expected_values (dict): expected output dictionary values"""
415-
414+
self.mock_redis_client.hget.return_value = "RSV"
416415
pk_test_update = "Immunization#4d2ac1eb-080f-4e54-9598-f2d53334687r"
417416
self.table.put_item(
418417
Item={

backend/tests/utils/mock_redis.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22

3-
MOCK_REDIS_D2V_RESPONSE = json.dumps({
3+
MOCK_REDIS_D2V_RESPONSE = {
44
"4740000": "SHINGLES",
55
"6142004": "FLU",
66
"16814004": "PCV13",
@@ -12,7 +12,7 @@
1212
"14189004:36653000:36989005": "MMR",
1313
"14189004:36653000:36989005:38907003": "MMRV",
1414
"397430003:398102009:76902006": "3in1"
15-
})
15+
}
1616

1717
MOCK_REDIS_V2D_RESPONSE = {
1818
"PERTUSSIS": "[{\"code\": \"27836007\", \"term\": \"Pertussis (disorder)\"}]",
@@ -80,4 +80,4 @@ def mock_redis_hkeys(name):
8080
# return all keys
8181
if isinstance(ret, dict) and ret:
8282
return list(ret.keys())
83-
return []
83+
return []

0 commit comments

Comments
 (0)