mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
- make sure when processing a job that we check the total_sent + job.notification_count against the service.message_limit.
This commit is contained in:
@@ -182,6 +182,25 @@ def test_should_not_process_if_send_limit_is_exceeded(
|
||||
assert tasks.process_row.called is False
|
||||
|
||||
|
||||
def test_should_not_process_if_send_limit_is_exceeded_by_job_notification_count(
|
||||
notify_api, notify_db_session, mocker
|
||||
):
|
||||
service = create_service(message_limit=9)
|
||||
template = create_template(service=service)
|
||||
job = create_job(template=template, notification_count=10, original_file_name='multiple_sms.csv')
|
||||
mock_s3 = mocker.patch('app.celery.tasks.s3.get_job_and_metadata_from_s3',
|
||||
return_value=(load_example_csv('multiple_sms'), {'sender_id': None}))
|
||||
mock_process_row = mocker.patch('app.celery.tasks.process_row')
|
||||
mocker.patch('app.celery.tasks.check_service_over_daily_message_limit',
|
||||
return_value=0)
|
||||
process_job(job.id)
|
||||
|
||||
job = jobs_dao.dao_get_job_by_id(job.id)
|
||||
assert job.job_status == 'sending limits exceeded'
|
||||
mock_s3.assert_not_called()
|
||||
mock_process_row.assert_not_called()
|
||||
|
||||
|
||||
def test_should_process_job_if_send_limits_are_not_exceeded(
|
||||
notify_api, notify_db_session, mocker
|
||||
):
|
||||
|
||||
@@ -65,8 +65,7 @@ def test_check_service_message_limit_in_cache_under_message_limit_passes(
|
||||
mock_set = mocker.patch('app.notifications.validators.redis_store.set')
|
||||
check_service_over_daily_message_limit(key_type, serialised_service)
|
||||
mock_get.assert_called_once_with(f'{serialised_service.id}-{datetime.utcnow().strftime("%Y-%m-%d")}-count')
|
||||
assert mock_get.called
|
||||
assert not mock_set.called
|
||||
mock_set.assert_not_called()
|
||||
|
||||
|
||||
def test_check_service_over_daily_message_limit_should_not_interact_with_cache_for_test_key(sample_service, mocker):
|
||||
@@ -74,7 +73,6 @@ def test_check_service_over_daily_message_limit_should_not_interact_with_cache_f
|
||||
mock_get = mocker.patch('app.notifications.validators.redis_store.get', side_effect=[None])
|
||||
serialised_service = SerialisedService.from_id(sample_service.id)
|
||||
check_service_over_daily_message_limit('test', serialised_service)
|
||||
app.notifications.validators.redis_store.assert_not_called
|
||||
mock_get.assert_not_called()
|
||||
|
||||
|
||||
@@ -105,7 +103,7 @@ def test_check_service_over_daily_message_limit_does_nothing_if_redis_disabled(n
|
||||
|
||||
@pytest.mark.parametrize('key_type', ['team', 'normal'])
|
||||
def test_check_service_message_limit_over_message_limit_fails(key_type, mocker, notify_db_session):
|
||||
service = create_service(restricted=True, message_limit=4)
|
||||
service = create_service(message_limit=4)
|
||||
mocker.patch('app.redis_store.get', return_value=5)
|
||||
|
||||
with pytest.raises(TooManyRequestsError) as e:
|
||||
|
||||
Reference in New Issue
Block a user