|
6 | 6 | import boto3 |
7 | 7 | import botocore.exceptions |
8 | 8 | import simplejson as json |
9 | | -from boto3.dynamodb.conditions import Key |
10 | 9 | from moto import mock_aws |
11 | 10 |
|
12 | 11 | from common.models.errors import ( |
@@ -139,53 +138,6 @@ def test_create_immunization_conditionalcheckfailedexception_error(self): |
139 | 138 | with self.assertRaises(ResourceFoundError): |
140 | 139 | self.repository.create_immunization(self.immunization, "supplier", "vax-type", self.table, False) |
141 | 140 |
|
142 | | - def create_immunization_uses_separate_identifier_pk_for_legacy_identifiers_test_logic( |
143 | | - self, legacy_identifier_system: str, new_identifier_system: str |
144 | | - ): |
145 | | - """it should use a new identifier_pk for a legacy identifier""" |
146 | | - self.mock_redis_getter.return_value = self.mock_redis |
147 | | - |
148 | | - legacy_immunization = create_covid_immunization_dict(imms_id) |
149 | | - legacy_immunization["identifier"][0]["system"] = legacy_identifier_system |
150 | | - |
151 | | - self.repository.create_immunization(legacy_immunization, "supplier", "vax-type", self.table, False) |
152 | | - item = self.table.put_item.call_args.kwargs["Item"] |
153 | | - |
154 | | - self.table.query.assert_called_with( |
155 | | - IndexName="IdentifierGSI", |
156 | | - KeyConditionExpression=Key("IdentifierPK").eq(new_identifier_system + "#" + "ACME-vacc123456"), |
157 | | - Limit=1, |
158 | | - ) |
159 | | - |
160 | | - self.table.put_item.assert_called_with( |
161 | | - Item={ |
162 | | - "PK": ANY, |
163 | | - "PatientPK": ANY, |
164 | | - "PatientSK": ANY, |
165 | | - "Resource": json.dumps( |
166 | | - legacy_immunization, use_decimal=True |
167 | | - ), # resource should contain legacy identifier |
168 | | - "IdentifierPK": new_identifier_system + "#" + "ACME-vacc123456", |
169 | | - "Operation": "CREATE", |
170 | | - "Version": 1, |
171 | | - "SupplierSystem": "supplier", |
172 | | - }, |
173 | | - ConditionExpression=ANY, |
174 | | - ) |
175 | | - self.assertEqual(item["PK"], f"Immunization#{legacy_immunization['id']}") |
176 | | - |
177 | | - def test_create_immunization_uses_separate_identifier_pk_for_legacy_identifiers_tpp(self): |
178 | | - """it should use a V5 identifier_pk for a legacy TPP identifier""" |
179 | | - self.create_immunization_uses_separate_identifier_pk_for_legacy_identifiers_test_logic( |
180 | | - "YGA", "https://tpp-uk.com/Id/ve/vacc" |
181 | | - ) |
182 | | - |
183 | | - def test_create_immunization_uses_separate_identifier_pk_for_legacy_identifiers_emis(self): |
184 | | - """it should use a V5 identifier_pk for a legacy EMIS identifier""" |
185 | | - self.create_immunization_uses_separate_identifier_pk_for_legacy_identifiers_test_logic( |
186 | | - "YGJ", "https://emishealth.com/identifiers/vacc" |
187 | | - ) |
188 | | - |
189 | 141 |
|
190 | 142 | class TestUpdateImmunization(TestImmunizationBatchRepository): |
191 | 143 | def test_update_immunization(self): |
@@ -348,63 +300,6 @@ def test_update_immunization_conditionalcheckfailedexception_error(self): |
348 | 300 | ) |
349 | 301 | self.repository.update_immunization(self.immunization, "supplier", "vax-type", self.table, False) |
350 | 302 |
|
351 | | - def update_immunization_uses_separate_identifier_pk_for_legacy_identifiers_test_logic( |
352 | | - self, legacy_identifier_system: str, new_identifier_system: str |
353 | | - ): |
354 | | - """it should use a new identifier_pk for a legacy identifier""" |
355 | | - legacy_immunization = create_covid_immunization_dict(imms_id) |
356 | | - legacy_immunization["identifier"][0]["system"] = legacy_identifier_system |
357 | | - |
358 | | - self.table.query = MagicMock( |
359 | | - return_value={ |
360 | | - "Count": 1, |
361 | | - "Items": [ |
362 | | - { |
363 | | - "PK": _make_immunization_pk(imms_id), |
364 | | - "Resource": json.dumps(legacy_immunization), |
365 | | - "Version": 1, |
366 | | - } |
367 | | - ], |
368 | | - } |
369 | | - ) |
370 | | - |
371 | | - self.repository.update_immunization(legacy_immunization, "supplier", "vax-type", self.table, True) |
372 | | - |
373 | | - self.table.query.assert_called_with( |
374 | | - IndexName="IdentifierGSI", |
375 | | - KeyConditionExpression=Key("IdentifierPK").eq(new_identifier_system + "#" + "ACME-vacc123456"), |
376 | | - Limit=1, |
377 | | - ) |
378 | | - |
379 | | - expected_values = { |
380 | | - ":timestamp": ANY, |
381 | | - ":patient_pk": ANY, |
382 | | - ":patient_sk": ANY, |
383 | | - ":imms_resource_val": json.dumps(legacy_immunization), # resource should contain legacy identifier |
384 | | - ":operation": "UPDATE", |
385 | | - ":version": 2, |
386 | | - ":supplier_system": "supplier", |
387 | | - } |
388 | | - |
389 | | - self.table.update_item.assert_called_with( |
390 | | - Key={"PK": _make_immunization_pk(imms_id)}, |
391 | | - UpdateExpression=ANY, |
392 | | - ExpressionAttributeNames={"#imms_resource": "Resource"}, |
393 | | - ExpressionAttributeValues=expected_values, |
394 | | - ReturnValues=ANY, |
395 | | - ConditionExpression=ANY, |
396 | | - ) |
397 | | - |
398 | | - def test_update_immunization_uses_separate_identifier_pk_for_legacy_identifiers_tpp(self): |
399 | | - self.update_immunization_uses_separate_identifier_pk_for_legacy_identifiers_test_logic( |
400 | | - "YGA", "https://tpp-uk.com/Id/ve/vacc" |
401 | | - ) |
402 | | - |
403 | | - def test_update_immunization_uses_separate_identifier_pk_for_legacy_identifiers_emis(self): |
404 | | - self.update_immunization_uses_separate_identifier_pk_for_legacy_identifiers_test_logic( |
405 | | - "YGJ", "https://emishealth.com/identifiers/vacc" |
406 | | - ) |
407 | | - |
408 | 303 |
|
409 | 304 | class TestDeleteImmunization(TestImmunizationBatchRepository): |
410 | 305 | def test_delete_immunization(self): |
@@ -518,58 +413,6 @@ def test_delete_immunization_conditionalcheckfailedexception_error(self): |
518 | 413 | ) |
519 | 414 | self.repository.delete_immunization(self.immunization, "supplier", "vax-type", self.table, False) |
520 | 415 |
|
521 | | - def delete_immunization_uses_separate_identifier_pk_for_legacy_identifiers_test_logic( |
522 | | - self, legacy_identifier_system: str, new_identifier_system: str |
523 | | - ): |
524 | | - """it should use a new identifier_pk for a legacy identifier""" |
525 | | - legacy_immunization = create_covid_immunization_dict(imms_id) |
526 | | - legacy_immunization["identifier"][0]["system"] = legacy_identifier_system |
527 | | - |
528 | | - self.table.query = MagicMock( |
529 | | - return_value={ |
530 | | - "Count": 1, |
531 | | - "Items": [ |
532 | | - { |
533 | | - "PK": _make_immunization_pk(imms_id), |
534 | | - "Resource": json.dumps(legacy_immunization), |
535 | | - "Version": 1, |
536 | | - } |
537 | | - ], |
538 | | - } |
539 | | - ) |
540 | | - |
541 | | - response = self.repository.delete_immunization(legacy_immunization, "supplier", "vax-type", self.table, True) |
542 | | - |
543 | | - self.table.query.assert_called_with( |
544 | | - IndexName="IdentifierGSI", |
545 | | - KeyConditionExpression=Key("IdentifierPK").eq(new_identifier_system + "#" + "ACME-vacc123456"), |
546 | | - Limit=1, |
547 | | - ) |
548 | | - |
549 | | - self.table.update_item.assert_called_with( |
550 | | - Key={"PK": _make_immunization_pk(imms_id)}, |
551 | | - UpdateExpression="SET DeletedAt = :timestamp, Operation = :operation, SupplierSystem = :supplier_system", |
552 | | - ExpressionAttributeValues={ |
553 | | - ":timestamp": ANY, |
554 | | - ":operation": "DELETE", |
555 | | - ":supplier_system": "supplier", |
556 | | - }, |
557 | | - ReturnValues=ANY, |
558 | | - ConditionExpression=ANY, |
559 | | - ) |
560 | | - |
561 | | - self.assertEqual(response, f"Immunization#{self.immunization['id']}") |
562 | | - |
563 | | - def test_delete_immunization_uses_separate_identifier_pk_for_legacy_identifiers_tpp(self): |
564 | | - self.delete_immunization_uses_separate_identifier_pk_for_legacy_identifiers_test_logic( |
565 | | - "YGA", "https://tpp-uk.com/Id/ve/vacc" |
566 | | - ) |
567 | | - |
568 | | - def test_delete_immunization_uses_separate_identifier_pk_for_legacy_identifiers_emis(self): |
569 | | - self.delete_immunization_uses_separate_identifier_pk_for_legacy_identifiers_test_logic( |
570 | | - "YGJ", "https://emishealth.com/identifiers/vacc" |
571 | | - ) |
572 | | - |
573 | 416 |
|
574 | 417 | @mock_aws |
575 | 418 | @patch.dict(os.environ, {"DYNAMODB_TABLE_NAME": "TestTable"}) |
|
0 commit comments