mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-05 14:10:47 -04:00
merge from main
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
from datetime import timedelta
|
||||
from os import getenv
|
||||
from unittest.mock import ANY, MagicMock, Mock, call, patch
|
||||
from unittest.mock import MagicMock, Mock, call, patch
|
||||
|
||||
import botocore
|
||||
import pytest
|
||||
@@ -70,7 +70,7 @@ def test_cleanup_old_s3_objects(mocker):
|
||||
mock_remove_csv_object.assert_called_once_with("A")
|
||||
|
||||
|
||||
def test_read_s3_file_success(mocker):
|
||||
def test_read_s3_file_success(client, mocker):
|
||||
mock_s3res = MagicMock()
|
||||
mock_extract_personalisation = mocker.patch("app.aws.s3.extract_personalisation")
|
||||
mock_extract_phones = mocker.patch("app.aws.s3.extract_phones")
|
||||
@@ -89,16 +89,13 @@ def test_read_s3_file_success(mocker):
|
||||
mock_extract_phones.return_value = ["1234567890"]
|
||||
mock_extract_personalisation.return_value = {"name": "John Doe"}
|
||||
|
||||
global job_cache
|
||||
job_cache = {}
|
||||
|
||||
read_s3_file(bucket_name, object_key, mock_s3res)
|
||||
mock_get_job_id.assert_called_once_with(object_key)
|
||||
mock_s3res.Object.assert_called_once_with(bucket_name, object_key)
|
||||
expected_calls = [
|
||||
call(ANY, job_id, file_content),
|
||||
call(ANY, f"{job_id}_phones", ["1234567890"]),
|
||||
call(ANY, f"{job_id}_personalisation", {"name": "John Doe"}),
|
||||
call(job_id, file_content),
|
||||
call(f"{job_id}_phones", ["1234567890"]),
|
||||
call(f"{job_id}_personalisation", {"name": "John Doe"}),
|
||||
]
|
||||
mock_set_job_cache.assert_has_calls(expected_calls, any_order=True)
|
||||
|
||||
@@ -380,9 +377,12 @@ def test_file_exists_false(notify_api, mocker):
|
||||
get_s3_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_get_s3_files_success(notify_api, mocker):
|
||||
def test_get_s3_files_success(client, mocker):
|
||||
mock_current_app = mocker.patch("app.aws.s3.current_app")
|
||||
mock_current_app.config = {"CSV_UPLOAD_BUCKET": {"bucket": "test-bucket"}}
|
||||
mock_current_app.config = {
|
||||
"CSV_UPLOAD_BUCKET": {"bucket": "test-bucket"},
|
||||
"job_cache": {},
|
||||
}
|
||||
mock_thread_pool_executor = mocker.patch("app.aws.s3.ThreadPoolExecutor")
|
||||
mock_read_s3_file = mocker.patch("app.aws.s3.read_s3_file")
|
||||
mock_list_s3_objects = mocker.patch("app.aws.s3.list_s3_objects")
|
||||
|
||||
@@ -3650,3 +3650,43 @@ def test_get_monthly_notification_data_by_service(sample_service, admin_request)
|
||||
0,
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
def test_get_service_notification_statistics_by_day(
|
||||
admin_request, mocker, sample_service
|
||||
):
|
||||
mock_data = [
|
||||
{
|
||||
"notification_type": "email",
|
||||
"status": "sent",
|
||||
"day": "2024-11-01",
|
||||
"count": 10,
|
||||
},
|
||||
{
|
||||
"notification_type": "sms",
|
||||
"status": "failed",
|
||||
"day": "2024-11-02",
|
||||
"count": 5,
|
||||
},
|
||||
{
|
||||
"notification_type": "sms",
|
||||
"status": "delivered",
|
||||
"day": "2024-11-03",
|
||||
"count": 11,
|
||||
},
|
||||
]
|
||||
|
||||
mock_get_service_statistics_for_specific_days = mocker.patch(
|
||||
"app.service.rest.get_service_statistics_for_specific_days",
|
||||
return_value=mock_data,
|
||||
)
|
||||
|
||||
response = admin_request.get(
|
||||
"service.get_service_notification_statistics_by_day",
|
||||
service_id=sample_service.id,
|
||||
start="2024-11-03",
|
||||
days="1",
|
||||
)["data"]
|
||||
|
||||
assert mock_get_service_statistics_for_specific_days.assert_called_once
|
||||
assert response == mock_data
|
||||
|
||||
@@ -46,6 +46,7 @@ def test_create_invited_user(
|
||||
auth_type=AuthType.EMAIL,
|
||||
folder_permissions=["folder_1", "folder_2", "folder_3"],
|
||||
nonce="FakeNonce",
|
||||
state="FakeState",
|
||||
**extra_args,
|
||||
)
|
||||
|
||||
@@ -110,6 +111,7 @@ def test_create_invited_user_without_auth_type(
|
||||
"permissions": "send_messages,manage_service,manage_api_keys",
|
||||
"folder_permissions": [],
|
||||
"nonce": "FakeNonce",
|
||||
"state": "FakeState",
|
||||
}
|
||||
|
||||
json_resp = admin_request.post(
|
||||
@@ -134,6 +136,7 @@ def test_create_invited_user_invalid_email(client, sample_service, mocker, fake_
|
||||
"permissions": "send_messages,manage_service,manage_api_keys",
|
||||
"folder_permissions": [fake_uuid, fake_uuid],
|
||||
"nonce": "FakeNonce",
|
||||
"state": "FakeState",
|
||||
}
|
||||
|
||||
data = json.dumps(data)
|
||||
@@ -235,6 +238,7 @@ def test_resend_expired_invite(
|
||||
response = client.post(
|
||||
url,
|
||||
headers=[("Content-Type", "application/json"), auth_header],
|
||||
data='{"nonce": "FakeNonce", "state": "FakeState"}',
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
Reference in New Issue
Block a user