mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-23 15:56:45 -04:00
Test postage setting on happy path for create and update template
This commit is contained in:
@@ -18,7 +18,8 @@ from app.models import (
|
|||||||
LETTER_TYPE,
|
LETTER_TYPE,
|
||||||
SMS_TYPE,
|
SMS_TYPE,
|
||||||
Template,
|
Template,
|
||||||
TemplateHistory
|
TemplateHistory,
|
||||||
|
CHOOSE_POSTAGE
|
||||||
)
|
)
|
||||||
from app.dao.templates_dao import dao_get_template_by_id, dao_redact_template
|
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(
|
def test_should_create_a_new_template_for_a_service(
|
||||||
client, sample_user, template_type, subject
|
client, sample_user, template_type, subject
|
||||||
):
|
):
|
||||||
service = create_service(service_permissions=[template_type])
|
service = create_service(service_permissions=[template_type, CHOOSE_POSTAGE])
|
||||||
data = {
|
data = {
|
||||||
'name': 'my template',
|
'name': 'my template',
|
||||||
'template_type': template_type,
|
'template_type': template_type,
|
||||||
@@ -53,6 +54,8 @@ def test_should_create_a_new_template_for_a_service(
|
|||||||
}
|
}
|
||||||
if subject:
|
if subject:
|
||||||
data.update({'subject': subject})
|
data.update({'subject': subject})
|
||||||
|
if template_type == LETTER_TYPE:
|
||||||
|
data.update({'postage': 'first'})
|
||||||
data = json.dumps(data)
|
data = json.dumps(data)
|
||||||
auth_header = create_authorization_header()
|
auth_header = create_authorization_header()
|
||||||
|
|
||||||
@@ -76,6 +79,11 @@ def test_should_create_a_new_template_for_a_service(
|
|||||||
else:
|
else:
|
||||||
assert not json_resp['data']['subject']
|
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'])
|
template = Template.query.get(json_resp['data']['id'])
|
||||||
from app.schemas import template_schema
|
from app.schemas import template_schema
|
||||||
assert sorted(json_resp['data']) == sorted(template_schema.dump(template).data)
|
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'
|
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 = {
|
data = {
|
||||||
'content': 'my template has new content <script type="text/javascript">alert("foo")</script>',
|
'content': 'my template has new content, swell!',
|
||||||
'created_by': str(sample_user.id)
|
'created_by': str(sample_user.id),
|
||||||
|
'postage': 'first'
|
||||||
}
|
}
|
||||||
data = json.dumps(data)
|
data = json.dumps(data)
|
||||||
auth_header = create_authorization_header()
|
auth_header = create_authorization_header()
|
||||||
|
|
||||||
update_response = client.post(
|
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],
|
headers=[('Content-Type', 'application/json'), auth_header],
|
||||||
data=data
|
data=data
|
||||||
)
|
)
|
||||||
@@ -373,10 +384,11 @@ def test_update_should_update_a_template(client, sample_user, sample_template):
|
|||||||
assert update_response.status_code == 200
|
assert update_response.status_code == 200
|
||||||
update_json_resp = json.loads(update_response.get_data(as_text=True))
|
update_json_resp = json.loads(update_response.get_data(as_text=True))
|
||||||
assert update_json_resp['data']['content'] == (
|
assert update_json_resp['data']['content'] == (
|
||||||
'my template has new content <script type="text/javascript">alert("foo")</script>'
|
'my template has new content, swell!'
|
||||||
)
|
)
|
||||||
assert update_json_resp['data']['name'] == sample_template.name
|
assert update_json_resp['data']['postage'] == 'first'
|
||||||
assert update_json_resp['data']['template_type'] == sample_template.template_type
|
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
|
assert update_json_resp['data']['version'] == 2
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user