Set postage to second class when creating new letter template

Also get rid of checks for CHOOSE_POSTAGE permission when creating
and updating a template.
This commit is contained in:
Pea Tyczynska
2019-01-30 16:26:49 +00:00
parent 208af8a508
commit ccd5a758f0
2 changed files with 33 additions and 68 deletions

View File

@@ -89,7 +89,7 @@ def test_should_create_a_new_template_for_a_service(
assert sorted(json_resp['data']) == sorted(template_schema.dump(template).data)
def test_should_create_a_new_template_for_a_service_adds_folder_relationship(
def test_create_a_new_template_for_a_service_adds_folder_relationship(
client, sample_service
):
parent_folder = create_template_folder(service=sample_service, name='parent folder')
@@ -115,6 +115,35 @@ def test_should_create_a_new_template_for_a_service_adds_folder_relationship(
assert template.folder == parent_folder
@pytest.mark.parametrize("template_type, expected_postage", [
(SMS_TYPE, None), (EMAIL_TYPE, None), (LETTER_TYPE, "second")
])
def test_create_a_new_template_for_a_service_adds_postage_for_letters_only(
client, sample_service, template_type, expected_postage
):
data = {
'name': 'my template',
'template_type': template_type,
'content': 'template <b>content</b>',
'service': str(sample_service.id),
'created_by': str(sample_service.users[0].id)
}
if template_type in [EMAIL_TYPE, LETTER_TYPE]:
data["subject"] = "Hi, I have good news"
data = json.dumps(data)
auth_header = create_authorization_header()
response = client.post(
'/service/{}/template'.format(sample_service.id),
headers=[('Content-Type', 'application/json'), auth_header],
data=data
)
assert response.status_code == 201
template = Template.query.filter(Template.name == 'my template').first()
assert template.postage == expected_postage
def test_create_template_should_return_400_if_folder_is_for_a_different_service(
client, sample_service
):
@@ -218,34 +247,6 @@ def test_should_raise_error_on_create_if_no_permission(
assert json_resp['message'] == expected_error
def test_should_raise_error_on_create_if_no_choose_postage_permission(client, sample_user):
service = create_service(service_permissions=[LETTER_TYPE])
data = {
'name': 'my template',
'template_type': LETTER_TYPE,
'content': 'template content',
'service': str(service.id),
'created_by': str(sample_user.id),
'subject': "Some letter",
'postage': 'first',
}
data = json.dumps(data)
auth_header = create_authorization_header()
response = client.post(
'/service/{}/template'.format(service.id),
headers=[('Content-Type', 'application/json'), auth_header],
data=data
)
json_resp = json.loads(response.get_data(as_text=True))
assert response.status_code == 403
assert json_resp['result'] == 'error'
assert json_resp['message'] == {
"template_postage": ["Setting postage on templates is not enabled for this service."]
}
@pytest.mark.parametrize('template_factory, expected_error', [
(sample_template_without_sms_permission, {'template_type': ['Updating text message templates is not allowed']}),
(sample_template_without_email_permission, {'template_type': ['Updating email templates is not allowed']}),
@@ -275,33 +276,6 @@ def test_should_be_error_on_update_if_no_permission(
assert json_resp['message'] == expected_error
def test_should_be_error_on_update_if_no_choose_postage_permission(client, sample_user):
service = create_service(service_name='some_service', service_permissions=[LETTER_TYPE])
template = create_template(service, template_type=LETTER_TYPE)
data = {
'content': 'new template content',
'created_by': str(sample_user.id),
'postage': 'first'
}
data = json.dumps(data)
auth_header = create_authorization_header()
update_response = client.post(
'/service/{}/template/{}'.format(
template.service_id, template.id),
headers=[('Content-Type', 'application/json'), auth_header],
data=data
)
json_resp = json.loads(update_response.get_data(as_text=True))
assert update_response.status_code == 403
assert json_resp['result'] == 'error'
assert json_resp['message'] == {
"template_postage": ["Setting postage on templates is not enabled for this service."]
}
def test_should_error_if_created_by_missing(client, sample_user, sample_service):
service_id = str(sample_service.id)
data = {