Skip to content

Commit

Permalink
remove check_rate_limiting
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Kehl committed Jan 28, 2025
1 parent a413ec0 commit 481f27d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 49 deletions.
3 changes: 0 additions & 3 deletions app/v2/notifications/post_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from app.notifications.validators import (
check_if_service_can_send_files_by_email,
check_is_message_too_long,
check_rate_limiting,
check_service_email_reply_to_id,
check_service_has_permission,
check_service_sms_sender_id,
Expand Down Expand Up @@ -54,8 +53,6 @@ def post_notification(notification_type):

check_service_has_permission(notification_type, authenticated_service.permissions)

check_rate_limiting(authenticated_service, api_user)

template, template_with_content = validate_template(
form["template_id"],
form.get("personalisation", {}),
Expand Down
47 changes: 1 addition & 46 deletions tests/app/service/send_notification/test_send_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
):
Expand Down

0 comments on commit 481f27d

Please sign in to comment.