mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
ugh
This commit is contained in:
@@ -209,7 +209,7 @@
|
|||||||
"filename": "tests/app/aws/test_s3.py",
|
"filename": "tests/app/aws/test_s3.py",
|
||||||
"hashed_secret": "67a74306b06d0c01624fe0d0249a570f4d093747",
|
"hashed_secret": "67a74306b06d0c01624fe0d0249a570f4d093747",
|
||||||
"is_verified": false,
|
"is_verified": false,
|
||||||
"line_number": 32,
|
"line_number": 34,
|
||||||
"is_secret": false
|
"is_secret": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -384,5 +384,5 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"generated_at": "2024-10-23T14:54:35Z"
|
"generated_at": "2024-10-23T15:35:38Z"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ from datetime import timedelta
|
|||||||
from os import getenv
|
from os import getenv
|
||||||
from unittest.mock import ANY, MagicMock, call
|
from unittest.mock import ANY, MagicMock, call
|
||||||
|
|
||||||
|
import botocore
|
||||||
import pytest
|
import pytest
|
||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
|
|
||||||
from app.aws.s3 import (
|
from app.aws.s3 import (
|
||||||
cleanup_old_s3_objects,
|
cleanup_old_s3_objects,
|
||||||
|
download_from_s3,
|
||||||
file_exists,
|
file_exists,
|
||||||
get_job_from_s3,
|
get_job_from_s3,
|
||||||
get_job_id_from_s3_object_key,
|
get_job_id_from_s3_object_key,
|
||||||
@@ -95,6 +97,43 @@ def test_read_s3_file_success(mocker):
|
|||||||
mock_set_job_cache.assert_has_calls(expected_calls, any_order=True)
|
mock_set_job_cache.assert_has_calls(expected_calls, any_order=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_download_from_s3_success(mocker):
|
||||||
|
mock_s3 = MagicMock()
|
||||||
|
mock_get_s3_client = mocker.patch("app.aws.s3.get_s3_client")
|
||||||
|
mock_current_app = mocker.patch("app.aws.s3.current_app")
|
||||||
|
mock_logger = mock_current_app.logger
|
||||||
|
mock_get_s3_client.return_value = mock_s3
|
||||||
|
bucket_name = "test_bucket"
|
||||||
|
s3_key = "test_key"
|
||||||
|
local_filename = "test_file"
|
||||||
|
access_key = "access_key"
|
||||||
|
region = "test_region"
|
||||||
|
download_from_s3(
|
||||||
|
bucket_name, s3_key, local_filename, access_key, "secret_key", region
|
||||||
|
)
|
||||||
|
mock_s3.download_file.assert_called_once_with(bucket_name, s3_key, local_filename)
|
||||||
|
mock_logger.info.assert_called_once_with(
|
||||||
|
f"File downloaded successfully to {local_filename}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_download_from_s3_no_credentials_error(mocker):
|
||||||
|
mock_get_s3_client = mocker.patch("app.aws.s3.get_s3_client")
|
||||||
|
mock_current_app = mocker.patch("app.aws.s3.current_app")
|
||||||
|
mock_logger = mock_current_app.logger
|
||||||
|
mock_s3 = MagicMock()
|
||||||
|
mock_s3.download_file.side_effect = botocore.exceptions.NoCredentialsError
|
||||||
|
mock_get_s3_client.return_value = mock_s3
|
||||||
|
try:
|
||||||
|
download_from_s3(
|
||||||
|
"test_bucket", "test_key", "test_file", "access_key", "secret_key", "region"
|
||||||
|
)
|
||||||
|
assert 1 == 0
|
||||||
|
except botocore.exceptions.NoCredentialsError:
|
||||||
|
assert 1 == 1
|
||||||
|
mock_logger.exception.assert_called_once_with("Credentials not found")
|
||||||
|
|
||||||
|
|
||||||
def test_list_s3_objects(mocker):
|
def test_list_s3_objects(mocker):
|
||||||
mocker.patch("app.aws.s3._get_bucket_name", return_value="Foo")
|
mocker.patch("app.aws.s3._get_bucket_name", return_value="Foo")
|
||||||
mock_s3_client = mocker.Mock()
|
mock_s3_client = mocker.Mock()
|
||||||
|
|||||||
Reference in New Issue
Block a user