Skip to content

Commit 9056a2d

Browse files
committed
remock test_fhir_repo
1 parent 4f756cc commit 9056a2d

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

backend/tests/test_fhir_repository.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
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 utils.mock_redis import mock_redis_hget
2019

2120
def _make_immunization_pk(_id):
2221
return f"Immunization#{_id}"
@@ -32,7 +31,6 @@ def setUp(self):
3231
super().setUp()
3332
self.redis_patcher = patch("models.utils.validation_utils.redis_client")
3433
self.mock_redis_client = self.redis_patcher.start()
35-
self.mock_redis_client.hget.side_effect = mock_redis_hget
3634
self.logger_info_patcher = patch("logging.Logger.info")
3735
self.mock_logger_info = self.logger_info_patcher.start()
3836

@@ -183,6 +181,8 @@ def tearDown(self):
183181

184182
def test_create_immunization(self):
185183
"""it should create Immunization, and return created object"""
184+
185+
self.mock_redis_client.hget.return_value = "COVID19"
186186
imms = create_covid_19_immunization_dict(imms_id="an-id")
187187

188188
self.table.put_item = MagicMock(return_value={"ResponseMetadata": {"HTTPStatusCode": 200}})
@@ -206,6 +206,8 @@ def test_create_immunization(self):
206206

207207
def test_create_immunization_batch(self):
208208
"""it should create Immunization, and return created object"""
209+
210+
self.mock_redis_client.hget.return_value = "COVID19"
209211
imms = create_covid_19_immunization_dict(imms_id="an-id")
210212

211213
self.table.put_item = MagicMock(return_value={"ResponseMetadata": {"HTTPStatusCode": 200}})
@@ -229,6 +231,8 @@ def test_create_immunization_batch(self):
229231

230232
def test_add_patient(self):
231233
"""it should store patient along the Immunization resource"""
234+
235+
self.mock_redis_client.hget.return_value = "COVID19"
232236
imms = create_covid_19_immunization_dict("an-id")
233237
self.table.put_item = MagicMock(return_value={"ResponseMetadata": {"HTTPStatusCode": 200}})
234238
self.table.query = MagicMock(return_value={})
@@ -252,6 +256,8 @@ def test_add_patient(self):
252256
def test_create_immunization_makes_new_id(self):
253257
"""create should create new Logical ID even if one is already provided"""
254258
imms_id = "original-id-from-request"
259+
260+
self.mock_redis_client.hget.return_value = "COVID19"
255261
imms = create_covid_19_immunization_dict(imms_id)
256262
self.table.put_item = MagicMock(return_value={"ResponseMetadata": {"HTTPStatusCode": 200}})
257263
self.table.query = MagicMock(return_value={})
@@ -264,6 +270,8 @@ def test_create_immunization_makes_new_id(self):
264270

265271
def test_create_immunization_returns_new_id(self):
266272
"""create should return the persisted object i.e. with new id"""
273+
274+
self.mock_redis_client.hget.return_value = "COVID19"
267275
imms_id = "original-id-from-request"
268276
imms = create_covid_19_immunization_dict(imms_id)
269277
self.table.put_item = MagicMock(return_value={"ResponseMetadata": {"HTTPStatusCode": 200}})
@@ -275,6 +283,8 @@ def test_create_immunization_returns_new_id(self):
275283

276284
def test_create_should_catch_dynamo_error(self):
277285
"""it should throw UnhandledResponse when the response from dynamodb can't be handled"""
286+
287+
self.mock_redis_client.hget.return_value = "COVID19"
278288
bad_request = 400
279289
response = {"ResponseMetadata": {"HTTPStatusCode": bad_request}}
280290
self.table.put_item = MagicMock(return_value=response)
@@ -291,6 +301,8 @@ def test_create_should_catch_dynamo_error(self):
291301

292302
def test_create_throws_error_when_identifier_already_in_dynamodb(self):
293303
"""it should throw UnhandledResponse when trying to update an immunization with an identfier that is already stored"""
304+
305+
self.mock_redis_client.hget.return_value = "COVID19"
294306
imms_id = "an-id"
295307
imms = create_covid_19_immunization_dict(imms_id)
296308
imms["patient"] = self.patient
@@ -318,6 +330,8 @@ def tearDown(self):
318330

