Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/dao/notifications_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def get_notification_with_personalisation(service_id, notification_id, key_type)
filter_dict["key_type"] = key_type

try:
return Notification.query.filter_by(**filter_dict).options(joinedload("template")).one()
return db.on_reader().query(Notification).filter_by(**filter_dict).options(joinedload("template")).one()
except NoResultFound:
current_app.logger.warning(f"Failed to get notification with filter: {filter_dict}")
return None
Expand Down
20 changes: 20 additions & 0 deletions tests/app/dao/notification_dao/test_notification_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,26 @@ def test_get_notification_with_personalisation_by_id_no_result(sample_template,
assert mock_logger.called


def test_get_notification_with_personalisation_uses_reader_bind(mocker, fake_uuid):
reader = mocker.Mock()
query = mocker.Mock()
query_with_filters = mocker.Mock()
query_with_template = mocker.Mock()

mocker.patch("app.dao.notifications_dao.db.on_reader", return_value=reader)
reader.query.return_value = query
query.filter_by.return_value = query_with_filters
query_with_filters.options.return_value = query_with_template
query_with_template.one.return_value = mocker.sentinel.notification

result = get_notification_with_personalisation(fake_uuid, fake_uuid, key_type=None)

reader.query.assert_called_once_with(Notification)
query.filter_by.assert_called_once_with(service_id=fake_uuid, id=fake_uuid)
query_with_filters.options.assert_called_once()
assert result == mocker.sentinel.notification


def test_get_notification_by_id_when_notification_exists(sample_notification):
notification_from_db = get_notification_by_id(sample_notification.id)

Expand Down
Loading