1- import time
21import unittest
32from utils import (
43 generate_csv ,
76 wait_for_ack_file ,
87 check_ack_file_content ,
98 validate_row_count ,
10- upload_config_file ,
11- generate_csv_with_ordered_100000_rows ,
12- verify_final_ack_file ,
139 delete_file_from_s3
1410)
1511from per_test import monitor
1814 SOURCE_BUCKET ,
1915 INPUT_PREFIX ,
2016 ACK_BUCKET ,
21- PRE_VALIDATION_ERROR ,
22- POST_VALIDATION_ERROR ,
2317 DUPLICATE ,
24- FILE_NAME_VAL_ERROR ,
2518 environment
2619)
2720
@@ -32,10 +25,16 @@ def setUp(self):
3225 self .ack_files = [] # Tracks ack keys
3326
3427 def tearDown (self ):
28+ # get name of unit test
29+ unit_test_name = self ._testMethodName
30+ marker = f"tearDown-{ unit_test_name } "
31+
32+ monitor (marker , is_test = False )
3533 for file_key in self .uploaded_files :
3634 delete_file_from_s3 (SOURCE_BUCKET , file_key )
3735 for ack_key in self .ack_files :
3836 delete_file_from_s3 (ACK_BUCKET , ack_key )
37+ monitor (marker , is_test = False )
3938
4039 if environment != "ref" :
4140 def test_create_success (self ):
@@ -143,110 +142,3 @@ def test_delete_success(self):
143142 ack_content = get_file_content_from_s3 (ACK_BUCKET , ack_key )
144143 check_ack_file_content (ack_content , "OK" , None , "DELETE" )
145144 monitor ("test_delete_success" )
146-
147- def test_pre_validation_error (self ):
148- """Test PRE-VALIDATION error scenario."""
149- monitor ("test_pre_validation_error" )
150- input_file = generate_csv ("PHYLIS" , "TRUE" , action_flag = "CREATE" )
151-
152- key = upload_file_to_s3 (input_file , SOURCE_BUCKET , INPUT_PREFIX )
153- self .uploaded_files .append (key )
154-
155- ack_key = wait_for_ack_file (None , input_file )
156- self .ack_files .append (ack_key )
157-
158- validate_row_count (input_file , ack_key )
159-
160- ack_content = get_file_content_from_s3 (ACK_BUCKET , ack_key )
161- check_ack_file_content (ack_content , "Fatal Error" , PRE_VALIDATION_ERROR , None )
162- monitor ("test_pre_validation_error" )
163-
164- def test_post_validation_error (self ):
165- """Test POST-VALIDATION error scenario."""
166- monitor ("test_post_validation_error" )
167- input_file = generate_csv ("" , "0.3" , action_flag = "CREATE" )
168-
169- key = upload_file_to_s3 (input_file , SOURCE_BUCKET , INPUT_PREFIX )
170- self .uploaded_files .append (key )
171-
172- ack_key = wait_for_ack_file (None , input_file )
173- self .ack_files .append (ack_key )
174-
175- ack_content = get_file_content_from_s3 (ACK_BUCKET , ack_key )
176- check_ack_file_content (ack_content , "Fatal Error" , POST_VALIDATION_ERROR , None )
177- monitor ("test_post_validation_error" )
178-
179- def test_file_name_validation_error (self ):
180- """Test FILE-NAME-VALIDATION error scenario."""
181- monitor ("test_file_name_validation_error" )
182- input_file = generate_csv ("PHYLIS" , "0.3" , action_flag = "CREATE" , file_key = True )
183-
184- key = upload_file_to_s3 (input_file , SOURCE_BUCKET , INPUT_PREFIX )
185- self .uploaded_files .append (key )
186-
187- ack_key = wait_for_ack_file (True , input_file )
188- self .ack_files .append (ack_key )
189-
190- ack_content = get_file_content_from_s3 (ACK_BUCKET , ack_key )
191- check_ack_file_content (ack_content , "Failure" , FILE_NAME_VAL_ERROR , None )
192- monitor ("test_file_name_validation_error" )
193-
194- def test_header_name_validation_error (self ):
195- """Test HEADER-NAME-VALIDATION error scenario."""
196- monitor ("test_header_name_validation_error" )
197- input_file = generate_csv ("PHYLIS" , "0.3" , action_flag = "CREATE" , headers = "NH_NUMBER" )
198-
199- key = upload_file_to_s3 (input_file , SOURCE_BUCKET , INPUT_PREFIX )
200- self .uploaded_files .append (key )
201-
202- ack_key = wait_for_ack_file (True , input_file )
203- self .ack_files .append (ack_key )
204-
205- ack_content = get_file_content_from_s3 (ACK_BUCKET , ack_key )
206- check_ack_file_content (ack_content , "Failure" , FILE_NAME_VAL_ERROR , None )
207- monitor ("test_header_name_validation_error" )
208-
209- # This test updates the permissions_config.json file from the imms-internal-dev-supplier-config
210- # S3 bucket shared across multiple environments (PR environments, internal-dev, int, and ref).
211- # Running this may modify permissions in these environments, causing unintended side effects.
212- @unittest .skip ("Modifies shared S3 permissions configuration" )
213- def test_invalid_permission (self ):
214- """Test INVALID-PERMISSION error scenario."""
215- monitor ("test_invalid_permission" )
216- upload_config_file ("MMR_FULL" ) # permissions_config.json is updated here
217- time .sleep (20 )
218-
219- input_file = generate_csv ("PHYLIS" , "0.3" , action_flag = "CREATE" )
220-
221- key = upload_file_to_s3 (input_file , SOURCE_BUCKET , INPUT_PREFIX )
222- self .uploaded_files .append (key )
223-
224- ack_key = wait_for_ack_file (True , input_file )
225- self .ack_files .append (ack_key )
226-
227- ack_content = get_file_content_from_s3 (ACK_BUCKET , ack_key )
228- check_ack_file_content (ack_content , "Failure" , FILE_NAME_VAL_ERROR , None )
229-
230- upload_config_file ("COVID19_FULL" )
231- time .sleep (20 )
232- monitor ("test_invalid_permission" )
233-
234- else :
235- def test_end_to_end_speed_test_with_100000_rows (self ):
236- monitor ("test_end_to_end_speed_test_with_100000_rows" )
237- """Test end_to_end_speed_test_with_100000_rows scenario with full integration"""
238- input_file = generate_csv_with_ordered_100000_rows (None )
239-
240- key = upload_file_to_s3 (input_file , SOURCE_BUCKET , INPUT_PREFIX )
241- self .uploaded_files .append (key )
242-
243- final_ack_key = wait_for_ack_file (None , input_file , timeout = 1800 )
244- self .ack_files .append (final_ack_key )
245-
246- response = verify_final_ack_file (final_ack_key )
247- assert response is True
248- monitor ("test_end_to_end_speed_test_with_100000_rows" )
249-
250-
251- if __name__ == "__main__" :
252- unittest .main ()
0 commit comments