319331
def test_create_patient_gsi(self):
320332
"""create Immunization method should create Patient index with nhs-number as ID and no system"""
333+
334+
self.mock_redis_client.hget.return_value = "COVID19"
321335
imms = create_covid_19_immunization_dict("an-id")
322336

323337
nhs_number = "1234567890"
@@ -335,6 +349,8 @@ def test_create_patient_gsi(self):
335349

336350
def test_create_patient_with_vaccine_type(self):
337351
"""Patient record should have a sort-key based on vaccine-type"""
352+
353+
self.mock_redis_client.hget.return_value = "FLU"
338354
imms = create_covid_19_immunization_dict("an-id")
339355

340356
update_target_disease_code(imms, "6142004")
@@ -352,6 +368,8 @@ def test_create_patient_with_vaccine_type(self):
352368

353369
def test_create_patient_with_unauthorised_vaccine_type_permissions(self):
354370
"""Patient record should not be created"""
371+
372+
self.mock_redis_client.hget.return_value = "FLU"
355373
imms = create_covid_19_immunization_dict("an-id")
356374

357375
update_target_disease_code(imms, "6142004")
@@ -372,6 +390,8 @@ def tearDown(self):
372390

373391
def test_update1(self):
374392
"""it should update record by replacing both Immunization and Patient"""
393+
394+
self.mock_redis_client.hget.return_value = "COVID19"
375395
imms_id = "an-imms-id"
376396
imms = create_covid_19_immunization_dict(imms_id)
377397
imms["patient"] = self.patient
@@ -425,6 +445,8 @@ def test_update1(self):
425445

426446
def test_update_throws_error_when_response_can_not_be_handled(self):
427447
"""it should throw UnhandledResponse when the response from dynamodb can't be handled"""
448+
449+
self.mock_redis_client.hget.return_value = "COVID19"
428450
imms_id = "an-id"
429451
imms = create_covid_19_immunization_dict(imms_id)
430452
imms["patient"] = self.patient
@@ -444,6 +466,8 @@ def test_update_throws_error_when_response_can_not_be_handled(self):
444466

445467
def test_update_throws_error_when_identifier_already_in_dynamodb(self):
446468
"""it should throw IdentifierDuplicationError when trying to update an immunization with an identfier that is already stored"""
469+
470+
self.mock_redis_client.hget.return_value = "COVID19"
447471
imms_id = "an-id"
448472
imms = create_covid_19_immunization_dict(imms_id)
449473
imms["patient"] = self.patient
@@ -697,6 +721,8 @@ def tearDown(self):
697721

698722
def test_decimal_on_create(self):
699723
"""it should create Immunization, and preserve decimal value"""
724+
725+
self.mock_redis_client.hget.return_value = "COVID19"
700726
imms = create_covid_19_immunization_dict(imms_id="an-id")
701727
imms["doseQuantity"] = 0.7477
702728

@@ -783,6 +809,7 @@ def run_update_immunization_test(self, imms_id, imms, resource, updated_dose_qua
783809

784810
def test_decimal_on_update(self):
785811
"""it should update record when replacing doseQuantity and keep decimal precision"""
812+
self.mock_redis_client.hget.return_value = "COVID19"
786813
imms_id = "an-imms-id"
787814
imms = create_covid_19_immunization_dict(imms_id)
788815
imms["doseQuantity"] = 1.5556
@@ -794,6 +821,7 @@ def test_decimal_on_update(self):
794821

795822
def test_decimal_on_update_patient(self):
796823
"""it should update record by replacing both Immunization and Patient and dosequantity"""
824+
self.mock_redis_client.hget.return_value = "COVID19"
797825
imms_id = "an-imms-id"
798826
imms = create_covid_19_immunization_dict(imms_id)
799827
imms["doseQuantity"] = 1.590

0 commit comments

Comments
 (0)