11from unittest import TestCase , mock
22import pandas
3+ from typing import TYPE_CHECKING
4+
5+ if TYPE_CHECKING :
6+ from unittest .mock import MagicMock
37
48from 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+ 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
2152class TestUploadToS3 (TestCase ):
2253 @mock .patch ("process_report.util.get_invoice_bucket" )
0 commit comments