Add a total-message daily limit (#195)

This commit is contained in:
Steven Reilly
2023-03-14 16:28:38 -04:00
committed by GitHub
parent 886db509a0
commit 8d87b6ec09
7 changed files with 174 additions and 89 deletions

View File

@@ -12,6 +12,7 @@ from app.notifications.process_notifications import (
create_content_for_notification,
)
from app.notifications.validators import (
check_application_over_daily_message_total,
check_if_service_can_send_files_by_email,
check_is_message_too_long,
check_notification_content_is_not_empty,
@@ -33,7 +34,12 @@ from app.serialised_models import (
SerialisedTemplate,
)
from app.utils import get_template_instance
from app.v2.errors import BadRequestError, RateLimitError, TooManyRequestsError
from app.v2.errors import (
BadRequestError,
RateLimitError,
TooManyRequestsError,
TotalRequestsError,
)
from tests.app.db import (
create_api_key,
create_reply_to_email,
@@ -113,6 +119,18 @@ def test_check_service_message_limit_over_message_limit_fails(key_type, mocker,
assert e.value.fields == []
@pytest.mark.parametrize('key_type', ['team', 'normal'])
def test_check_service_message_limit_over_total_limit_fails(key_type, mocker, notify_db_session):
service = create_service()
mocker.patch('app.redis_store.get', return_value="5001")
with pytest.raises(TotalRequestsError) as e:
check_application_over_daily_message_total(key_type, service)
assert e.value.status_code == 429
assert e.value.message == 'Exceeded total application limits (5000) for today'
assert e.value.fields == []
@pytest.mark.parametrize('template_type, notification_type',
[(EMAIL_TYPE, EMAIL_TYPE),
(SMS_TYPE, SMS_TYPE)])