From fb1ca9b20d636f73a4a37f59fec88488614ea617 Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Mon, 24 Dec 2018 12:24:17 +0000 Subject: [PATCH] Test postage setting on happy path for create and update template --- tests/app/template/test_rest.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/tests/app/template/test_rest.py b/tests/app/template/test_rest.py index 429172011..64c51becc 100644 --- a/tests/app/template/test_rest.py +++ b/tests/app/template/test_rest.py @@ -18,7 +18,8 @@ from app.models import ( LETTER_TYPE, SMS_TYPE, Template, - TemplateHistory + TemplateHistory, + CHOOSE_POSTAGE ) from app.dao.templates_dao import dao_get_template_by_id, dao_redact_template @@ -43,7 +44,7 @@ from tests.conftest import set_config_values def test_should_create_a_new_template_for_a_service( client, sample_user, template_type, subject ): - service = create_service(service_permissions=[template_type]) + service = create_service(service_permissions=[template_type, CHOOSE_POSTAGE]) data = { 'name': 'my template', 'template_type': template_type, @@ -53,6 +54,8 @@ def test_should_create_a_new_template_for_a_service( } if subject: data.update({'subject': subject}) + if template_type == LETTER_TYPE: + data.update({'postage': 'first'}) data = json.dumps(data) auth_header = create_authorization_header() @@ -76,6 +79,11 @@ def test_should_create_a_new_template_for_a_service( else: assert not json_resp['data']['subject'] + if template_type == LETTER_TYPE: + assert json_resp['data']['postage'] == 'first' + else: + assert not json_resp['data']['postage'] + template = Template.query.get(json_resp['data']['id']) from app.schemas import template_schema assert sorted(json_resp['data']) == sorted(template_schema.dump(template).data) @@ -356,16 +364,19 @@ def test_must_have_a_subject_on_an_email_or_letter_template(client, sample_user, assert json_resp['errors'][0]["message"] == 'subject is a required property' -def test_update_should_update_a_template(client, sample_user, sample_template): +def test_update_should_update_a_template(client, sample_user): + service = create_service(service_permissions=[LETTER_TYPE, CHOOSE_POSTAGE]) + template = create_template(service, template_type="letter", postage="second") data = { - 'content': 'my template has new content ', - 'created_by': str(sample_user.id) + 'content': 'my template has new content, swell!', + 'created_by': str(sample_user.id), + 'postage': 'first' } data = json.dumps(data) auth_header = create_authorization_header() update_response = client.post( - '/service/{}/template/{}'.format(sample_template.service_id, sample_template.id), + '/service/{}/template/{}'.format(service.id, template.id), headers=[('Content-Type', 'application/json'), auth_header], data=data ) @@ -373,10 +384,11 @@ def test_update_should_update_a_template(client, sample_user, sample_template): assert update_response.status_code == 200 update_json_resp = json.loads(update_response.get_data(as_text=True)) assert update_json_resp['data']['content'] == ( - 'my template has new content ' + 'my template has new content, swell!' ) - assert update_json_resp['data']['name'] == sample_template.name - assert update_json_resp['data']['template_type'] == sample_template.template_type + assert update_json_resp['data']['postage'] == 'first' + assert update_json_resp['data']['name'] == template.name + assert update_json_resp['data']['template_type'] == template.template_type assert update_json_resp['data']['version'] == 2