Restore dao_create_template and use custom template fixture instead

This commit is contained in:
Imdad Ahad
2017-03-08 13:03:44 +00:00
parent 36d52c6e42
commit a4dc614ef7
4 changed files with 50 additions and 43 deletions

View File

@@ -13,8 +13,8 @@ from app.dao.dao_utils import (
@transactional @transactional
@version_class(Template, TemplateHistory) @version_class(Template, TemplateHistory)
def dao_create_template(template, template_id=None): def dao_create_template(template):
template.id = template_id or uuid.uuid4() # must be set now so version history model can use same id template.id = uuid.uuid4() # must be set now so version history model can use same id
template.archived = False template.archived = False
db.session.add(template) db.session.add(template)

View File

@@ -26,11 +26,11 @@ from app.dao.provider_details_dao import (
) )
from app.models import Service, Template from app.models import Service, Template
from app.utils import get_london_midnight_in_utc from app.utils import get_london_midnight_in_utc
from tests.app.db import create_notification, create_service, create_template from tests.app.db import create_notification, create_service
from tests.app.conftest import ( from tests.app.conftest import (
sample_job as create_sample_job, sample_job as create_sample_job,
sample_notification_history as create_notification_history, sample_notification_history as create_notification_history,
create_notify_template create_custom_template
) )
from tests.conftest import set_config_values from tests.conftest import set_config_values
from unittest.mock import call, patch, PropertyMock from unittest.mock import call, patch, PropertyMock
@@ -46,17 +46,12 @@ def _create_slow_delivery_notification(provider='mmg'):
) )
template = Template.query.get(current_app.config['FUNCTIONAL_TEST_PROVIDER_SMS_TEMPLATE_ID']) template = Template.query.get(current_app.config['FUNCTIONAL_TEST_PROVIDER_SMS_TEMPLATE_ID'])
if not template: if not template:
template = create_notify_template( template = create_custom_template(
service=service, service=service,
user=service.users[0], user=service.users[0],
template_config_name='FUNCTIONAL_TEST_PROVIDER_SMS_TEMPLATE_ID', template_config_name='FUNCTIONAL_TEST_PROVIDER_SMS_TEMPLATE_ID',
content='',
template_type='sms' template_type='sms'
) )
# template = create_template(
# template_id=current_app.config.get('FUNCTIONAL_TEST_PROVIDER_SMS_TEMPLATE_ID'),
# service=service
# )
create_notification( create_notification(
template=template, template=template,

View File

@@ -782,22 +782,26 @@ def mock_firetext_client(mocker, statsd_client=None):
def sms_code_template(notify_db, def sms_code_template(notify_db,
notify_db_session): notify_db_session):
service, user = notify_service(notify_db, notify_db_session) service, user = notify_service(notify_db, notify_db_session)
return create_notify_template(service=service, return create_custom_template(
user=user, service=service,
template_config_name='SMS_CODE_TEMPLATE_ID', user=user,
content='((verify_code))', template_config_name='SMS_CODE_TEMPLATE_ID',
template_type='sms') content='((verify_code))',
template_type='sms'
)
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def email_verification_template(notify_db, def email_verification_template(notify_db,
notify_db_session): notify_db_session):
service, user = notify_service(notify_db, notify_db_session) service, user = notify_service(notify_db, notify_db_session)
return create_notify_template(service=service, return create_custom_template(
user=user, service=service,
template_config_name='EMAIL_VERIFY_CODE_TEMPLATE_ID', user=user,
content='((user_name)) use ((url)) to complete registration', template_config_name='EMAIL_VERIFY_CODE_TEMPLATE_ID',
template_type='email') content='((user_name)) use ((url)) to complete registration',
template_type='email'
)
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
@@ -805,12 +809,14 @@ def invitation_email_template(notify_db,
notify_db_session): notify_db_session):
service, user = notify_service(notify_db, notify_db_session) service, user = notify_service(notify_db, notify_db_session)
content = '((user_name)) is invited to Notify by ((service_name)) ((url)) to complete registration', content = '((user_name)) is invited to Notify by ((service_name)) ((url)) to complete registration',
return create_notify_template(service=service, return create_custom_template(
user=user, service=service,
template_config_name='INVITATION_EMAIL_TEMPLATE_ID', user=user,
content=content, template_config_name='INVITATION_EMAIL_TEMPLATE_ID',
subject='Invitation to ((service_name))', content=content,
template_type='email') subject='Invitation to ((service_name))',
template_type='email'
)
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
@@ -818,12 +824,14 @@ def password_reset_email_template(notify_db,
notify_db_session): notify_db_session):
service, user = notify_service(notify_db, notify_db_session) service, user = notify_service(notify_db, notify_db_session)
return create_notify_template(service=service, return create_custom_template(
user=user, service=service,
template_config_name='PASSWORD_RESET_TEMPLATE_ID', user=user,
content='((user_name)) you can reset password by clicking ((url))', template_config_name='PASSWORD_RESET_TEMPLATE_ID',
subject='Reset your password', content='((user_name)) you can reset password by clicking ((url))',
template_type='email') subject='Reset your password',
template_type='email'
)
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
@@ -833,10 +841,12 @@ def already_registered_template(notify_db,
content = """Sign in here: ((signin_url)) If youve forgotten your password, content = """Sign in here: ((signin_url)) If youve forgotten your password,
you can reset it here: ((forgot_password_url)) feedback:((feedback_url))""" you can reset it here: ((forgot_password_url)) feedback:((feedback_url))"""
return create_notify_template(service=service, user=user, return create_custom_template(
template_config_name='ALREADY_REGISTERED_EMAIL_TEMPLATE_ID', service=service, user=user,
content=content, template_config_name='ALREADY_REGISTERED_EMAIL_TEMPLATE_ID',
template_type='email') content=content,
template_type='email'
)
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
@@ -848,15 +858,17 @@ def change_email_confirmation_template(notify_db,
((url)) ((url))
If you didnt try to change the email address for your GOV.UK Notify account, let us know here: If you didnt try to change the email address for your GOV.UK Notify account, let us know here:
((feedback_url))""" ((feedback_url))"""
template = create_notify_template(service=service, template = create_custom_template(
user=user, service=service,
template_config_name='CHANGE_EMAIL_CONFIRMATION_TEMPLATE_ID', user=user,
content=content, template_config_name='CHANGE_EMAIL_CONFIRMATION_TEMPLATE_ID',
template_type='email') content=content,
template_type='email'
)
return template return template
def create_notify_template(service, user, template_config_name, content, template_type, subject=None): def create_custom_template(service, user, template_config_name, template_type, content='', subject=None):
template = Template.query.get(current_app.config[template_config_name]) template = Template.query.get(current_app.config[template_config_name])
if not template: if not template:
data = { data = {

View File

@@ -51,7 +51,7 @@ def create_template(
if template_type != SMS_TYPE: if template_type != SMS_TYPE:
data['subject'] = 'Template subject' data['subject'] = 'Template subject'
template = Template(**data) template = Template(**data)
dao_create_template(template, template_id) dao_create_template(template)
return template return template