99DOWNLOAD_FILE_PATH = f'{ Path .cwd ()} /downloads'
1010SAVED_FILE_PATH = f'{ Path .cwd ()} /tests/unit_tests/test_files'
1111
12- SUCCESS_FILE_NAME = 'success_1_all_attrs .zip'
13- MAC_SUCCESS_FILE_NAME = 'success_2_mac_issue .zip'
12+ SUCCESS_FILE_NAME = 'browncounty-mn-us--flex-v2 .zip'
13+ MAC_SUCCESS_FILE_NAME = 'otterexpress-mn-us--flex-v2 .zip'
1414FAILURE_FILE_NAME = 'fail_schema_1.zip'
1515
16- DATA_TYPE = 'gtfs_flex'
17- SCHEMA_VERSION = 'v2.0'
18-
1916
2017class TestSuccessWithMacOSFile (unittest .TestCase ):
2118 @patch .object (GTFSFlexValidation , 'download_single_file' )
@@ -35,10 +32,11 @@ def setUp(self, mock_download_single_file):
3532 self .validator .file_relative_path = MAC_SUCCESS_FILE_NAME
3633 self .validator .container_name = None
3734 self .validator .settings = Settings ()
35+ self .validator .prefix = self .validator .settings .get_unique_id ()
3836 mock_download_single_file .return_value = file_path
3937
4038 def tearDown (self ):
41- pass
39+ GTFSFlexValidation . clean_up ( os . path . join ( DOWNLOAD_FILE_PATH , self . validator . prefix ))
4240
4341 def test_validate_with_valid_file (self ):
4442 # Arrange
@@ -70,15 +68,17 @@ def setUp(self, mock_download_single_file):
7068 os .makedirs (dl_folder_path , exist_ok = True ) # Ensure this directory is created in the test
7169
7270 with patch .object (GTFSFlexValidation , '__init__' , return_value = None ):
73- self .validator = GTFSFlexValidation (file_path = file_path , storage_client = MagicMock ())
71+ self .validator = GTFSFlexValidation (file_path = file_path , storage_client = MagicMock (),
72+ prefix = Settings ().get_unique_id ())
7473 self .validator .file_path = file_path
7574 self .validator .file_relative_path = SUCCESS_FILE_NAME
7675 self .validator .container_name = None
7776 self .validator .settings = Settings ()
77+ self .validator .prefix = self .validator .settings .get_unique_id ()
7878 mock_download_single_file .return_value = os .path .join (dl_folder_path , SUCCESS_FILE_NAME )
7979
8080 def tearDown (self ):
81- pass
81+ GTFSFlexValidation . clean_up ( os . path . join ( DOWNLOAD_FILE_PATH , self . validator . prefix ))
8282
8383 def test_validate_with_valid_file (self ):
8484 # Arrange
@@ -128,33 +128,6 @@ def test_download_single_file(self):
128128 content = f .read ()
129129 self .assertEqual (content , b'file_content' )
130130
131- def test_download_multiple_file_with_same_name (self ):
132- # Arrange
133- file_upload_path = DOWNLOAD_FILE_PATH
134- self .validator .storage_client = MagicMock ()
135- self .validator .storage_client .get_file_from_url = MagicMock ()
136- file = MagicMock ()
137- file .file_path = 'text_file.txt'
138- file .get_stream = MagicMock (return_value = b'file_content' )
139- self .validator .storage_client .get_file_from_url .return_value = file
140-
141- # Act
142- first_downloaded_file_path = self .validator .download_single_file (file_upload_path = file_upload_path )
143- second_downloaded_file_path = self .validator .download_single_file (file_upload_path = file_upload_path )
144-
145- # Assert
146- self .assertNotEqual (first_downloaded_file_path , second_downloaded_file_path ,
147- "The downloaded file paths should be different for files with the same name." )
148-
149- # Check if the get_file_from_url was called for both download attempts
150- self .assertEqual (self .validator .storage_client .get_file_from_url .call_count , 2 ,
151- "get_file_from_url should be called twice for two downloads." )
152- file .get_stream .assert_called ()
153-
154- # Additional assertions to verify that the paths indeed point to different locations
155- self .assertTrue (first_downloaded_file_path .startswith (DOWNLOAD_FILE_PATH ))
156- self .assertTrue (second_downloaded_file_path .startswith (DOWNLOAD_FILE_PATH ))
157-
158131 def test_clean_up_file (self ):
159132 # Arrange
160133 file_upload_path = DOWNLOAD_FILE_PATH
@@ -203,10 +176,11 @@ def setUp(self, mock_download_single_file):
203176 self .validator .file_relative_path = FAILURE_FILE_NAME
204177 self .validator .container_name = None
205178 self .validator .settings = MagicMock ()
179+ self .validator .prefix = Settings ().get_unique_id ()
206180 mock_download_single_file .return_value = file_path
207181
208182 def tearDown (self ):
209- pass
183+ GTFSFlexValidation . clean_up ( os . path . join ( DOWNLOAD_FILE_PATH , self . validator . prefix ))
210184
211185 def test_validate_with_invalid_file (self ):
212186 # Arrange
@@ -259,12 +233,7 @@ def test_download_single_file_exception(self):
259233 file .get_stream = MagicMock (side_effect = FileNotFoundError ("Mocked FileNotFoundError" ))
260234 self .validator .storage_client .get_file_from_url .return_value = file
261235
262- # Create the mock folder that would be used
263- unique_id = "mocked-uuid"
264- self .validator .settings .get_unique_id = MagicMock ()
265- self .validator .settings .get_unique_id .return_value = unique_id
266-
267- dl_folder_path = os .path .join (DOWNLOAD_FILE_PATH , unique_id )
236+ dl_folder_path = os .path .join (DOWNLOAD_FILE_PATH , self .validator .prefix )
268237 os .makedirs (dl_folder_path , exist_ok = True )
269238
270239 # Act & Assert
0 commit comments