From cce887b99cdbbf3e368da3092555a0ebb73094e4 Mon Sep 17 00:00:00 2001 From: Lucas Bacciotti Date: Fri, 5 Jul 2024 09:54:37 +0100 Subject: [PATCH] [COST-5222] Fix FileNotFoundError in GCP Unit Test (#514) * Checking if the report name is already in dict to avoid duplication and hence FileNotFound exception when deleting. --- nise/__init__.py | 2 +- nise/report.py | 3 ++- tests/test_report.py | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/nise/__init__.py b/nise/__init__.py index 6d8c101e..511a7465 100644 --- a/nise/__init__.py +++ b/nise/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.5.6" +__version__ = "4.5.7" VERSION = __version__.split(".") diff --git a/nise/report.py b/nise/report.py index 7c9c58bb..6cfb901a 100644 --- a/nise/report.py +++ b/nise/report.py @@ -1189,7 +1189,8 @@ def gcp_create_report(options): # noqa: C901 local_file_path, output_file_name = write_gcp_file(gen_start_date, gen_end_date, data, options) output_files.append(output_file_name) - monthly_files.append(local_file_path) + if local_file_path not in monthly_files: + monthly_files.append(local_file_path) for index, month_file in enumerate(monthly_files): if gcp_bucket_name: diff --git a/tests/test_report.py b/tests/test_report.py index 0bd419d9..d3b60407 100644 --- a/tests/test_report.py +++ b/tests/test_report.py @@ -1627,6 +1627,24 @@ def test_gcp_create_report_without_write_monthly(self): self.assertFalse(os.path.isfile(expected_output_file_path)) + def test_gcp_create_report_without_write_monthly_overlapping_month(self): + """Test that there are no Exceptions when processing overlapping months dates.""" + now = datetime.datetime(2024, 7, 1, 0, 0) + yesterday = datetime.datetime(2024, 6, 30, 0, 0) + report_prefix = "test_report" + options = { + "start_date": yesterday, + "end_date": now, + "gcp_report_prefix": report_prefix, + "gcp_bucket_name": "gcp_bucket_name", + } + fix_dates(options, "gcp") + gcp_create_report(options) + output_file_name = "{}-{}.csv".format(report_prefix, yesterday.strftime("%Y-%m-%d")) + expected_output_file_path = "{}/{}".format(os.getcwd(), output_file_name) + + self.assertFalse(os.path.isfile(expected_output_file_path)) + def test_gcp_create_report_with_dataset_name_static_data(self): """Test the gcp report creation method where a dataset name is included and static data used.""" now = datetime.datetime.now().replace(microsecond=0, second=0, minute=0, hour=0)