Merge pull request #2924 from alphagov/add-contact-block-to-serialize-template

Add contact block to serialize template for v2
This commit is contained in:
Pea M. Tyczynska
2020-07-23 15:42:17 +01:00
committed by GitHub
3 changed files with 12 additions and 2 deletions

View File

@@ -184,6 +184,7 @@ def create_template(
folder=None,
postage=None,
process_type='normal',
contact_block_id=None
):
data = {
'name': template_name or '{} Template Name'.format(template_type),
@@ -194,10 +195,12 @@ def create_template(
'reply_to': reply_to,
'hidden': hidden,
'folder': folder,
'process_type': process_type
'process_type': process_type,
}
if template_type == LETTER_TYPE:
data["postage"] = postage or "second"
if contact_block_id:
data['service_letter_contact_id'] = contact_block_id
if template_type != SMS_TYPE:
data['subject'] = subject
template = Template(**data)

View File

@@ -19,7 +19,12 @@ valid_version_params = [None, 1]
def test_get_template_by_id_returns_200(
client, sample_service, tmp_type, expected_name, expected_subject, version, postage
):
template = create_template(sample_service, template_type=tmp_type)
letter_contact_block_id = None
if tmp_type == 'letter':
letter_contact_block = create_letter_contact(sample_service, "Buckingham Palace, London, SW1A 1AA")
letter_contact_block_id = letter_contact_block.id
template = create_template(sample_service, template_type=tmp_type, contact_block_id=(letter_contact_block_id))
auth_header = create_authorization_header(service_id=sample_service.id)
version_path = '/version/{}'.format(version) if version else ''
@@ -44,6 +49,7 @@ def test_get_template_by_id_returns_200(
'name': expected_name,
'personalisation': {},
'postage': postage,
'letter_contact_block': letter_contact_block.contact_block if letter_contact_block_id else None,
}
assert json_response == expected_response