From 4a3835d70bb143de23437e6f50f1050f810cd0b1 Mon Sep 17 00:00:00 2001 From: Alex Schofield Date: Thu, 22 Aug 2024 11:56:43 +0100 Subject: fix: inject mock_config into interface error test --- tests/test_extract_lambda.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'tests/test_extract_lambda.py') diff --git a/tests/test_extract_lambda.py b/tests/test_extract_lambda.py index af3503d..ee677bd 100644 --- a/tests/test_extract_lambda.py +++ b/tests/test_extract_lambda.py @@ -17,6 +17,13 @@ from src.extract_lambda import ( retrieve_secrets, extract_bucket, ) +from pg8000.native import InterfaceError + + +@pytest.fixture(scope="function", autouse=True) +def aws_mocks(): + with mock_aws(): + yield @pytest.fixture @@ -212,12 +219,18 @@ class TestConnectToDatabase: with pytest.raises(DBConnectionException): connect_to_database() - def test_logs_interface_error(self, caplog): + def test_logs_interface_error(self, caplog, mock_config): + # Use mock_config fixture which already mocks the retrieve_secrets + # function to return JSON string with DB connection details logger = logging.getLogger() logger.info("Testing now.") caplog.set_level(logging.ERROR) - with pytest.raises(DBConnectionException): + + with patch( + "src.extract_lambda.Connection", side_effect=InterfaceError("Test error") + ), pytest.raises(DBConnectionException): connect_to_database() + assert "Interface error" in caplog.text -- cgit v1.2.3