diff options
| -rw-r--r-- | src/extract_lambda.py | 3 | ||||
| -rw-r--r-- | tests/test_extract_lambda.py | 10 |
2 files changed, 8 insertions, 5 deletions
diff --git a/src/extract_lambda.py b/src/extract_lambda.py index 0e6dd8c..874098b 100644 --- a/src/extract_lambda.py +++ b/src/extract_lambda.py @@ -107,6 +107,9 @@ def extract_bucket(client=None): bucket["Name"] for bucket in response["Buckets"] if "extract" in bucket["Name"] ] + if not extract_bucket_filter: + raise ValueError("No extract_bucket found") + return extract_bucket_filter[0] diff --git a/tests/test_extract_lambda.py b/tests/test_extract_lambda.py index 1266cbb..bba433c 100644 --- a/tests/test_extract_lambda.py +++ b/tests/test_extract_lambda.py @@ -184,10 +184,8 @@ class TestExtractBucket: result = extract_bucket(s3_client) assert result == "extract_bucket" - def test_returns_index_error_if_no_buckets(self, s3_client): - # We don't even need to delete the bucket as there are no buckets - # due to the mock being reset for each test function now - with pytest.raises(IndexError, match="list index out of range"): + def test_raises_value_error_if_no_buckets(self, s3_client): + with pytest.raises(ValueError, match="No extract_bucket found"): extract_bucket(s3_client) @@ -196,7 +194,9 @@ class TestListExistingS3Files: logger = logging.getLogger() logger.info("Testing now.") caplog.set_level(logging.ERROR) - list_existing_s3_files(client=s3_client) + + with pytest.raises(ValueError, match="No extract_bucket found"): + list_existing_s3_files(client=s3_client) assert "Error listing S3 objects" in caplog.text def test_error_if_bucket_is_empty(self, s3_client, caplog, s3_mock_bucket): |
