don't hit the query to get daily msg stats if redis is disabled

This commit is contained in:
Leo Hemsted
2017-12-04 11:12:26 +00:00
parent 3ba7e8abd9
commit 88c878c83e
2 changed files with 21 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
import pytest
from freezegun import freeze_time
from flask import current_app
import app
from app.models import INTERNATIONAL_SMS_TYPE, SMS_TYPE, EMAIL_TYPE
from app.notifications.validators import (
@@ -18,6 +19,8 @@ from app.v2.errors import (
BadRequestError,
TooManyRequestsError,
RateLimitError)
from tests.conftest import set_config
from tests.app.conftest import (
sample_notification as create_notification,
sample_service as create_service,
@@ -26,6 +29,13 @@ from tests.app.conftest import (
from tests.app.db import create_reply_to_email, create_service_sms_sender
# all of these tests should have redis enabled (except where we specifically disable it)
@pytest.fixture(scope='module', autouse=True)
def enable_redis(notify_api):
with set_config(notify_api, 'REDIS_ENABLED', True):
yield
@pytest.mark.parametrize('key_type', ['test', 'team', 'normal'])
def test_check_service_message_limit_in_cache_with_unrestricted_service_is_allowed(
key_type,
@@ -78,6 +88,15 @@ def test_should_set_cache_value_as_value_from_database_if_cache_not_set(
)
def test_should_not_access_database_if_redis_disabled(notify_api, sample_service, mocker):
with set_config(notify_api, 'REDIS_ENABLED', False):
db_mock = mocker.patch('app.notifications.validators.services_dao')
check_service_over_daily_message_limit('normal', sample_service)
assert db_mock.method_calls == []
@pytest.mark.parametrize('key_type', ['team', 'normal'])
def test_check_service_message_limit_over_message_limit_fails(key_type, notify_db, notify_db_session, mocker):
with freeze_time("2016-01-01 12:00:00.000000"):