Skip to content

Commit 1368d46

Browse files
committed
Added test for testing fetch out-of-band utility
1 parent 8636696 commit 1368d46

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

process_report/tests/unit/invoices/test_base_invoice.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
from unittest import TestCase, mock
22
import pandas
3+
from typing import TYPE_CHECKING
4+
5+
if TYPE_CHECKING:
6+
from unittest.mock import MagicMock
37

48
from process_report.tests import util as test_utils
59

@@ -17,6 +21,33 @@ def test_filter_exported_columns(self):
1721

1822
self.assertTrue(result_invoice.equals(answer_invoice))
1923

24+
@mock.patch("pandas.read_csv")
25+
def test_fetch_with_mock_s3_bucket(self, mock_read_csv: "MagicMock") -> None:
26+
"""Test that fetch() method loads data correctly when S3 bucket is mocked."""
27+
test_invoice = test_utils.new_base_invoice(
28+
name="TestInvoice", invoice_month="2024-08"
29+
)
30+
expected_data = pandas.DataFrame(
31+
{
32+
"Invoice Month": ["2024-08", "2024-08"],
33+
"Project - Allocation": ["P1", "P2"],
34+
"Manager (PI)": ["[email protected]", "[email protected]"],
35+
"Cost": [100.00, 150.00],
36+
}
37+
)
38+
mock_read_csv.return_value = expected_data
39+
40+
mock_s3_bucket = mock.MagicMock()
41+
mock_s3_bucket.download_file.return_value = None
42+
43+
test_invoice.fetch(mock_s3_bucket)
44+
45+
self.assertIsNotNone(test_invoice.data)
46+
self.assertTrue(test_invoice.data.equals(expected_data))
47+
mock_s3_bucket.download_file.assert_called_once_with(
48+
"Invoices/2024-08/TestInvoice 2024-08.csv", "TestInvoice 2024-08.csv"
49+
)
50+
2051

2152
class TestUploadToS3(TestCase):
2253
@mock.patch("process_report.util.get_invoice_bucket")

0 commit comments

Comments
 (0)