diff --git a/app/__init__.py b/app/__init__.py index a21d26636..6b0008888 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -18,10 +18,9 @@ feature_flags = flask_featureflags.FeatureFlag() login_manager = LoginManager() -service_content = ContentLoader( - "app/content/frameworks/g-cloud-6/manifests/edit_service_as_admin.yml", - "app/content/frameworks/g-cloud-6/questions/services/" -) +content_loader = ContentLoader('app/content') +content_loader.load_manifest('g-cloud-6', 'services', 'edit_service_as_admin') +content_loader.load_manifest('g-cloud-7', 'declaration', 'declaration') from app.main.helpers.service import parse_document_upload_time diff --git a/app/assets/scss/application.scss b/app/assets/scss/application.scss index c78e8be67..8cfa4c7b7 100644 --- a/app/assets/scss/application.scss +++ b/app/assets/scss/application.scss @@ -37,6 +37,7 @@ $path: "/admin/static/images/"; @import "views/view_audits"; @import "_diff.scss"; @import "views/statistics"; +@import "views/view_declaration"; // Graphs @import "_c3"; diff --git a/app/assets/scss/views/_view_declaration.scss b/app/assets/scss/views/_view_declaration.scss new file mode 100644 index 000000000..3ee6b4436 --- /dev/null +++ b/app/assets/scss/views/_view_declaration.scss @@ -0,0 +1,3 @@ +.declaration-summary thead .summary-item-field-heading-first { + width: 60%; +} diff --git a/app/main/views/services.py b/app/main/views/services.py index 5655bc0bc..067c57966 100644 --- a/app/main/views/services.py +++ b/app/main/views/services.py @@ -11,7 +11,7 @@ from ... import data_api_client -from ... import service_content +from ... import content_loader from .. import main from . import get_template_data @@ -51,7 +51,7 @@ def view(service_id): return redirect(url_for('.index')) service_data['priceString'] = format_service_price(service_data) - content = service_content.get_builder().filter(service_data) + content = content_loader.get_builder('g-cloud-6', 'edit_service_as_admin').filter(service_data) template_data = get_template_data( sections=content, @@ -101,7 +101,7 @@ def update_service_status(service_id): def edit(service_id, section): service_data = data_api_client.get_service(service_id)['services'] - content = service_content.get_builder().filter(service_data) + content = content_loader.get_builder('g-cloud-6', 'edit_service_as_admin').filter(service_data) template_data = get_template_data( section=content.get_section(section), @@ -153,7 +153,7 @@ def validate_archived_services(old_archived_service, new_archived_service): except (HTTPError, KeyError, ValueError): return abort(404) - content = service_content.get_builder().filter(service_data) + content = content_loader.get_builder('g-cloud-6', 'edit_service_as_admin').filter(service_data) # It's possible to have an empty array if none of the lines were changed. # TODO This possibility isn't actually handled. @@ -188,7 +188,7 @@ def update(service_id, section_id): abort(404) service = service['services'] - content = service_content.get_builder().filter(service) + content = content_loader.get_builder('g-cloud-6', 'edit_service_as_admin').filter(service) section = content.get_section(section_id) if section is None or not section.editable: abort(404) diff --git a/app/main/views/suppliers.py b/app/main/views/suppliers.py index 48f184e99..acee1a960 100644 --- a/app/main/views/suppliers.py +++ b/app/main/views/suppliers.py @@ -3,18 +3,17 @@ from .. import main from . import get_template_data -from ... import data_api_client +from ... import data_api_client, content_loader from ..forms import EmailAddressForm from ..auth import role_required -from dmutils.apiclient.errors import HTTPError +from dmutils.apiclient.errors import HTTPError, APIError from dmutils.audit import AuditTypes -from dmutils.email import send_email, \ - generate_token, MandrillException +from dmutils.email import send_email, generate_token, MandrillException @main.route('/suppliers', methods=['GET']) @login_required -@role_required('admin', 'admin-ccs-category') +@role_required('admin', 'admin-ccs-category', 'admin-ccs-sourcing') def find_suppliers(): suppliers = data_api_client.find_suppliers(prefix=request.args.get("supplier_name_prefix")) @@ -39,6 +38,89 @@ def edit_supplier_name(supplier_id): ) +@main.route('/suppliers//edit/declarations/', methods=['GET']) +@login_required +@role_required('admin-ccs-sourcing') +def view_supplier_declaration(supplier_id, framework_slug): + supplier = data_api_client.get_supplier(supplier_id)['suppliers'] + framework = data_api_client.get_framework(framework_slug)['frameworks'] + try: + declaration = data_api_client.get_supplier_declaration(supplier_id, framework_slug)['declaration'] + except APIError as e: + if e.status_code != 404: + raise + declaration = {} + + content = content_loader.get_builder(framework_slug, 'declaration').filter(declaration) + + return render_template( + "suppliers/view_declaration.html", + supplier=supplier, + framework=framework, + declaration=declaration, + content=content, + **get_template_data()) + + +@main.route( + '/suppliers//edit/declarations//', + methods=['GET']) +@login_required +@role_required('admin-ccs-sourcing') +def edit_supplier_declaration_section(supplier_id, framework_slug, section_id): + supplier = data_api_client.get_supplier(supplier_id)['suppliers'] + framework = data_api_client.get_framework(framework_slug)['frameworks'] + try: + declaration = data_api_client.get_supplier_declaration(supplier_id, framework_slug)['declaration'] + except APIError as e: + if e.status_code != 404: + raise + declaration = {} + + content = content_loader.get_builder(framework_slug, 'declaration').filter(declaration) + section = content.get_section(section_id) + if section is None: + abort(404) + + return render_template( + "suppliers/edit_declaration.html", + supplier=supplier, + framework=framework, + declaration=declaration, + section=section, + **get_template_data()) + + +@main.route( + '/suppliers//edit/declarations//', + methods=['POST']) +def update_supplier_declaration_section(supplier_id, framework_slug, section_id): + supplier = data_api_client.get_supplier(supplier_id)['suppliers'] + framework = data_api_client.get_framework(framework_slug)['frameworks'] + try: + declaration = data_api_client.get_supplier_declaration(supplier_id, framework_slug)['declaration'] + except APIError as e: + if e.status_code != 404: + raise + declaration = {} + + content = content_loader.get_builder(framework_slug, 'declaration').filter(declaration) + section = content.get_section(section_id) + if section is None: + abort(404) + + posted_data = section.get_data(request.form) + + if section.has_changes_to_save(declaration, posted_data): + declaration.update(posted_data) + data_api_client.set_supplier_declaration( + supplier_id, framework_slug, declaration, + current_user.email_address) + + return redirect(url_for('.view_supplier_declaration', + supplier_id=supplier_id, framework_slug=framework_slug)) + + @main.route('/suppliers//edit/name', methods=['POST']) @login_required @role_required('admin') diff --git a/app/templates/index.html b/app/templates/index.html index d1e3af32a..7152c65ec 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -32,9 +32,10 @@ {% include "toolkit/page-heading.html" %} {% endwith %} - {% if current_user.has_role('admin') or current_user.has_role('admin-ccs-category') %} + {% if current_user.has_any_role('admin', 'admin-ccs-category', 'admin-ccs-sourcing') %}
+ {% if current_user.has_any_role('admin', 'admin-ccs-category') %}

