diff --git a/app/models.py b/app/models.py index 801bc62be..e7fbce1a0 100644 --- a/app/models.py +++ b/app/models.py @@ -682,7 +682,6 @@ class NotificationHistory(db.Model): @classmethod def from_notification(cls, notification): history = cls(**{c.name: getattr(notification, c.name) for c in cls.__table__.columns}) - history.template = notification.template return history def update_from_notification(self, notification): diff --git a/tests/app/conftest.py b/tests/app/conftest.py index c6cc1a024..674b99e31 100644 --- a/tests/app/conftest.py +++ b/tests/app/conftest.py @@ -434,6 +434,7 @@ def sample_notification(notify_db, 'job': job, 'service_id': service.id, 'service': service, + 'template_id': template.id if template else None, 'template': template, 'template_version': template.version, 'status': status, diff --git a/tests/app/notifications/test_process_notification.py b/tests/app/notifications/test_process_notification.py index b43379848..95b0d2cb9 100644 --- a/tests/app/notifications/test_process_notification.py +++ b/tests/app/notifications/test_process_notification.py @@ -42,17 +42,38 @@ def test_create_content_for_notification_fails_with_additional_personalisation(s @freeze_time("2016-01-01 11:09:00.061258") -def test_persist_notification_creates_and_save_to_db(sample_template, sample_api_key, mocker): +def test_persist_notification_creates_and_save_to_db(sample_template, sample_api_key, sample_job, mocker): mocked_redis = mocker.patch('app.notifications.process_notifications.redis_store.incr') assert Notification.query.count() == 0 assert NotificationHistory.query.count() == 0 notification = persist_notification(sample_template.id, sample_template.version, '+447111111111', sample_template.service.id, {}, 'sms', sample_api_key.id, - sample_api_key.key_type) - assert Notification.query.count() == 1 + sample_api_key.key_type, job_id=sample_job.id, + job_row_number=100, reference="ref") + assert Notification.query.get(notification.id) is not None - assert NotificationHistory.query.count() == 1 + assert NotificationHistory.query.get(notification.id) is not None + + notification_from_db = Notification.query.one() + notification_history_from_db = NotificationHistory.query.one() + + assert notification_from_db.id == notification_history_from_db.id + assert notification_from_db.template_id == notification_history_from_db.template_id + assert notification_from_db.template_version == notification_history_from_db.template_version + assert notification_from_db.api_key_id == notification_history_from_db.api_key_id + assert notification_from_db.key_type == notification_history_from_db.key_type + assert notification_from_db.key_type == notification_history_from_db.key_type + assert notification_from_db.billable_units == notification_history_from_db.billable_units + assert notification_from_db.notification_type == notification_history_from_db.notification_type + assert notification_from_db.created_at == notification_history_from_db.created_at + assert not notification_from_db.sent_at + assert not notification_history_from_db.sent_at + assert notification_from_db.updated_at == notification_history_from_db.updated_at + assert notification_from_db.status == notification_history_from_db.status + assert notification_from_db.reference == notification_history_from_db.reference + assert notification_from_db.client_reference == notification_history_from_db.client_reference + mocked_redis.assert_called_once_with(str(sample_template.service_id) + "-2016-01-01-count") diff --git a/tests/app/template_statistics/test_rest.py b/tests/app/template_statistics/test_rest.py index 1e85d0165..8a9ad4ae3 100644 --- a/tests/app/template_statistics/test_rest.py +++ b/tests/app/template_statistics/test_rest.py @@ -3,8 +3,6 @@ import json from freezegun import freeze_time -from app import db -from app.models import TemplateStatistics from tests import create_authorization_header from tests.app.conftest import sample_template as create_sample_template, sample_template, sample_notification, \ sample_email_template