From 852cf478f8700d034abbe0e984c51e8a7727529f Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Tue, 17 Mar 2020 15:41:30 +0000 Subject: [PATCH] Remove the check for daily limits --- app/notifications/validators.py | 3 +- .../rest/test_send_notification.py | 65 +------------------ 2 files changed, 3 insertions(+), 65 deletions(-) diff --git a/app/notifications/validators.py b/app/notifications/validators.py index ef79cf79e..3b9cf6c62 100644 --- a/app/notifications/validators.py +++ b/app/notifications/validators.py @@ -50,7 +50,8 @@ def check_service_over_daily_message_limit(key_type, service): def check_rate_limiting(service, api_key): check_service_over_api_rate_limit(service, api_key) - check_service_over_daily_message_limit(api_key.key_type, service) + # Reduce queries to the notifications table + # check_service_over_daily_message_limit(api_key.key_type, service) def check_template_is_for_notification_type(notification_type, template_type): diff --git a/tests/app/notifications/rest/test_send_notification.py b/tests/app/notifications/rest/test_send_notification.py index 3949cee8f..d5be60713 100644 --- a/tests/app/notifications/rest/test_send_notification.py +++ b/tests/app/notifications/rest/test_send_notification.py @@ -18,7 +18,7 @@ from app.dao.services_dao import dao_update_service from app.dao.api_key_dao import save_model_api_key from app.errors import InvalidRequest from app.models import Template -from app.v2.errors import RateLimitError, TooManyRequestsError +from app.v2.errors import RateLimitError from tests import create_authorization_header from tests.app.db import ( @@ -404,69 +404,6 @@ def test_should_allow_valid_email_notification(notify_api, sample_email_template assert response_data['template_version'] == sample_email_template.version -@freeze_time("2016-01-01 12:00:00.061258") -def test_should_block_api_call_if_over_day_limit_for_live_service( - notify_db_session, - notify_api, - mocker): - with notify_api.test_request_context(): - with notify_api.test_client() as client: - mocker.patch( - 'app.notifications.validators.check_service_over_daily_message_limit', - side_effect=TooManyRequestsError(1) - ) - mocker.patch('app.celery.provider_tasks.deliver_email.apply_async') - service = create_service(message_limit=1) - email_template = create_template(service, template_type=EMAIL_TYPE) - create_notification(template=email_template) - - data = { - 'to': 'ok@ok.com', - 'template': str(email_template.id) - } - - auth_header = create_authorization_header(service_id=service.id) - - response = client.post( - path='/notifications/email', - data=json.dumps(data), - headers=[('Content-Type', 'application/json'), auth_header]) - json.loads(response.get_data(as_text=True)) - assert response.status_code == 429 - - -@freeze_time("2016-01-01 12:00:00.061258") -def test_should_block_api_call_if_over_day_limit_for_restricted_service( - notify_db_session, - notify_api, - mocker): - with notify_api.test_request_context(): - with notify_api.test_client() as client: - mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async') - mocker.patch( - 'app.notifications.validators.check_service_over_daily_message_limit', - side_effect=TooManyRequestsError(1) - ) - service = create_service(restricted=True, message_limit=1) - email_template = create_template(service, template_type=EMAIL_TYPE) - create_notification(template=email_template) - - data = { - 'to': 'ok@ok.com', - 'template': str(email_template.id) - } - - auth_header = create_authorization_header(service_id=service.id) - - response = client.post( - path='/notifications/email', - data=json.dumps(data), - headers=[('Content-Type', 'application/json'), auth_header]) - json.loads(response.get_data(as_text=True)) - - assert response.status_code == 429 - - @pytest.mark.parametrize('restricted', [True, False]) @freeze_time("2016-01-01 12:00:00.061258") def test_should_allow_api_call_if_under_day_limit_regardless_of_type(