add actual_template relationship to notification

also renamed the function to make it apparent that it'll join and grab personalisation
This commit is contained in:
Leo Hemsted
2016-08-09 13:07:48 +01:00
parent c820938ced
commit 46c0728b12
6 changed files with 43 additions and 22 deletions

View File

@@ -188,7 +188,7 @@ def test_send_sms_should_use_template_version_from_notification_not_latest(
sender=None
)
persisted_notification = notifications_dao.get_notification(sample_template.service_id, db_notification.id)
persisted_notification = notifications_dao.get_notification_by_id(db_notification.id)
assert persisted_notification.to == db_notification.to
assert persisted_notification.template_id == sample_template.id
assert persisted_notification.template_version == version_on_notification
@@ -223,7 +223,7 @@ def test_should_call_send_sms_response_task_if_research_mode(notify_db, sample_s
('mmg', str(sample_notification.id), sample_notification.to), queue='research-mode'
)
persisted_notification = notifications_dao.get_notification(sample_service.id, sample_notification.id)
persisted_notification = notifications_dao.get_notification_by_id(sample_notification.id)
assert persisted_notification.to == sample_notification.to
assert persisted_notification.template_id == sample_notification.template_id
assert persisted_notification.status == 'sending'
@@ -499,7 +499,7 @@ def test_should_not_set_billable_units_if_research_mode(notify_db, sample_servic
sample_notification.id
)
persisted_notification = notifications_dao.get_notification(sample_service.id, sample_notification.id)
persisted_notification = notifications_dao.get_notification_by_id(sample_notification.id)
assert persisted_notification.billable_units == 0

View File

@@ -23,7 +23,7 @@ from app.models import (
from app.dao.notifications_dao import (
dao_create_notification,
dao_update_notification,
get_notification,
get_notification_with_personalisation,
get_notification_for_job,
get_notifications_for_job,
dao_get_notification_statistics_for_service,
@@ -57,7 +57,7 @@ def test_should_have_decorated_notifications_dao_functions():
assert update_notification_status_by_reference.__wrapped__.__name__ == 'update_notification_status_by_reference' # noqa
assert get_notification_for_job.__wrapped__.__name__ == 'get_notification_for_job' # noqa
assert get_notifications_for_job.__wrapped__.__name__ == 'get_notifications_for_job' # noqa
assert get_notification.__wrapped__.__name__ == 'get_notification' # noqa
assert get_notification_with_personalisation.__wrapped__.__name__ == 'get_notification_with_personalisation' # noqa
assert get_notifications_for_service.__wrapped__.__name__ == 'get_notifications_for_service' # noqa
assert get_notification_by_id.__wrapped__.__name__ == 'get_notification_by_id' # noqa
assert delete_notifications_created_more_than_a_week_ago.__wrapped__.__name__ == 'delete_notifications_created_more_than_a_week_ago' # noqa
@@ -637,9 +637,11 @@ def test_save_notification_with_no_job(sample_template, mmg_provider):
def test_get_notification(sample_notification):
notification_from_db = get_notification(
notification_from_db = get_notification_with_personalisation(
sample_notification.service.id,
sample_notification.id)
sample_notification.id,
key_type=None
)
assert sample_notification == notification_from_db

View File

@@ -640,14 +640,15 @@ def test_get_notification_selects_correct_template_for_personalisation(notify_ap
auth_header = create_authorization_header(service_id=sample_template.service_id)
response = client.get(path='/notifications', headers=[auth_header])
assert response.status_code == 200
resp = json.loads(response.get_data(as_text=True))
assert len(resp['notifications']) == 2
assert resp['notifications'][0]['template_version'] == 1
assert resp['notifications'][0]['body'] == 'This is a template'
assert resp['notifications'][1]['template_version'] == 2
assert resp['notifications'][1]['body'] == 'foo'
assert response.status_code == 200
resp = json.loads(response.get_data(as_text=True))
assert len(resp['notifications']) == 2
assert resp['notifications'][0]['template_version'] == 1
assert resp['notifications'][0]['body'] == 'This is a template'
assert resp['notifications'][1]['template_version'] == 2
assert resp['notifications'][1]['body'] == 'foo'
def _create_auth_header_from_key(api_key):