@@ -61,6 +62,7 @@

+ {% endif %}
@@ -71,6 +73,8 @@
+ {% if current_user.has_any_role('admin') %} +

@@ -79,6 +83,8 @@

+ + {% endif %}
{% endif %} diff --git a/app/templates/suppliers/edit_declaration.html b/app/templates/suppliers/edit_declaration.html new file mode 100644 index 000000000..adbc99e0c --- /dev/null +++ b/app/templates/suppliers/edit_declaration.html @@ -0,0 +1,46 @@ +{% import 'macros/toolkit_forms.html' as forms %} + +{% extends "_base_page.html" %} + +{% block page_title %} + Change {{ framework.name }} declaration +{% endblock %} + +{% block content %} +
+
+
+ {% + with + context = supplier.name, + heading = section.name, + smaller = True + %} + {% include "toolkit/page-heading.html" %} + {% endwith %} +
+
+ +
+
+
+
+ {% for question in section.questions %} + {{ forms[question.type](question, declaration, {}) }} + {% endfor %} + {% + with + type = "save", + label = "Save and return to summary" + %} + {% include "toolkit/button.html" %} + {% endwith %} +

+ Return without saving +

+
+
+
+ + +{% endblock %} diff --git a/app/templates/suppliers/view_declaration.html b/app/templates/suppliers/view_declaration.html new file mode 100644 index 000000000..697b76463 --- /dev/null +++ b/app/templates/suppliers/view_declaration.html @@ -0,0 +1,44 @@ +{% import "toolkit/summary-table.html" as summary %} + +{% extends "_base_page.html" %} + +{% block page_title %} + Change {{ framework.name }} declaration +{% endblock %} + +{% block content %} +
+
+
+ {% + with + context = supplier.name, + heading = framework.name + " declaration", + smaller = True + %} + {% include "toolkit/page-heading.html" %} + {% endwith %} +
+
+ + {% for section in content %} + {{ summary.heading(section.name) }} + {{ summary.top_link("Edit", url_for('.edit_supplier_declaration_section', supplier_id=supplier.id, framework_slug=framework.slug, section_id=section.id)) }} + {% call(item) summary.list_table( + section.questions, + caption="Declaration", + empty_message="This supplier not made a declaration", + field_headings=[ + 'Declaration question', + 'Declaration answer' + ] + ) %} + {% call summary.row() %} + {{ summary.field_name(item.question) }} + {{ summary[item.type](declaration[item.id]) }} + {% endcall %} + {% endcall %} + {% endfor %} +
+ +{% endblock %} diff --git a/app/templates/view_suppliers.html b/app/templates/view_suppliers.html index 2c2a55e0d..fa3098c35 100644 --- a/app/templates/view_suppliers.html +++ b/app/templates/view_suppliers.html @@ -23,20 +23,31 @@ {% endwith %}
- {% call(item) summary.list_table( - suppliers, - caption="Suppliers", - empty_message="No suppliers were found", - field_headings=[ + {% if current_user.has_role("admin") %} + {% set field_headings = [ "Name", - summary.hidden_field_heading("Edit name"), + summary.hidden_field_heading("Change name"), summary.hidden_field_heading("Users"), summary.hidden_field_heading("Services"), - ] if current_user.has_role('admin') else [ + ] %} + {% elif current_user.has_role("admin-ccs-sourcing") %} + {% set field_headings = [ + "Name", + summary.hidden_field_heading("Change declarations"), + ] %} + {% else %} + {% set field_headings = [ "Name", summary.hidden_field_heading("Users"), summary.hidden_field_heading("Services"), - ], + ] %} + {% endif %} + + {% call(item) summary.list_table( + suppliers, + caption="Suppliers", + empty_message="No suppliers were found", + field_headings=field_headings, field_headings_visible=True) %} {% call summary.row() %} @@ -44,8 +55,13 @@ {% if current_user.has_role('admin') %} {{ summary.edit_link("Change name", url_for(".edit_supplier_name", supplier_id=item.id)) }} {% endif %} - {{ summary.edit_link("Users", url_for(".find_supplier_users", supplier_id=item.id)) }} - {{ summary.edit_link("Services", url_for(".find_supplier_services", supplier_id=item.id)) }} + {% if current_user.has_role('admin-ccs-sourcing') %} + {{ summary.edit_link("G-Cloud 7 declaration", url_for(".view_supplier_declaration", supplier_id=item.id, framework_slug="g-cloud-7")) }} + {% endif %} + {% if current_user.has_any_role('admin', 'admin-ccs-category') %} + {{ summary.edit_link("Users", url_for(".find_supplier_users", supplier_id=item.id)) }} + {{ summary.edit_link("Services", url_for(".find_supplier_services", supplier_id=item.id)) }} + {% endif %} {% endcall %} {% endcall %}
diff --git a/example_responses/declaration_response.json b/example_responses/declaration_response.json new file mode 100644 index 000000000..cb2ea1ef8 --- /dev/null +++ b/example_responses/declaration_response.json @@ -0,0 +1,17 @@ +{ + "declaration": { + "PR1": true, + "PR2": false, + "SQC2": true, + "PR5": false, + "PR3": true, + "PR4": false, + "SQ1-3": [], + "SQA2": false, + "SQA3": true, + "SQA4": false, + "SQA5": true, + "AQA3": false, + "SQC3": ["race", "sexual orientation"] + } +} diff --git a/example_responses/framework_response.json b/example_responses/framework_response.json new file mode 100644 index 000000000..70fe109c2 --- /dev/null +++ b/example_responses/framework_response.json @@ -0,0 +1,6 @@ +{ + "frameworks": { + "slug": "g-cloud-7", + "name": "G-Cloud 7" + } +} diff --git a/requirements.txt b/requirements.txt index 0bf58852b..ad11db300 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,7 +10,7 @@ six==1.9.0 boto==2.36.0 markdown==2.6.2 -git+https://github.com/alphagov/digitalmarketplace-utils.git@8.6.0#egg=digitalmarketplace-utils==8.6.0 +git+https://github.com/alphagov/digitalmarketplace-utils.git@10.0.0#egg=digitalmarketplace-utils==10.0.0 # Required for SNI to work in requests pyOpenSSL==0.14 diff --git a/tests/app/helpers.py b/tests/app/helpers.py index 95ff61cec..948ffb890 100644 --- a/tests/app/helpers.py +++ b/tests/app/helpers.py @@ -24,19 +24,9 @@ def setUp(self): ) self._default_suffix_patch.start() - self._user_callback = login_manager.user_callback - login_manager.user_loader(self.user_loader) - - def user_loader(self, user_id): - if user_id: - return User( - user_id, 'test@example.com', None, None, False, True, 'tester', 'admin' - ) - def tearDown(self): self._s3_patch.stop() self._default_suffix_patch.stop() - login_manager.user_loader(self._user_callback) def load_example_listing(self, name): file_path = os.path.join("example_responses", "{}.json".format(name)) @@ -64,8 +54,11 @@ def status_code(self): class LoggedInApplicationTest(BaseApplicationTest): + user_role = 'admin' + def setUp(self): super(LoggedInApplicationTest, self).setUp() + patch_config = { 'authenticate_user.return_value': { 'users': { @@ -89,8 +82,18 @@ def setUp(self): 'password': '1234567890' }) + self._user_callback = login_manager.user_callback + login_manager.user_loader(self.user_loader) + + def user_loader(self, user_id): + if user_id: + return User( + user_id, 'test@example.com', None, None, False, True, 'tester', self.user_role + ) + def tearDown(self): self._data_api_client.stop() + login_manager.user_loader(self._user_callback) def _replace_whitespace(self, string, replacement_substring=""): # Replace all runs of whitespace with replacement_substring diff --git a/tests/app/main/views/test_login.py b/tests/app/main/views/test_login.py index f69806a68..940163bb7 100644 --- a/tests/app/main/views/test_login.py +++ b/tests/app/main/views/test_login.py @@ -36,9 +36,11 @@ def test_should_show_login_page(self): assert_equal(res.status_code, 200) assert_in("Administrator login", res.get_data(as_text=True)) + @mock.patch('app.data_api_client') @mock.patch('app.main.views.login.data_api_client') - def test_valid_login(self, data_api_client): - data_api_client.authenticate_user.return_value = user_data() + def test_valid_login(self, login_data_api_client, init_data_api_client): + login_data_api_client.authenticate_user.return_value = user_data() + init_data_api_client.get_user.return_value = user_data() res = self.client.post('/admin/login', data={ 'email_address': 'valid@email.com', 'password': '1234567890' @@ -101,9 +103,11 @@ def test_should_have_cookie_on_redirect(self, data_api_client): assert_in('HttpOnly', cookie_parts) assert_in('Path=/admin', cookie_parts) + @mock.patch('app.data_api_client') @mock.patch('app.main.views.login.data_api_client') - def test_should_redirect_to_login_on_logout(self, data_api_client): - data_api_client.authenticate_user.return_value = user_data() + def test_should_redirect_to_login_on_logout(self, login_data_api_client, init_data_api_client): + login_data_api_client.authenticate_user.return_value = user_data() + init_data_api_client.get_user.return_value = user_data() self.client.post('/admin/login', data={ 'email_address': 'valid@example.com', 'password': '1234567890', @@ -112,9 +116,11 @@ def test_should_redirect_to_login_on_logout(self, data_api_client): assert_equal(res.status_code, 302) assert_equal(urlsplit(res.location).path, '/admin/login') + @mock.patch('app.data_api_client') @mock.patch('app.main.views.login.data_api_client') - def test_logout_should_log_user_out(self, data_api_client): - data_api_client.authenticate_user.return_value = user_data() + def test_logout_should_log_user_out(self, login_data_api_client, init_data_api_client): + login_data_api_client.authenticate_user.return_value = user_data() + init_data_api_client.get_user.return_value = user_data() self.client.post('/admin/login', data={ 'email_address': 'valid@example.com', 'password': '1234567890', diff --git a/tests/app/main/views/test_services.py b/tests/app/main/views/test_services.py index 8a9969166..647730f06 100644 --- a/tests/app/main/views/test_services.py +++ b/tests/app/main/views/test_services.py @@ -454,15 +454,15 @@ def test_cannot_get_archived_services_for_nonexistent_service_ids(self): response = self._get_archived_services_response('30', '40') self.assertEqual(404, response.status_code) - @mock.patch('app.main.views.services.service_content') - def test_can_get_archived_services_with_dates_and_diffs(self, service_content): + @mock.patch('app.main.views.services.content_loader') + def test_can_get_archived_services_with_dates_and_diffs(self, content_loader): class TestBuilder(object): @staticmethod def filter(*args): return self.TestContent() - service_content.get_builder.return_value = TestBuilder() + content_loader.get_builder.return_value = TestBuilder() response = self._get_archived_services_response('10', '20') # check title is there @@ -497,14 +497,14 @@ def filter(*args): self.strip_all_whitespace(response.get_data(as_text=True)) ) - @mock.patch('app.main.views.services.service_content') - def test_can_get_archived_services_with_differing_keys(self, service_content): + @mock.patch('app.main.views.services.content_loader') + def test_can_get_archived_services_with_differing_keys(self, content_loader): class TestBuilder(object): @staticmethod def filter(*args): return self.TestContent() - service_content.get_builder.return_value = TestBuilder() + content_loader.get_builder.return_value = TestBuilder() response = self._get_archived_services_response('10', '50') self.assertEqual(200, response.status_code) diff --git a/tests/app/main/views/test_suppliers.py b/tests/app/main/views/test_suppliers.py index a414f9a6d..262cc92ed 100644 --- a/tests/app/main/views/test_suppliers.py +++ b/tests/app/main/views/test_suppliers.py @@ -6,8 +6,9 @@ from io import BytesIO as StringIO import mock from lxml import html +from nose.tools import eq_ from nose.tools import assert_equals -from dmutils.apiclient.errors import HTTPError +from dmutils.apiclient.errors import HTTPError, APIError from dmutils.email import MandrillException from dmutils.audit import AuditTypes from ...helpers import LoggedInApplicationTest, Response @@ -615,3 +616,137 @@ def test_should_be_a_503_if_email_fails(self, data_api_client, send_email): ) self.assertEqual(res.status_code, 503) + + +@mock.patch('app.main.views.suppliers.data_api_client') +class TestViewingASupplierDeclaration(LoggedInApplicationTest): + user_role = 'admin-ccs-sourcing' + + def test_should_not_be_visible_to_admin_users(self, data_api_client): + self.user_role = 'admin' + + response = self.client.get('/admin/suppliers/1234/edit/declarations/g-cloud-7') + + eq_(response.status_code, 403) + + def test_should_404_if_supplier_does_not_exist(self, data_api_client): + data_api_client.get_supplier.side_effect = APIError(Response(404)) + + response = self.client.get('/admin/suppliers/1234/edit/declarations/g-cloud-7') + + eq_(response.status_code, 404) + data_api_client.get_supplier.assert_called_with('1234') + assert not data_api_client.get_framework.called + + def test_should_404_if_framework_does_not_exist(self, data_api_client): + data_api_client.get_supplier.return_value = self.load_example_listing('supplier_response') + data_api_client.get_framework.side_effect = APIError(Response(404)) + + response = self.client.get('/admin/suppliers/1234/edit/declarations/g-cloud-7') + + eq_(response.status_code, 404) + data_api_client.get_supplier.assert_called_with('1234') + data_api_client.get_framework.assert_called_with('g-cloud-7') + + def test_should_not_404_if_declaration_does_not_exist(self, data_api_client): + data_api_client.get_supplier.return_value = self.load_example_listing('supplier_response') + data_api_client.get_framework.return_value = self.load_example_listing('framework_response') + data_api_client.get_supplier_declaration.side_effect = APIError(Response(404)) + + response = self.client.get('/admin/suppliers/1234/edit/declarations/g-cloud-7') + + eq_(response.status_code, 200) + data_api_client.get_supplier.assert_called_with('1234') + data_api_client.get_framework.assert_called_with('g-cloud-7') + data_api_client.get_supplier_declaration.assert_called_with('1234', 'g-cloud-7') + + def test_should_show_declaration(self, data_api_client): + data_api_client.get_supplier.return_value = self.load_example_listing('supplier_response') + data_api_client.get_framework.return_value = self.load_example_listing('framework_response') + data_api_client.get_supplier_declaration.return_value = self.load_example_listing('declaration_response') + + response = self.client.get('/admin/suppliers/1234/edit/declarations/g-cloud-7') + document = html.fromstring(response.get_data(as_text=True)) + + eq_(response.status_code, 200) + data = document.cssselect('.summary-item-row td.summary-item-field') + eq_(data[0].text_content().strip(), "Yes") + + +@mock.patch('app.main.views.suppliers.data_api_client') +class TestEditingASupplierDeclaration(LoggedInApplicationTest): + user_role = 'admin-ccs-sourcing' + + def test_should_not_be_visible_to_admin_users(self, data_api_client): + self.user_role = 'admin' + + response = self.client.get('/admin/suppliers/1234/edit/declarations/g-cloud-7/section') + + eq_(response.status_code, 403) + + def test_should_404_if_supplier_does_not_exist(self, data_api_client): + data_api_client.get_supplier.side_effect = APIError(Response(404)) + + response = self.client.get('/admin/suppliers/1234/edit/declarations/g-cloud-7/g_cloud_7_essentials') + + eq_(response.status_code, 404) + data_api_client.get_supplier.assert_called_with('1234') + assert not data_api_client.get_framework.called + + def test_should_404_if_framework_does_not_exist(self, data_api_client): + data_api_client.get_supplier.return_value = self.load_example_listing('supplier_response') + data_api_client.get_framework.side_effect = APIError(Response(404)) + + response = self.client.get('/admin/suppliers/1234/edit/declarations/g-cloud-7/g_cloud_7_essentials') + + eq_(response.status_code, 404) + data_api_client.get_supplier.assert_called_with('1234') + data_api_client.get_framework.assert_called_with('g-cloud-7') + + def test_should_404_if_section_does_not_exist(self, data_api_client): + data_api_client.get_supplier.return_value = self.load_example_listing('supplier_response') + data_api_client.get_framework.return_value = self.load_example_listing('framework_response') + data_api_client.get_supplier_declaration.side_effect = APIError(Response(404)) + + response = self.client.get('/admin/suppliers/1234/edit/declarations/g-cloud-7/not_a_section') + + eq_(response.status_code, 404) + + def test_should_not_404_if_declaration_does_not_exist(self, data_api_client): + data_api_client.get_supplier.return_value = self.load_example_listing('supplier_response') + data_api_client.get_framework.return_value = self.load_example_listing('framework_response') + data_api_client.get_supplier_declaration.side_effect = APIError(Response(404)) + + response = self.client.get('/admin/suppliers/1234/edit/declarations/g-cloud-7/g_cloud_7_essentials') + + eq_(response.status_code, 200) + data_api_client.get_supplier.assert_called_with('1234') + data_api_client.get_framework.assert_called_with('g-cloud-7') + data_api_client.get_supplier_declaration.assert_called_with('1234', 'g-cloud-7') + + def test_should_prefill_form_with_declaration(self, data_api_client): + data_api_client.get_supplier.return_value = self.load_example_listing('supplier_response') + data_api_client.get_framework.return_value = self.load_example_listing('framework_response') + data_api_client.get_supplier_declaration.return_value = self.load_example_listing('declaration_response') + + response = self.client.get('/admin/suppliers/1234/edit/declarations/g-cloud-7/g_cloud_7_essentials') + document = html.fromstring(response.get_data(as_text=True)) + + eq_(response.status_code, 200) + assert document.cssselect('#input-PR1-yes')[0].checked + assert not document.cssselect('#input-PR1-no')[0].checked + + def test_should_set_declaration(self, data_api_client): + data_api_client.get_supplier.return_value = self.load_example_listing('supplier_response') + data_api_client.get_framework.return_value = self.load_example_listing('framework_response') + data_api_client.get_supplier_declaration.return_value = self.load_example_listing('declaration_response') + + response = self.client.post( + '/admin/suppliers/1234/edit/declarations/g-cloud-7/g_cloud_7_essentials', + data={'PR1': 'false'}) + + declaration = self.load_example_listing('declaration_response')['declaration'] + declaration['PR1'] = False + + data_api_client.set_supplier_declaration.assert_called_with( + '1234', 'g-cloud-7', declaration, 'test@example.com')