From c62f2a3f7cb88cc0587cb7d9526c2cc7e4ee0cc5 Mon Sep 17 00:00:00 2001 From: Alexey Bezhan Date: Thu, 9 Nov 2017 14:42:43 +0000 Subject: [PATCH] Update create_custom_template test helper to create history object `create_custom_template` is not using `dao_create_template` since it explicitly sets a template id. Notifications.template relationship now refers to a TemplateHistory objects, so we need to make sure that `create_custom_template` creates a matching TemplateHistory record when it creates a Template. --- tests/app/celery/test_scheduled_tasks.py | 16 +++++++--------- tests/app/conftest.py | 3 +++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/app/celery/test_scheduled_tasks.py b/tests/app/celery/test_scheduled_tasks.py index 01e40dd95..6bdce0f6f 100644 --- a/tests/app/celery/test_scheduled_tasks.py +++ b/tests/app/celery/test_scheduled_tasks.py @@ -48,7 +48,6 @@ from app.models import ( NotificationHistory, Service, StatsTemplateUsageByMonth, - Template, JOB_STATUS_READY_TO_SEND, JOB_STATUS_IN_PROGRESS, JOB_STATUS_SENT_TO_DVLA, @@ -81,14 +80,13 @@ def _create_slow_delivery_notification(provider='mmg'): service = create_service( service_id=current_app.config.get('FUNCTIONAL_TEST_PROVIDER_SERVICE_ID') ) - template = Template.query.get(current_app.config['FUNCTIONAL_TEST_PROVIDER_SMS_TEMPLATE_ID']) - if not template: - template = create_custom_template( - service=service, - user=service.users[0], - template_config_name='FUNCTIONAL_TEST_PROVIDER_SMS_TEMPLATE_ID', - template_type='sms' - ) + + template = create_custom_template( + service=service, + user=service.users[0], + template_config_name='FUNCTIONAL_TEST_PROVIDER_SMS_TEMPLATE_ID', + template_type='sms' + ) create_notification( template=template, diff --git a/tests/app/conftest.py b/tests/app/conftest.py index 356c951e5..f2c2cd41f 100644 --- a/tests/app/conftest.py +++ b/tests/app/conftest.py @@ -14,6 +14,7 @@ from app import db from app.models import ( Service, Template, + TemplateHistory, ApiKey, Job, Notification, @@ -38,6 +39,7 @@ from app.dao.notifications_dao import dao_create_notification from app.dao.invited_user_dao import save_invited_user from app.dao.provider_rates_dao import create_provider_rates from app.clients.sms.firetext import FiretextClient +from app.history_meta import create_history from tests import create_authorization_header from tests.app.db import ( create_user, @@ -974,6 +976,7 @@ def create_custom_template(service, user, template_config_name, template_type, c } template = Template(**data) db.session.add(template) + db.session.add(create_history(template, TemplateHistory)) db.session.commit() return template