From 08b0b592b27fd124f0dd25265b0a79f8de4d92be Mon Sep 17 00:00:00 2001 From: David Kennedy Date: Fri, 14 Jun 2024 15:17:57 -0400 Subject: [PATCH] fixed paths on export and import scripts --- src/registrar/management/commands/export_tables.py | 4 ++-- src/registrar/management/commands/import_tables.py | 2 +- src/registrar/tests/test_management_scripts.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/registrar/management/commands/export_tables.py b/src/registrar/management/commands/export_tables.py index d9b45ec94..7d7521c1f 100644 --- a/src/registrar/management/commands/export_tables.py +++ b/src/registrar/management/commands/export_tables.py @@ -49,11 +49,11 @@ class Command(BaseCommand): matching_files = [file for file in os.listdir(tmp_dir) if file.startswith(pattern)] for file_path in matching_files: # Add each file to the zip archive - zipf.write(file_path, os.path.basename(file_path)) + zipf.write(f"tmp/{file_path}", os.path.basename(file_path)) logger.info(f"Added {file_path} to {zip_file_path}") # Remove the file after adding to zip - os.remove(file_path) + os.remove(f"tmp/{file_path}") logger.info(f"Removed {file_path}") def export_table(self, table_name): diff --git a/src/registrar/management/commands/import_tables.py b/src/registrar/management/commands/import_tables.py index 7797d8d75..cb78e13bd 100644 --- a/src/registrar/management/commands/import_tables.py +++ b/src/registrar/management/commands/import_tables.py @@ -83,7 +83,7 @@ class Command(BaseCommand): matching_files = [file for file in os.listdir(tmp_dir) if file.startswith(pattern)] for csv_filename in matching_files: try: - with open(csv_filename, "r") as csvfile: + with open(f"tmp/{csv_filename}", "r") as csvfile: dataset = tablib.Dataset().load(csvfile.read(), format="csv") result = resource_instance.import_data(dataset, dry_run=False, skip_epp_save=self.skip_epp_save) if result.has_errors(): diff --git a/src/registrar/tests/test_management_scripts.py b/src/registrar/tests/test_management_scripts.py index 8e3917d40..784fe3b67 100644 --- a/src/registrar/tests/test_management_scripts.py +++ b/src/registrar/tests/test_management_scripts.py @@ -934,13 +934,13 @@ class TestExportTables(MockEppLib): # Check that the CSV file was written for table_name in table_names: # Check that os.remove was called - mock_remove.assert_any_call(f"{table_name}_1.csv") + mock_remove.assert_any_call(f"tmp/{table_name}_1.csv") # Check that the zipfile was created and files were added mock_zipfile.assert_called_once_with("tmp/exported_tables.zip", "w", compression=pyzipper.ZIP_DEFLATED) zipfile_instance = mock_zipfile.return_value.__enter__.return_value for table_name in table_names: - zipfile_instance.write.assert_any_call(f"{table_name}_1.csv", f"{table_name}_1.csv") + zipfile_instance.write.assert_any_call(f"tmp/{table_name}_1.csv", f"{table_name}_1.csv") # Verify logging for added files for table_name in table_names: