From 3a2cfda8b24aa95b76128448fc5a1a092cc91a9b Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 3 Jan 2019 15:18:53 +0000 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20show=20postage=20to=20users=20w?= =?UTF-8?q?ho=20can=E2=80=99t=20choose=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If you can’t choose postage on a per-template basis, you shouldn’t be see the thing that indicates that postage can be changed. --- app/templates/views/templates/_template.html | 11 +++++------ tests/app/main/views/test_templates.py | 12 ++++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/templates/views/templates/_template.html b/app/templates/views/templates/_template.html index 61b75a257..ad56f8911 100644 --- a/app/templates/views/templates/_template.html +++ b/app/templates/views/templates/_template.html @@ -21,13 +21,12 @@ Send -
- {% if current_service.has_permission("choose_postage") and template_postage %} -

Postage

: {{ template_postage }} class - {% elif (current_service.has_permission("choose_postage") and not template_postage) or not current_service.has_permission("choose_postage") %} -

Postage

: {{ current_service.postage }} class + {% if current_service.has_permission("choose_postage") %} +
+

Postage

: + {{ template_postage or current_service.postage }} class +
{% endif %} -
{% endif %} {% else %} {% if current_user.has_permissions('send_messages', restrict_admin_usage=True) %} diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index d05edb241..786d9dfbc 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -403,9 +403,13 @@ def test_user_with_only_send_and_view_sees_letter_page( @pytest.mark.parametrize("permissions,template_postage,expected_result", [ - (["choose_postage", "letter"], "first", "first"), - (["choose_postage", "letter"], None, "second"), - (["letter"], "first", "second"), + (["choose_postage", "letter"], "first", "Postage: first class"), + (["choose_postage", "letter"], "second", "Postage: second class"), + (["choose_postage", "letter"], None, "Postage: second class"), + pytest.param( + ["letter"], None, "Postage: second class", + marks=pytest.mark.xfail(raises=AttributeError) + ), ]) def test_view_letter_template_displays_postage_dynamically_based_on_service_permissions_and_template_postage( client_request, @@ -431,7 +435,7 @@ def test_view_letter_template_displays_postage_dynamically_based_on_service_perm template_id=fake_uuid, ) - assert "Postage: {} class".format(expected_result) in page.text + assert normalize_spaces(page.select_one('#postage').text) == expected_result def test_view_non_letter_template_does_not_display_postage(