From afc889de865e6ce42b19ce89c57e9bfed98d6757 Mon Sep 17 00:00:00 2001 From: T-Aji Date: Mon, 19 Aug 2024 09:27:20 +0100 Subject: test: handler exception test failing --- tests/test_extract_lambda.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') diff --git a/tests/test_extract_lambda.py b/tests/test_extract_lambda.py index 4b61b83..bc40df1 100644 --- a/tests/test_extract_lambda.py +++ b/tests/test_extract_lambda.py @@ -76,6 +76,17 @@ class TestLambdaHandler: mock_process_and_upload_tables.assert_called_once_with(mock_db, {}) mock_db.close.assert_called_once() + def test_lambda_handler_exception_error(self, mocker): + with patch("src.extract_lambda.connect_to_database", side_effect=Exception("Database connection error")): + mock_process_and_upload_tables = mocker.patch("src.extract_lambda.process_and_upload_tables") + mock_list_existing_s3_files = mocker.patch("src.extract_lambda.list_existing_s3_files") + event = {} + context = {} + response = lambda_handler(event, context) + assert response['statusCode'] == 500 + assert json.loads(response['body']) == 'Internal server error.' + mock_list_existing_s3_files.assert_not_called() + mock_process_and_upload_tables.assert_not_called() class TestListExistingS3Files: def test_error_if_no_bucket(self, s3_client, caplog): -- cgit v1.2.3