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.
This commit is contained in:
Alexey Bezhan
2017-11-09 14:42:43 +00:00
parent 94dae42902
commit c62f2a3f7c
2 changed files with 10 additions and 9 deletions

View File

@@ -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,

View File

@@ -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