project-koku / nise

A tool for generating sample cost usage data for testing purposes
GNU Affero General Public License v3.0
9 stars 15 forks source link

[COST-5222] Fix FileNotFoundError in GCP Unit Test #514

Closed bacciotti closed 3 months ago

bacciotti commented 3 months ago

The error occurred in the GCP test test_gcp_create_report_without_write_monthly whenever it was executed on the first day of the month. This happened because a list was generated with a filename for each month. Consequently, when the range "last day of month X" to "first day of month Y" was processed, the list was populated with a file for month X and another for month Y. However, in a testing scenario, the report name was always test_report.csv, resulting in a list with this value repeated twice. Therefore, an attempt to delete the file was made twice, causing an error on the second attempt since it had already been deleted the first time.

This change ensures that if the csv file has the same name, it will be added to the list only once. This prevents a second (or nth) deletion attempt.

How to test?

  1. Checkout branch
  2. Adapt the test_gcp_create_report_without_write_monthly test (test_report.py) adding the following lines to force a test with different dates:
    • Two months:
      now = datetime.datetime(2024, 6, 30, 0, 0)
      yesterday = datetime.datetime(2024, 7, 1, 0, 0)
    • One month
      now = datetime.datetime(2024, 7, 1, 0, 0)
      yesterday = datetime.datetime(2024, 7, 2, 0, 0)
  3. Run python3 -m unittest tests.test_report or python3 -m unittest tests.test_report.GCPReportTestCase
codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 93.8%. Comparing base (77dbbce) to head (0abd2f6).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #514 +/- ## ======================================= + Coverage 93.6% 93.8% +0.2% ======================================= Files 62 62 Lines 4698 4699 +1 Branches 663 664 +1 ======================================= + Hits 4399 4408 +9 + Misses 156 152 -4 + Partials 143 139 -4 ```