mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
Moved the cache key to the utils module.
Renamed the dao method.
This commit is contained in:
@@ -5,7 +5,7 @@ from app.dao.templates_dao import (
|
||||
dao_get_all_templates_for_service,
|
||||
dao_update_template,
|
||||
dao_get_template_versions,
|
||||
dao_get_templates_by_for_cache)
|
||||
dao_get_templates_for_cache)
|
||||
from tests.app.conftest import sample_template as create_sample_template
|
||||
from app.models import Template, TemplateHistory
|
||||
import pytest
|
||||
@@ -293,7 +293,7 @@ def test_get_templates_by_ids_successful(notify_db, notify_db_session):
|
||||
sample_cache_dict = {str.encode(str(template_1.id)): str.encode('2'),
|
||||
str.encode(str(template_2.id)): str.encode('3')}
|
||||
cache = [[k, v] for k, v in sample_cache_dict.items()]
|
||||
templates = dao_get_templates_by_for_cache(cache)
|
||||
templates = dao_get_templates_for_cache(cache)
|
||||
assert len(templates) == 2
|
||||
assert [(template_1.id, template_1.template_type, template_1.name, 2),
|
||||
(template_2.id, template_2.template_type, template_2.name, 3)] == templates
|
||||
@@ -309,11 +309,11 @@ def test_get_templates_by_ids_successful_for_one_cache_item(notify_db, notify_db
|
||||
)
|
||||
sample_cache_dict = {str.encode(str(template_1.id)): str.encode('2')}
|
||||
cache = [[k, v] for k, v in sample_cache_dict.items()]
|
||||
templates = dao_get_templates_by_for_cache(cache)
|
||||
templates = dao_get_templates_for_cache(cache)
|
||||
assert len(templates) == 1
|
||||
assert [(template_1.id, template_1.template_type, template_1.name, 2)] == templates
|
||||
|
||||
|
||||
def test_get_templates_by_ids_returns_empty_list():
|
||||
assert dao_get_templates_by_for_cache({}) == []
|
||||
assert dao_get_templates_by_for_cache(None) == []
|
||||
assert dao_get_templates_for_cache({}) == []
|
||||
assert dao_get_templates_for_cache(None) == []
|
||||
|
||||
@@ -7,13 +7,13 @@ from sqlalchemy.exc import SQLAlchemyError
|
||||
from freezegun import freeze_time
|
||||
from collections import namedtuple
|
||||
|
||||
from app import cache_key_for_service_template_counter
|
||||
from app.models import Template, Notification, NotificationHistory
|
||||
from app.notifications import SendNotificationToQueueError
|
||||
from app.notifications.process_notifications import (create_content_for_notification,
|
||||
persist_notification,
|
||||
send_notification_to_queue,
|
||||
simulated_recipient)
|
||||
from app.utils import cache_key_for_service_template_counter
|
||||
from app.v2.errors import BadRequestError
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ def test_exception_thown_by_redis_store_get_should_not_be_fatal(sample_template,
|
||||
|
||||
def test_cache_is_not_incremented_on_failure_to_persist_notification(sample_api_key, mocker):
|
||||
mocked_redis = mocker.patch('app.redis_store.incr')
|
||||
mocked_redis_hash = mocker.patch('app.redis_store.increment_hash_value')
|
||||
mock_service_template_cache = mocker.patch('app.redis_store.increment_hash_value')
|
||||
with pytest.raises(SQLAlchemyError):
|
||||
persist_notification(template_id=None,
|
||||
template_version=None,
|
||||
@@ -127,7 +127,7 @@ def test_cache_is_not_incremented_on_failure_to_persist_notification(sample_api_
|
||||
api_key_id=sample_api_key.id,
|
||||
key_type=sample_api_key.key_type)
|
||||
mocked_redis.assert_not_called()
|
||||
mocked_redis_hash.assert_not_called()
|
||||
mock_service_template_cache.assert_not_called()
|
||||
|
||||
|
||||
@freeze_time("2016-01-01 11:09:00.061258")
|
||||
@@ -135,7 +135,8 @@ def test_persist_notification_with_optionals(sample_job, sample_api_key, mocker)
|
||||
assert Notification.query.count() == 0
|
||||
assert NotificationHistory.query.count() == 0
|
||||
mocked_redis = mocker.patch('app.notifications.process_notifications.redis_store.incr')
|
||||
mocked_redis_hash = mocker.patch('app.notifications.process_notifications.redis_store.increment_hash_value')
|
||||
mock_service_template_cache = mocker.patch(
|
||||
'app.notifications.process_notifications.redis_store.increment_hash_value')
|
||||
n_id = uuid.uuid4()
|
||||
created_at = datetime.datetime(2016, 11, 11, 16, 8, 18)
|
||||
persist_notification(template_id=sample_job.template.id,
|
||||
@@ -158,8 +159,8 @@ def test_persist_notification_with_optionals(sample_job, sample_api_key, mocker)
|
||||
assert persisted_notification.job_row_number == 10
|
||||
assert persisted_notification.created_at == created_at
|
||||
mocked_redis.assert_called_once_with(str(sample_job.service_id) + "-2016-01-01-count")
|
||||
mocked_redis_hash.assert_called_once_with(cache_key_for_service_template_counter(sample_job.service_id),
|
||||
sample_job.template.id)
|
||||
mock_service_template_cache.assert_called_once_with(cache_key_for_service_template_counter(sample_job.service_id),
|
||||
sample_job.template.id)
|
||||
assert persisted_notification.client_reference == "ref from client"
|
||||
assert persisted_notification.reference is None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user