mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-11 02:23:32 -04:00
@@ -12,18 +12,9 @@ from app.dao import notifications_dao
|
||||
from app.dao.api_key_dao import save_model_api_key
|
||||
from app.dao.services_dao import dao_update_service
|
||||
from app.dao.templates_dao import dao_get_all_templates_for_service, dao_update_template
|
||||
from app.enums import KeyType, NotificationType, TemplateType
|
||||
from app.errors import InvalidRequest
|
||||
from app.models import (
|
||||
KEY_TYPE_NORMAL,
|
||||
KEY_TYPE_TEAM,
|
||||
KEY_TYPE_TEST,
|
||||
ApiKey,
|
||||
Notification,
|
||||
NotificationHistory,
|
||||
NotificationType,
|
||||
Template,
|
||||
TemplateType,
|
||||
)
|
||||
from app.models import ApiKey, Notification, NotificationHistory, Template
|
||||
from app.service.send_notification import send_one_off_notification
|
||||
from app.v2.errors import RateLimitError
|
||||
from tests import create_service_authorization_header
|
||||
@@ -557,7 +548,7 @@ def test_should_not_send_email_if_team_api_key_and_not_a_service_user(
|
||||
}
|
||||
|
||||
auth_header = create_service_authorization_header(
|
||||
service_id=sample_email_template.service_id, key_type=KEY_TYPE_TEAM
|
||||
service_id=sample_email_template.service_id, key_type=KeyType.TEAM
|
||||
)
|
||||
|
||||
response = client.post(
|
||||
@@ -587,7 +578,7 @@ def test_should_not_send_sms_if_team_api_key_and_not_a_service_user(
|
||||
}
|
||||
|
||||
auth_header = create_service_authorization_header(
|
||||
service_id=sample_template.service_id, key_type=KEY_TYPE_TEAM
|
||||
service_id=sample_template.service_id, key_type=KeyType.TEAM
|
||||
)
|
||||
|
||||
response = client.post(
|
||||
@@ -618,7 +609,7 @@ def test_should_send_email_if_team_api_key_and_a_service_user(
|
||||
"template": sample_email_template.id,
|
||||
}
|
||||
auth_header = create_service_authorization_header(
|
||||
service_id=sample_email_template.service_id, key_type=KEY_TYPE_TEAM
|
||||
service_id=sample_email_template.service_id, key_type=KeyType.TEAM
|
||||
)
|
||||
|
||||
response = client.post(
|
||||
@@ -650,7 +641,7 @@ def test_should_send_sms_to_anyone_with_test_key(
|
||||
service=sample_template.service,
|
||||
name="test_key",
|
||||
created_by=sample_template.created_by,
|
||||
key_type=KEY_TYPE_TEST,
|
||||
key_type=KeyType.TEST,
|
||||
)
|
||||
save_model_api_key(api_key)
|
||||
auth_header = create_jwt_token(
|
||||
@@ -688,7 +679,7 @@ def test_should_send_email_to_anyone_with_test_key(
|
||||
service=sample_email_template.service,
|
||||
name="test_key",
|
||||
created_by=sample_email_template.created_by,
|
||||
key_type=KEY_TYPE_TEST,
|
||||
key_type=KeyType.TEST,
|
||||
)
|
||||
save_model_api_key(api_key)
|
||||
auth_header = create_jwt_token(
|
||||
@@ -726,7 +717,7 @@ def test_should_send_sms_if_team_api_key_and_a_service_user(
|
||||
service=sample_template.service,
|
||||
name="team_key",
|
||||
created_by=sample_template.created_by,
|
||||
key_type=KEY_TYPE_TEAM,
|
||||
key_type=KeyType.TEAM,
|
||||
)
|
||||
save_model_api_key(api_key)
|
||||
auth_header = create_jwt_token(
|
||||
@@ -784,7 +775,7 @@ def test_should_persist_notification(
|
||||
service=template.service,
|
||||
name="team_key",
|
||||
created_by=template.created_by,
|
||||
key_type=KEY_TYPE_TEAM,
|
||||
key_type=KeyType.TEAM,
|
||||
)
|
||||
save_model_api_key(api_key)
|
||||
auth_header = create_jwt_token(
|
||||
@@ -843,7 +834,7 @@ def test_should_delete_notification_and_return_error_if_redis_fails(
|
||||
service=template.service,
|
||||
name="team_key",
|
||||
created_by=template.created_by,
|
||||
key_type=KEY_TYPE_TEAM,
|
||||
key_type=KeyType.TEAM,
|
||||
)
|
||||
save_model_api_key(api_key)
|
||||
auth_header = create_jwt_token(
|
||||
@@ -919,7 +910,7 @@ def test_should_not_persist_notification_or_send_sms_if_simulated_number(
|
||||
assert Notification.query.count() == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("key_type", [KEY_TYPE_NORMAL, KEY_TYPE_TEAM])
|
||||
@pytest.mark.parametrize("key_type", [KeyType.NORMAL, KeyType.TEAM])
|
||||
@pytest.mark.parametrize(
|
||||
"notification_type, to",
|
||||
[
|
||||
@@ -964,7 +955,7 @@ def test_should_not_send_notification_to_non_guest_list_recipient_in_trial_mode(
|
||||
"Can’t send to this recipient when service is in trial mode "
|
||||
"– see https://www.notifications.service.gov.uk/trial-mode"
|
||||
)
|
||||
if key_type == KEY_TYPE_NORMAL
|
||||
if key_type == KeyType.NORMAL
|
||||
else ("Can’t send to this recipient using a team-only API key")
|
||||
)
|
||||
|
||||
@@ -976,7 +967,7 @@ def test_should_not_send_notification_to_non_guest_list_recipient_in_trial_mode(
|
||||
|
||||
|
||||
@pytest.mark.parametrize("service_restricted", [True, False])
|
||||
@pytest.mark.parametrize("key_type", [KEY_TYPE_NORMAL, KEY_TYPE_TEAM])
|
||||
@pytest.mark.parametrize("key_type", [KeyType.NORMAL, KeyType.TEAM])
|
||||
@pytest.mark.parametrize(
|
||||
"notification_type, to, normalized_to",
|
||||
[
|
||||
|
||||
@@ -7,15 +7,14 @@ from notifications_utils.recipients import InvalidPhoneError
|
||||
|
||||
from app.config import QueueNames
|
||||
from app.dao.service_guest_list_dao import dao_add_and_commit_guest_list_contacts
|
||||
from app.models import (
|
||||
KEY_TYPE_NORMAL,
|
||||
PRIORITY,
|
||||
GuestListRecipientType,
|
||||
Notification,
|
||||
from app.enums import (
|
||||
KeyType,
|
||||
NotificationType,
|
||||
ServiceGuestList,
|
||||
RecipientType,
|
||||
TemplateProcessType,
|
||||
TemplateType,
|
||||
)
|
||||
from app.models import Notification, ServiceGuestList
|
||||
from app.service.send_notification import send_one_off_notification
|
||||
from app.v2.errors import BadRequestError
|
||||
from tests.app.db import (
|
||||
@@ -90,7 +89,7 @@ def test_send_one_off_notification_calls_persist_correctly_for_sms(
|
||||
personalisation={"name": "foo"},
|
||||
notification_type=NotificationType.SMS,
|
||||
api_key_id=None,
|
||||
key_type=KEY_TYPE_NORMAL,
|
||||
key_type=KeyType.NORMAL,
|
||||
created_by_id=str(service.created_by_id),
|
||||
reply_to_text="testing",
|
||||
reference=None,
|
||||
@@ -147,7 +146,7 @@ def test_send_one_off_notification_calls_persist_correctly_for_email(
|
||||
personalisation={"name": "foo"},
|
||||
notification_type=NotificationType.EMAIL,
|
||||
api_key_id=None,
|
||||
key_type=KEY_TYPE_NORMAL,
|
||||
key_type=KeyType.NORMAL,
|
||||
created_by_id=str(service.created_by_id),
|
||||
reply_to_text=None,
|
||||
reference=None,
|
||||
@@ -160,7 +159,7 @@ def test_send_one_off_notification_honors_priority(
|
||||
):
|
||||
service = create_service()
|
||||
template = create_template(service=service)
|
||||
template.process_type = PRIORITY
|
||||
template.process_type = TemplateProcessType.PRIORITY
|
||||
|
||||
post_data = {
|
||||
"template_id": str(template.id),
|
||||
@@ -204,7 +203,7 @@ def test_send_one_off_notification_raises_if_cant_send_to_recipient(
|
||||
dao_add_and_commit_guest_list_contacts(
|
||||
[
|
||||
ServiceGuestList.from_string(
|
||||
service.id, GuestListRecipientType.MOBILE, "2028765309"
|
||||
service.id, RecipientType.MOBILE, "2028765309"
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
@@ -14,7 +14,7 @@ from app.dao.service_user_dao import dao_get_service_user
|
||||
from app.dao.services_dao import dao_add_user_to_service, dao_remove_user_from_service
|
||||
from app.dao.templates_dao import dao_redact_template
|
||||
from app.dao.users_dao import save_model_user
|
||||
from app.enums import KeyType, ServicePermissionType, TemplateType, NotificationType
|
||||
from app.enums import KeyType, NotificationType, ServicePermissionType, TemplateType
|
||||
from app.models import (
|
||||
AnnualBilling,
|
||||
EmailBranding,
|
||||
|
||||
@@ -2,7 +2,8 @@ import pytest
|
||||
from flask import current_app
|
||||
|
||||
from app.dao.services_dao import dao_add_user_to_service
|
||||
from app.models import Notification, NotificationType, TemplateType
|
||||
from app.enums import NotificationType, TemplateType
|
||||
from app.models import Notification
|
||||
from app.service.sender import send_notification_to_service_users
|
||||
from tests.app.db import create_service, create_template, create_user
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@ import json
|
||||
import uuid
|
||||
|
||||
from app.dao.service_guest_list_dao import dao_add_and_commit_guest_list_contacts
|
||||
from app.models import GuestListRecipientType, ServiceGuestList
|
||||
from app.enums import RecipientType
|
||||
from app.models import ServiceGuestList
|
||||
from tests import create_admin_authorization_header
|
||||
|
||||
|
||||
@@ -25,15 +26,15 @@ def test_get_guest_list_separates_emails_and_phones(client, sample_service):
|
||||
[
|
||||
ServiceGuestList.from_string(
|
||||
sample_service.id,
|
||||
GuestListRecipientType.EMAIL,
|
||||
RecipientType.EMAIL,
|
||||
"service@example.com",
|
||||
),
|
||||
ServiceGuestList.from_string(
|
||||
sample_service.id, GuestListRecipientType.MOBILE, "2028675309"
|
||||
sample_service.id, RecipientType.MOBILE, "2028675309"
|
||||
),
|
||||
ServiceGuestList.from_string(
|
||||
sample_service.id,
|
||||
GuestListRecipientType.MOBILE,
|
||||
RecipientType.MOBILE,
|
||||
"+1800-555-5555",
|
||||
),
|
||||
]
|
||||
|
||||
@@ -4,13 +4,7 @@ from datetime import date, datetime
|
||||
import pytest
|
||||
from freezegun import freeze_time
|
||||
|
||||
from app.models import (
|
||||
KEY_TYPE_NORMAL,
|
||||
KEY_TYPE_TEAM,
|
||||
KEY_TYPE_TEST,
|
||||
NotificationType,
|
||||
TemplateType,
|
||||
)
|
||||
from app.enums import KeyType, NotificationType, TemplateType
|
||||
from tests.app.db import (
|
||||
create_ft_notification_status,
|
||||
create_notification,
|
||||
@@ -285,13 +279,13 @@ def test_get_monthly_notification_stats_ignores_test_keys(
|
||||
admin_request, sample_service
|
||||
):
|
||||
create_ft_notification_status(
|
||||
datetime(2016, 6, 1), service=sample_service, key_type=KEY_TYPE_NORMAL, count=1
|
||||
datetime(2016, 6, 1), service=sample_service, key_type=KeyType.NORMAL, count=1
|
||||
)
|
||||
create_ft_notification_status(
|
||||
datetime(2016, 6, 1), service=sample_service, key_type=KEY_TYPE_TEAM, count=2
|
||||
datetime(2016, 6, 1), service=sample_service, key_type=KeyType.TEAM, count=2
|
||||
)
|
||||
create_ft_notification_status(
|
||||
datetime(2016, 6, 1), service=sample_service, key_type=KEY_TYPE_TEST, count=4
|
||||
datetime(2016, 6, 1), service=sample_service, key_type=KeyType.TEST, count=4
|
||||
)
|
||||
|
||||
response = admin_request.get(
|
||||
|
||||
Reference in New Issue
Block a user