-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kenneth Kehl
committed
Jan 28, 2025
1 parent
a413ec0
commit 481f27d
Showing
2 changed files
with
1 addition
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
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, RateLimitError | ||
from app.errors import InvalidRequest | ||
from app.models import ApiKey, Notification, NotificationHistory, Template | ||
from app.service.send_notification import send_one_off_notification | ||
from notifications_utils import SMS_CHAR_COUNT_LIMIT | ||
|
@@ -1124,51 +1124,6 @@ def test_create_template_raises_invalid_request_when_content_too_large( | |
} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"notification_type, send_to", | ||
[ | ||
(NotificationType.SMS, "2028675309"), | ||
( | ||
NotificationType.EMAIL, | ||
"[email protected]", | ||
), | ||
], | ||
) | ||
def test_returns_a_429_limit_exceeded_if_rate_limit_exceeded( | ||
client, sample_service, mocker, notification_type, send_to | ||
): | ||
sample = create_template(sample_service, template_type=notification_type) | ||
persist_mock = mocker.patch("app.notifications.rest.persist_notification") | ||
deliver_mock = mocker.patch("app.notifications.rest.send_notification_to_queue") | ||
|
||
mocker.patch( | ||
"app.notifications.rest.check_rate_limiting", | ||
side_effect=RateLimitError("LIMIT", "INTERVAL", "TYPE"), | ||
) | ||
|
||
data = {"to": send_to, "template": str(sample.id)} | ||
|
||
auth_header = create_service_authorization_header(service_id=sample.service_id) | ||
|
||
response = client.post( | ||
path=f"/notifications/{notification_type}", | ||
data=json.dumps(data), | ||
headers=[("Content-Type", "application/json"), auth_header], | ||
) | ||
|
||
message = json.loads(response.data)["message"] | ||
result = json.loads(response.data)["result"] | ||
assert response.status_code == 429 | ||
assert result == "error" | ||
assert message == ( | ||
"Exceeded rate limit for key type TYPE of LIMIT " | ||
"requests per INTERVAL seconds" | ||
) | ||
|
||
assert not persist_mock.called | ||
assert not deliver_mock.called | ||
|
||
|
||
def test_should_allow_store_original_number_on_sms_notification( | ||
client, sample_template, mocker | ||
): | ||
|