Skip to content

Commit

Permalink
Use return_value instead of side_effect to avoid StopIteration error
Browse files Browse the repository at this point in the history
When there are two months to iterate over, the Mock raised a StopIteration error
because it only had one side_effect value. A return_value makes more sense for
the goal of the test.
  • Loading branch information
samdoran committed Aug 1, 2023
1 parent b25584c commit 47fe857
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from unittest.mock import patch

import faker
import q
from dateutil.relativedelta import relativedelta
from nise.generators.oci.oci_generator import OCI_REPORT_TYPE_TO_COLS
from nise.generators.ocp.ocp_generator import OCP_REPORT_TYPE_TO_COLS
Expand Down Expand Up @@ -1381,7 +1382,7 @@ def test_gcp_create_report_with_dataset_name_no_report_prefix(self):
self.assertTrue(os.path.isfile(expected_output_file_path))
os.remove(expected_output_file_path)

@patch("nise.report.uuid4", side_effect=["nise"])
@patch("nise.report.uuid4", return_value="25150e4f-bfe5-406b-aaa9-b19f59875420")
def test_gcp_create_report_no_report_prefix(self, patch_etag):
"""Test the gcp report creation method."""
now = datetime.datetime.now().replace(microsecond=0, second=0, minute=0, hour=0)
Expand All @@ -1391,7 +1392,7 @@ def test_gcp_create_report_no_report_prefix(self, patch_etag):
invoice_month = yesterday.strftime("%Y%m")
scan_start = yesterday.date()
scan_end = now.date()
expected_file_name = f"{invoice_month}_nise_{scan_start}:{scan_end}.csv"
expected_file_name = f"{invoice_month}_{patch_etag.return_value}_{scan_start}:{scan_end}.csv"
expected_output_file_path = "{}/{}".format(os.getcwd(), expected_file_name)
self.assertTrue(os.path.isfile(expected_output_file_path))
os.remove(expected_output_file_path)
Expand Down

0 comments on commit 47fe857

Please sign in to comment.