mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
these three tests replicate some testing that is done in the client tests themselves.
This commit is contained in:
@@ -97,25 +97,6 @@ def test_persist_notification_throws_exception_when_missing_template(sample_api_
|
||||
assert NotificationHistory.query.count() == 0
|
||||
|
||||
|
||||
def test_exception_thown_by_redis_store_get_should_not_be_fatal(sample_template, sample_api_key, mocker):
|
||||
mocker.patch(
|
||||
'app.notifications.process_notifications.redis_store.redis_store.incr',
|
||||
side_effect=Exception("broken redis"))
|
||||
|
||||
notification = persist_notification(
|
||||
sample_template.id,
|
||||
sample_template.version,
|
||||
'+447111111111',
|
||||
sample_template.service,
|
||||
{},
|
||||
'sms',
|
||||
sample_api_key.id,
|
||||
sample_api_key.key_type)
|
||||
assert Notification.query.count() == 1
|
||||
assert Notification.query.get(notification.id) is not None
|
||||
assert NotificationHistory.query.count() == 1
|
||||
|
||||
|
||||
def test_cache_is_not_incremented_on_failure_to_persist_notification(sample_api_key, mocker):
|
||||
mocked_redis = mocker.patch('app.redis_store.get')
|
||||
mock_service_template_cache = mocker.patch('app.redis_store.get_all_from_hash')
|
||||
|
||||
@@ -23,42 +23,6 @@ from tests.app.conftest import (
|
||||
sample_api_key)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('key_type', ['team', 'normal'])
|
||||
def test_exception_thrown_by_redis_store_get_should_not_be_fatal(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
notify_api,
|
||||
key_type,
|
||||
mocker):
|
||||
with freeze_time("2016-01-01 12:00:00.000000"):
|
||||
|
||||
mocker.patch('app.notifications.validators.redis_store.redis_store.get', side_effect=Exception("broken redis"))
|
||||
mocker.patch('app.notifications.validators.redis_store.redis_store.set')
|
||||
|
||||
service = create_service(notify_db, notify_db_session, restricted=True, limit=4)
|
||||
for x in range(5):
|
||||
create_notification(notify_db, notify_db_session, service=service)
|
||||
|
||||
with pytest.raises(TooManyRequestsError) as e:
|
||||
check_service_over_daily_message_limit(key_type, service)
|
||||
assert e.value.status_code == 429
|
||||
assert e.value.message == 'Exceeded send limits (4) for today'
|
||||
assert e.value.fields == []
|
||||
app.notifications.validators.redis_store.redis_store.set.assert_called_with(
|
||||
"{}-2016-01-01-count".format(str(service.id)), 5, 3600, None, False, False
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('key_type', ['test', 'team', 'normal'])
|
||||
def test_exception_thown_by_redis_store_set_should_not_be_fatal(
|
||||
key_type,
|
||||
sample_service,
|
||||
mocker):
|
||||
mocker.patch('app.notifications.validators.redis_store.redis_store.set', side_effect=Exception("broken redis"))
|
||||
mocker.patch('app.notifications.validators.redis_store.get', return_value=None)
|
||||
assert not check_service_over_daily_message_limit(key_type, sample_service)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('key_type', ['test', 'team', 'normal'])
|
||||
def test_check_service_message_limit_in_cache_with_unrestricted_service_is_allowed(
|
||||
key_type,
|
||||
|
||||
Reference in New Issue
Block a user