@@ -73,7 +73,7 @@ def setUp(self):
7373 @patch ("create_notification.get_practitioner_details_from_pds" )
7474 @patch ("create_notification.get_service_url" )
7575 @patch ("create_notification.uuid.uuid4" )
76- def test_create_mns_notification_success_with_real_payload (self , mock_uuid , mock_get_service_url , mock_get_gp ):
76+ def test_create_mns_notification_complete_payload (self , mock_uuid , mock_get_service_url , mock_get_gp ):
7777 mock_uuid .return_value = MagicMock (hex = "236a1d4a-5d69-4fa9-9c7f-e72bf505aa5b" )
7878 mock_get_service_url .return_value = self .expected_immunisation_url
7979 mock_get_gp .return_value = self .expected_gp_ods_code
@@ -84,47 +84,33 @@ def test_create_mns_notification_success_with_real_payload(self, mock_uuid, mock
8484 self .assertEqual (result ["type" ], IMMUNISATION_TYPE )
8585 self .assertEqual (result ["source" ], self .expected_immunisation_url )
8686 self .assertEqual (result ["subject" ], "9481152782" )
87- self .assertIn ("id" , result )
88- self .assertIn ("time" , result )
89- self .assertIn ("dataref" , result )
90- self .assertIn ("filtering" , result )
91-
92- @patch ("create_notification.get_practitioner_details_from_pds" )
93- @patch ("create_notification.get_service_url" )
94- def test_create_mns_notification_dataref_format_real_payload (self , mock_get_service_url , mock_get_gp ):
95- mock_get_service_url .return_value = self .expected_immunisation_url
96- mock_get_gp .return_value = self .expected_gp_ods_code
97-
98- result = create_mns_notification (self .sample_sqs_event )
9987
10088 expected_dataref = f"{ self .expected_immunisation_url } /Immunization/d058014c-b0fd-4471-8db9-3316175eb825"
10189 self .assertEqual (result ["dataref" ], expected_dataref )
10290
103- @patch ("create_notification.get_practitioner_details_from_pds" )
104- @patch ("create_notification.get_service_url" )
105- def test_create_mns_notification_filtering_fields_real_payload (self , mock_get_service_url , mock_get_gp ):
106- mock_get_service_url .return_value = self .expected_immunisation_url
107- mock_get_gp .return_value = self .expected_gp_ods_code
108-
109- result = create_mns_notification (self .sample_sqs_event )
110-
11191 filtering = result ["filtering" ]
11292 self .assertEqual (filtering ["generalpractitioner" ], self .expected_gp_ods_code )
11393 self .assertEqual (filtering ["sourceorganisation" ], "B0C4P" )
11494 self .assertEqual (filtering ["sourceapplication" ], "TPP" )
11595 self .assertEqual (filtering ["immunisationtype" ], "hib" )
11696 self .assertEqual (filtering ["action" ], "CREATE" )
117- self .assertIsInstance (filtering ["subjectage" ], str )
97+ self .assertEqual (filtering ["subjectage" ], "21" )
98+
99+ self .assertIn ("id" , result )
100+ self .assertIsInstance (result ["id" ], str )
118101
119102 @patch ("create_notification.get_practitioner_details_from_pds" )
120103 @patch ("create_notification.get_service_url" )
121- def test_create_mns_notification_age_calculation_real_payload (self , mock_get_service_url , mock_get_gp ):
122- mock_get_service_url .return_value = self .expected_immunisation_url
123- mock_get_gp .return_value = self .expected_gp_ods_code
104+ def test_create_mns_notification_missing_nhs_number (self , mock_get_service_url , mock_get_gp ):
105+ sqs_event_data = copy .deepcopy (self .sample_sqs_event )
124106
125- result = create_mns_notification (self .sample_sqs_event )
107+ body = json .loads (sqs_event_data ["body" ])
108+ body ["dynamodb" ]["NewImage" ]["Imms" ]["M" ]["NHS_NUMBER" ]["S" ] = ""
109+ sqs_event_data ["body" ] = json .dumps (body )
126110
127- self .assertEqual (result ["filtering" ]["subjectage" ], "21" )
111+ with self .assertRaises (ValueError ) as context :
112+ create_mns_notification (sqs_event_data )
113+ self .assertIn ("NHS number is required" , str (context .exception ))
128114
129115 @patch ("create_notification.get_practitioner_details_from_pds" )
130116 @patch ("create_notification.get_service_url" )
@@ -136,17 +122,6 @@ def test_create_mns_notification_calls_get_practitioner_real_payload(self, mock_
136122
137123 mock_get_gp .assert_called_once_with ("9481152782" )
138124
139- @patch ("create_notification.get_practitioner_details_from_pds" )
140- @patch ("create_notification.get_service_url" )
141- def test_create_mns_notification_uuid_generated (self , mock_get_service_url , mock_get_gp ):
142- mock_get_service_url .return_value = self .expected_immunisation_url
143- mock_get_gp .return_value = self .expected_gp_ods_code
144-
145- result1 = create_mns_notification (self .sample_sqs_event )
146- result2 = create_mns_notification (self .sample_sqs_event )
147-
148- self .assertNotEqual (result1 ["id" ], result2 ["id" ])
149-
150125 @patch ("create_notification.get_practitioner_details_from_pds" )
151126 @patch ("create_notification.get_service_url" )
152127 def test_create_mns_notification_invalid_json_body (self , mock_get_service_url , mock_get_gp ):
@@ -200,7 +175,7 @@ def test_create_mns_notification_missing_imms_data_field(self, mock_get_service_
200175 "body" : json .dumps ({"dynamodb" : {"NewImage" : {"ImmsID" : {"S" : "test-id" }}}}),
201176 }
202177
203- with self .assertRaises ((KeyError , TypeError )):
178+ with self .assertRaises ((KeyError , TypeError , ValueError )):
204179 create_mns_notification (incomplete_event )
205180
206181 @patch ("create_notification.get_practitioner_details_from_pds" )
@@ -385,7 +360,3 @@ def test_unwrap_list_type(self):
385360 value = {"L" : [{"S" : "item1" }, {"S" : "item2" }]}
386361 result = _unwrap_dynamodb_value (value )
387362 self .assertEqual (result , [{"S" : "item1" }, {"S" : "item2" }])
388-
389-
390- if __name__ == "__main__" :
391- unittest .main ()
0 commit comments