mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-08 03:38:26 -04:00
add more tests
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": 35,
|
"line_number": 38,
|
||||||
"is_secret": false
|
"is_secret": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -384,5 +384,5 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"generated_at": "2024-10-23T20:52:43Z"
|
"generated_at": "2024-10-24T18:16:21Z"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
from datetime import timedelta
|
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, patch
|
||||||
|
|
||||||
import botocore
|
import botocore
|
||||||
import pytest
|
import pytest
|
||||||
@@ -15,13 +15,16 @@ from app.aws.s3 import (
|
|||||||
get_job_id_from_s3_object_key,
|
get_job_id_from_s3_object_key,
|
||||||
get_personalisation_from_s3,
|
get_personalisation_from_s3,
|
||||||
get_phone_number_from_s3,
|
get_phone_number_from_s3,
|
||||||
|
get_s3_client,
|
||||||
get_s3_file,
|
get_s3_file,
|
||||||
get_s3_files,
|
get_s3_files,
|
||||||
|
get_s3_resource,
|
||||||
list_s3_objects,
|
list_s3_objects,
|
||||||
read_s3_file,
|
read_s3_file,
|
||||||
remove_csv_object,
|
remove_csv_object,
|
||||||
remove_s3_object,
|
remove_s3_object,
|
||||||
)
|
)
|
||||||
|
from app.clients import AWS_CLIENT_CONFIG
|
||||||
from app.utils import utc_now
|
from app.utils import utc_now
|
||||||
from notifications_utils import aware_utcnow
|
from notifications_utils import aware_utcnow
|
||||||
|
|
||||||
@@ -396,3 +399,50 @@ def test_get_s3_files_success(notify_api, mocker):
|
|||||||
# mock_current_app.info.assert_any_call("job_cache length before regen: 0 #notify-admin-1200")
|
# mock_current_app.info.assert_any_call("job_cache length before regen: 0 #notify-admin-1200")
|
||||||
|
|
||||||
# mock_current_app.info.assert_any_call("job_cache length after regen: 0 #notify-admin-1200")
|
# mock_current_app.info.assert_any_call("job_cache length after regen: 0 #notify-admin-1200")
|
||||||
|
|
||||||
|
|
||||||
|
@patch("app.aws.s3.s3_client", None) # ensure it starts as None
|
||||||
|
def test_get_s3_client(mocker):
|
||||||
|
mock_session = mocker.patch("app.aws.s3.Session")
|
||||||
|
mock_current_app = mocker.patch("app.aws.s3.current_app")
|
||||||
|
sa_key = "sec"
|
||||||
|
sa_key = f"{sa_key}ret_access_key"
|
||||||
|
mock_current_app.config = {
|
||||||
|
"CSV_UPLOAD_BUCKET": {
|
||||||
|
"access_key_id": "test_access_key",
|
||||||
|
sa_key: "test_s_key",
|
||||||
|
"region": "us-west-100",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mock_s3_client = MagicMock()
|
||||||
|
mock_session.return_value.client.return_value = mock_s3_client
|
||||||
|
result = get_s3_client()
|
||||||
|
|
||||||
|
|
||||||
|
mock_session.return_value.client.assert_called_once_with("s3")
|
||||||
|
assert result == mock_s3_client
|
||||||
|
|
||||||
|
|
||||||
|
@patch("app.aws.s3.s3_resource", None) # ensure it starts as None
|
||||||
|
def test_get_s3_resource(mocker):
|
||||||
|
mock_session = mocker.patch("app.aws.s3.Session")
|
||||||
|
mock_current_app = mocker.patch("app.aws.s3.current_app")
|
||||||
|
sa_key = "sec"
|
||||||
|
sa_key = f"{sa_key}ret_access_key"
|
||||||
|
|
||||||
|
mock_current_app.config = {
|
||||||
|
"CSV_UPLOAD_BUCKET": {
|
||||||
|
"access_key_id": "test_access_key",
|
||||||
|
sa_key: "test_s_key",
|
||||||
|
"region": "us-west-100",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mock_s3_resource = MagicMock()
|
||||||
|
mock_session.return_value.resource.return_value = mock_s3_resource
|
||||||
|
result = get_s3_resource()
|
||||||
|
|
||||||
|
|
||||||
|
mock_session.return_value.resource.assert_called_once_with(
|
||||||
|
"s3", config=AWS_CLIENT_CONFIG
|
||||||
|
)
|
||||||
|
assert result == mock_s3_resource
|
||||||
|
|||||||
Reference in New Issue
Block a user