diff --git a/tests/app/dao/test_templates_dao.py b/tests/app/dao/test_templates_dao.py index a01126445..287db454c 100644 --- a/tests/app/dao/test_templates_dao.py +++ b/tests/app/dao/test_templates_dao.py @@ -10,14 +10,20 @@ from app.models import Template, TemplateHistory import pytest -def test_create_template(sample_service, sample_user): +@pytest.mark.parametrize('template_type, subject', [ + ('sms', None), + ('email', 'subject'), +]) +def test_create_template(sample_service, sample_user, template_type, subject): data = { 'name': 'Sample Template', - 'template_type': "sms", + 'template_type': template_type, 'content': "Template content", 'service': sample_service, 'created_by': sample_user } + if subject: + data.update({'subject': subject}) template = Template(**data) dao_create_template(template) diff --git a/tests/app/template/test_rest.py b/tests/app/template/test_rest.py index 2d36e4360..8f18e5f0e 100644 --- a/tests/app/template/test_rest.py +++ b/tests/app/template/test_rest.py @@ -1,3 +1,4 @@ +import pytest import json import random import string @@ -8,16 +9,24 @@ from tests.app.conftest import sample_template as create_sample_template from app.dao.templates_dao import dao_get_template_by_id -def test_should_create_a_new_sms_template_for_a_service(notify_api, sample_user, sample_service): +@pytest.mark.parametrize('template_type, subject', [ + ('sms', None), + ('email', 'subject'), +]) +def test_should_create_a_new_template_for_a_service( + notify_api, sample_user, sample_service, template_type, subject +): with notify_api.test_request_context(): with notify_api.test_client() as client: data = { 'name': 'my template', - 'template_type': 'sms', + 'template_type': template_type, 'content': 'template content', 'service': str(sample_service.id), 'created_by': str(sample_user.id) } + if subject: + data.update({'subject': subject}) data = json.dumps(data) auth_header = create_authorization_header() @@ -29,12 +38,15 @@ def test_should_create_a_new_sms_template_for_a_service(notify_api, sample_user, assert response.status_code == 201 json_resp = json.loads(response.get_data(as_text=True)) assert json_resp['data']['name'] == 'my template' - assert json_resp['data']['template_type'] == 'sms' + assert json_resp['data']['template_type'] == template_type assert json_resp['data']['content'] == 'template content' assert json_resp['data']['service'] == str(sample_service.id) assert json_resp['data']['id'] assert json_resp['data']['version'] == 1 - assert not json_resp['data']['subject'] + if subject: + assert json_resp['data']['subject'] == 'subject' + else: + assert not json_resp['data']['subject'] def test_should_create_a_new_email_template_for_a_service(notify_api, sample_user, sample_service):