From 7b1f07dd31c3343cf24cf5d2bb7c33f7f7242b11 Mon Sep 17 00:00:00 2001 From: Alexey Bezhan Date: Wed, 22 Nov 2017 14:19:49 +0000 Subject: [PATCH] Add tests for reading and updating template reply_to through the API --- tests/app/template/test_rest.py | 37 +++++++++++++++++++++++-- tests/app/template/test_rest_history.py | 19 +++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/tests/app/template/test_rest.py b/tests/app/template/test_rest.py index 2c0f8ea96..da72c3dff 100644 --- a/tests/app/template/test_rest.py +++ b/tests/app/template/test_rest.py @@ -17,9 +17,7 @@ from tests.app.conftest import ( sample_template_without_letter_permission, sample_template_without_sms_permission, ) -from tests.app.db import create_service - -from app.dao.templates_dao import dao_get_template_by_id +from tests.app.db import create_service, create_letter_contact @pytest.mark.parametrize('template_type, subject', [ @@ -618,6 +616,39 @@ def test_update_set_process_type_on_template(client, sample_template): assert template.process_type == 'priority' +def test_get_template_reply_to(client, sample_letter_template): + auth_header = create_authorization_header() + letter_contact = create_letter_contact(sample_letter_template.service, "Edinburgh, ED1 1AA") + sample_letter_template.reply_to = str(letter_contact.id) + + resp = client.get('/service/{}/template/{}'.format(sample_letter_template.service_id, sample_letter_template.id), + headers=[auth_header]) + + assert resp.status_code == 200, resp.get_data(as_text=True) + json_resp = json.loads(resp.get_data(as_text=True)) + + assert 'service_letter_contact_id' not in json_resp['data'] + assert json_resp['data']['reply_to'] == str(letter_contact.id) + + +def test_update_template_reply_to(client, sample_letter_template): + auth_header = create_authorization_header() + letter_contact = create_letter_contact(sample_letter_template.service, "Edinburgh, ED1 1AA") + + data = { + 'reply_to': str(letter_contact.id), + } + + resp = client.post('/service/{}/template/{}'.format(sample_letter_template.service_id, sample_letter_template.id), + data=json.dumps(data), + headers=[('Content-Type', 'application/json'), auth_header]) + + assert resp.status_code == 200, resp.get_data(as_text=True) + + template = dao_get_template_by_id(sample_letter_template.id) + assert template.reply_to == letter_contact.id + + def test_update_redact_template(admin_request, sample_template): assert sample_template.redact_personalisation is False diff --git a/tests/app/template/test_rest_history.py b/tests/app/template/test_rest_history.py index 482b04aad..c26c4abc8 100644 --- a/tests/app/template/test_rest_history.py +++ b/tests/app/template/test_rest_history.py @@ -3,6 +3,7 @@ from datetime import (datetime, date) from flask import url_for from app.dao.templates_dao import dao_update_template from tests import create_authorization_header +from tests.app.db import create_letter_contact def test_template_history_version(notify_api, sample_user, sample_template): @@ -93,3 +94,21 @@ def test_all_versions_of_template(notify_api, sample_template): assert json_resp['data'][1]['content'] == newer_content assert json_resp['data'][1]['updated_at'] assert json_resp['data'][2]['content'] == old_content + + +def test_update_template_reply_to_updates_history(client, sample_letter_template): + auth_header = create_authorization_header() + letter_contact = create_letter_contact(sample_letter_template.service, "Edinburgh, ED1 1AA") + + sample_letter_template.reply_to = letter_contact.id + dao_update_template(sample_letter_template) + + resp = client.get( + '/service/{}/template/{}/version/2'.format(sample_letter_template.service_id, sample_letter_template.id), + headers=[auth_header] + ) + assert resp.status_code == 200 + + hist_json_resp = json.loads(resp.get_data(as_text=True)) + assert 'service_letter_contact_id' not in hist_json_resp['data'] + assert hist_json_resp['data']['reply_to'] == str(letter_contact.id)