def test_letter_output_notification_reference(extra_args, expected_field): template = LetterDVLATemplate({ 'content': '', 'subject': '' }, notification_reference="1234567", **extra_args) assert str(template).split('|')[1] == expected_field
def test_letter_output_stores_valid_notification_reference(): assert LetterDVLATemplate( { 'content': '', 'subject': '' }, notification_reference="1234567", ).notification_reference == "1234567"
def test_letter_address_format(address, expected): assert LetterDVLATemplate( { 'content': '', 'subject': '' }, address, notification_reference="1234567", ).values_with_default_optional_address_lines == expected
def test_letter_output_numeric_id(id, expected_exception): with pytest.raises(TypeError) as error: LetterDVLATemplate( { 'content': '', 'subject': '' }, notification_reference=id, ) assert str(error.value) == expected_exception
def test_lists_in_combination_with_other_elements_in_letters( markdown, expected): assert str( LetterDVLATemplate( { 'content': markdown, 'subject': 'Hello' }, {}, notification_reference="1234567", )).split('|')[ 33] == '1 January 2001<cr><cr><h1>Hello<normal><cr><cr>' + expected
def view_template_as_dvla_markup(service_id, template_id): template = service_api_client.get_service_template(service_id, str(template_id))['data'] if template['template_type'] != 'letter': abort(404) return Response( str(LetterDVLATemplate( template, notification_reference=1, )), mimetype='text/plain', )
def test_letter_output_pipe_delimiting(): template = LetterDVLATemplate( { "content": 'Pipes | pipes | everywhere', 'subject': 'Your | is due soon', }, { 'thing': '|', 'name': '|', 'address line 1': '|', 'address line 2': 'Managing Director', 'address line 3': '123 Electric Avenue', 'address line 4': 'Great Yarmouth', 'address line 5': 'Norfolk', 'address line 6': '', 'postcode': 'NR1 5PQ', }, notification_reference="1", ) assert len(str(template).split('|')) == len(dvla_file_spec) assert 'Pipes pipes everywhere' in str(template)
def test_letter_output_template(field): # To debug this test it’s helpful uncomment the following line: # print(field) template = LetterDVLATemplate( { "content": ('Dear ((name)),\n\n' 'Thank you for applying to register a lasting power of ' 'attorney (LPA) for property and financial affairs. We ' 'have checked your application and...'), 'subject': 'Your ((thing)) is something & something', }, { 'thing': 'application', 'name': 'Henry Hadlow', 'addressline1': 'Mr Henry Hadlow', 'addressline2': '123 Electric Avenue', 'addressline3': 'Great Yarmouth', 'addressline4': 'Norfolk', 'addressline5': '', 'addressline6': '', 'postcode': 'NR1 5PQ', }, notification_reference="reference", contact_block=""" The Pension Service Mail Handling Site A Wolverhampton WV9 1LU Telephone: 0845 300 0168 Email: [email protected] Monday - Friday 8am - 6pm www.gov.uk """, ) assert str(template).split('|')[int(field['Field number']) - 1] == field['Example']
LetterImageTemplate( { "content": "((content))", "subject": "((subject))" }, contact_block='((contact_block))', image_url='http://example.com', page_count=99, ), ['content', 'subject', 'contact_block'], ), ( LetterDVLATemplate( { "content": "((content))", "subject": "((subject))" }, contact_block='((contact_block))', notification_reference='foo', ), ['content', 'subject', 'contact_block'], ), ]) def test_templates_extract_placeholders( template_instance, expected_placeholders, ): assert template_instance.placeholders == set(expected_placeholders) def test_email_preview_escapes_html_in_from_name(): template = EmailPreviewTemplate(