Merge pull request #2549 from alphagov/revert-2536-ensure_no_errors_when_creating_template

Revert "Ensure dao_create_template doesn't clash with new trigger"
This commit is contained in:
Pea (Malgorzata Tyczynska)
2019-06-26 18:34:48 +01:00
committed by GitHub
2 changed files with 11 additions and 14 deletions

View File

@@ -24,19 +24,16 @@ def dao_create_template(template):
template.id = 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
# The template redacted is now being inserted via a trigger redacted_dict = {
# this will catch any Notify templates being added by a db migration "template": template,
if not TemplateRedacted.query.filter(TemplateRedacted.template_id == template.id).first(): "redact_personalisation": False,
redacted_dict = { }
"template": template, if template.created_by:
"redact_personalisation": False, redacted_dict.update({"updated_by": template.created_by})
} else:
if template.created_by: redacted_dict.update({"updated_by_id": template.created_by_id})
redacted_dict.update({"updated_by": template.created_by})
else:
redacted_dict.update({"updated_by_id": template.created_by_id})
template.template_redacted = TemplateRedacted(**redacted_dict) template.template_redacted = TemplateRedacted(**redacted_dict)
db.session.add(template) db.session.add(template)

View File

@@ -17,7 +17,7 @@ valid_version_params = [None, 1]
]) ])
@pytest.mark.parametrize("version", valid_version_params) @pytest.mark.parametrize("version", valid_version_params)
def test_get_template_by_id_returns_200( def test_get_template_by_id_returns_200(
client, sample_service, mock, tmp_type, expected_name, expected_subject, version, postage client, sample_service, tmp_type, expected_name, expected_subject, version, postage
): ):
template = create_template(sample_service, template_type=tmp_type) template = create_template(sample_service, template_type=tmp_type)
auth_header = create_authorization_header(service_id=sample_service.id) auth_header = create_authorization_header(service_id=sample_service.id)
@@ -36,7 +36,7 @@ def test_get_template_by_id_returns_200(
'id': '{}'.format(template.id), 'id': '{}'.format(template.id),
'type': '{}'.format(template.template_type), 'type': '{}'.format(template.template_type),
'created_at': template.created_at.strftime(DATETIME_FORMAT), 'created_at': template.created_at.strftime(DATETIME_FORMAT),
'updated_at': mock.ANY, 'updated_at': None,
'version': template.version, 'version': template.version,
'created_by': template.created_by.email_address, 'created_by': template.created_by.email_address,
'body': template.content, 'body': template.content,