Skip to content

Commit 8aba5e7

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

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import pandas as pd
2+
from typing import TYPE_CHECKING
3+
4+
if TYPE_CHECKING:
5+
from pytest_mock.plugin import MockerFixture
6+
7+
from process_report.tests import util as test_utils
8+
9+
10+
def test_fetch_with_mock_s3_bucket(mocker: "MockerFixture") -> None:
11+
"""Test that fetch() out-of-band utility function loads data correctly when S3 bucket is mocked."""
12+
13+
test_invoice = test_utils.new_base_invoice(
14+
name="TestInvoice", invoice_month="2024-08"
15+
)
16+
expected_data = pd.DataFrame(
17+
{
18+
"Invoice Month": ["2024-08", "2024-08"],
19+
"Project - Allocation": ["P1", "P2"],
20+
"Manager (PI)": ["[email protected]", "[email protected]"],
21+
"Cost": [100.00, 150.00],
22+
}
23+
)
24+
25+
mocker.patch("pandas.read_csv", return_value=expected_data)
26+
mock_s3_bucket = mocker.Mock()
27+
mock_s3_bucket.download_file.return_value = None
28+
29+
test_invoice.fetch(mock_s3_bucket)
30+
31+
assert test_invoice.data is not None
32+
pd.testing.assert_frame_equal(test_invoice.data, expected_data)
33+
mock_s3_bucket.download_file.assert_called_once_with(
34+
"Invoices/2024-08/TestInvoice 2024-08.csv", "TestInvoice 2024-08.csv"
35+
)

0 commit comments

Comments
 (0)