diff --git a/importer/main.py b/importer/main.py index 885d8a06..9cfd3eca 100644 --- a/importer/main.py +++ b/importer/main.py @@ -1,3 +1,4 @@ +import os import csv import json import uuid @@ -876,9 +877,13 @@ def clean_duplicates(users, cascade_delete): # Create a csv file and initialize the CSV writer def write_csv(data, resource_type, fieldnames): logging.info("Writing to csv file") + path = 'csv/exports' + if not os.path.exists(path): + os.makedirs(path) + current_time = datetime.now().strftime("%Y-%m-%d-%H-%M") - csv_file = f"csv/exports/{current_time}-export_{resource_type}.csv" - with open(csv_file, "w", newline="") as file: + csv_file = f"{path}/{current_time}-export_{resource_type}.csv" + with open(csv_file, 'w', newline='') as file: csv_writer = csv.writer(file) csv_writer.writerow(fieldnames) csv_writer.writerows(data) diff --git a/importer/test_main.py b/importer/test_main.py index 6560a3dd..87e3857d 100644 --- a/importer/test_main.py +++ b/importer/test_main.py @@ -462,10 +462,11 @@ def test_export_resource_to_csv( [ "City1", "active", + "update", "ba787982-b973-4bd5-854e-eacbe161e297", "ba787 982-b973-4bd5-854e-eacbe161e297", "test location-1", - "Location/18fcbc2e-4240-4a84-a270-7a444523d7b6", + "18fcbc2e-4240-4a84-a270-7a444523d7b6", "Jurisdiction", "jdn", "Jurisdiction", @@ -475,6 +476,7 @@ def test_export_resource_to_csv( test_elements = [ "name", "status", + "method", "id", "identifier", "parentName",