Skip to content

Commit

Permalink
[COST-5222] Fix FileNotFoundError in GCP Unit Test (#514)
Browse files Browse the repository at this point in the history
* Checking if the report name is already in dict to avoid duplication and hence FileNotFound exception when deleting.
  • Loading branch information
bacciotti authored Jul 5, 2024
1 parent 77dbbce commit cce887b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion nise/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "4.5.6"
__version__ = "4.5.7"

VERSION = __version__.split(".")
3 changes: 2 additions & 1 deletion nise/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cce887b

Please sign in to comment.