Skip to content

Commit

Permalink
Update tests to work properly on month boundaries
Browse files Browse the repository at this point in the history
The multi-part file names are different when the date range spans a
month boundary.
  • Loading branch information
samdoran committed Aug 1, 2023
1 parent 2672945 commit b25584c
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,12 +644,19 @@ def test_aws_create_report_with_local_dir_static_generation_multi_file(self):
"write_monthly": True,
}
aws_create_report(options)
month_output_file_name = "{}-{}-{}".format(calendar.month_name[now.month], now.year, "cur_report")
expected_month_output_file_1 = "{}/{}-1.csv".format(os.getcwd(), month_output_file_name)
expected_month_output_file_2 = "{}/{}-2.csv".format(os.getcwd(), month_output_file_name)
month_output_file_name = f"{calendar.month_name[now.month]}-{now.year}-cur_report"
expected_month_output_file_1 = f"{os.path.join(os.getcwd(), month_output_file_name)}-1"
expected_month_output_file_2 = f"{os.path.join(os.getcwd(), month_output_file_name)}-2"

if now.day == 1:
# First of the month will have numbered files for the previous month but not the current month
expected_month_output_file_1 = f"{os.path.join(os.getcwd(), month_output_file_name)}"
expected_month_output_file_2 = os.path.join(
os.getcwd(), f"{calendar.month_name[yesterday.month]}-{yesterday.year}-cur_report-1"
)

self.assertTrue(os.path.isfile(expected_month_output_file_1))
self.assertTrue(os.path.isfile(expected_month_output_file_2))
self.assertTrue(os.path.isfile(f"{expected_month_output_file_1}.csv"))
self.assertTrue(os.path.isfile(f"{expected_month_output_file_2}.csv"))

# cleanup any leftover files
regex = re.compile(month_output_file_name)
Expand Down Expand Up @@ -1111,19 +1118,24 @@ def test_ocp_create_report_with_local_dir_static_generation_multi_file(self):
if "ocp_ros_usage" == report_type:
continue
with self.subTest(report=report_type):
month_output_file_name = "{}-{}-{}-{}".format(
calendar.month_name[now.month], now.year, cluster_id, report_type
)
month_output_file_name = f"{calendar.month_name[now.month]}-{now.year}-{cluster_id}-{report_type}"
month_output_file_pt_1 = f"{month_output_file_name}-1"
month_output_file_pt_2 = f"{month_output_file_name}-2"

expected_month_output_file_1 = "{}/{}.csv".format(os.getcwd(), month_output_file_pt_1)
expected_month_output_file_2 = "{}/{}.csv".format(os.getcwd(), month_output_file_pt_2)
if now.day == 1:
# First of the month will have numbered files for the previous month but not the current month
month_output_file_pt_1 = month_output_file_name
month_output_file_pt_2 = (
f"{calendar.month_name[yesterday.month]}-{yesterday.year}-{cluster_id}-{report_type}-1"
)

expected_month_output_file_1 = os.path.join(os.getcwd(), month_output_file_pt_1)
expected_month_output_file_2 = os.path.join(os.getcwd(), month_output_file_pt_2)

print(f"{report_type}: {expected_month_output_file_1}")
print(f"{report_type}: {expected_month_output_file_2}")
self.assertTrue(os.path.isfile(expected_month_output_file_1))
self.assertTrue(os.path.isfile(expected_month_output_file_2))
self.assertTrue(os.path.isfile(f"{expected_month_output_file_1}.csv"))
self.assertTrue(os.path.isfile(f"{expected_month_output_file_2}.csv"))

# cleanup any leftover files
regex = re.compile(month_output_file_name)
Expand Down

0 comments on commit b25584c

Please sign in to comment.