From 4cae9243796fa7b492493dd3a10cd01ace15f947 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 1 Mar 2019 12:22:57 +0000 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20prefil=20answer=20to=20research?= =?UTF-8?q?=20consent=20question?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We were treating `None` (not answered) the same as `False` (previously answered no). --- app/main/views/service_settings.py | 5 ++++- tests/app/main/views/test_service_settings.py | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index 0852a3419..834bcea64 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -151,7 +151,10 @@ def estimate_usage(service_id): volume_email=current_service.volume_email, volume_sms=current_service.volume_sms, volume_letter=current_service.volume_letter, - consent_to_research='yes' if current_service.consent_to_research else 'no', + consent_to_research={ + True: 'yes', + False: 'no', + }.get(current_service.consent_to_research), ) if form.validate_on_submit(): diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index 681d0c379..de723e0cb 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -826,6 +826,11 @@ def test_non_gov_user_is_told_they_cant_go_live( assert page.select('button') == [] +@pytest.mark.parametrize('consent_to_research, displayed_consent', ( + (None, None), + (True, 'yes'), + (False, 'no'), +)) @pytest.mark.parametrize('volumes, displayed_volumes', ( ( (('email', None), ('sms', None), ('letter', None)), @@ -841,6 +846,8 @@ def test_should_show_estimate_volumes( client_request, volumes, displayed_volumes, + consent_to_research, + displayed_consent, ): for channel, volume in volumes: mocker.patch( @@ -849,6 +856,12 @@ def test_should_show_estimate_volumes( new_callable=PropertyMock, return_value=volume, ) + mocker.patch( + 'app.models.service.Service.consent_to_research', + create=True, + new_callable=PropertyMock, + return_value=consent_to_research, + ) page = client_request.get( 'main.estimate_usage', service_id=SERVICE_ONE_ID ) @@ -875,6 +888,14 @@ def test_should_show_estimate_volumes( ) == label assert page.select_one('#volume_{}'.format(channel))['value'] == value + assert len(page.select('input[type=radio]')) == 2 + + if displayed_consent is None: + assert len(page.select('input[checked]')) == 0 + else: + assert len(page.select('input[checked]')) == 1 + assert page.select_one('input[checked]')['value'] == displayed_consent + @pytest.mark.parametrize('consent_to_research, expected_persisted_consent_to_research', ( ('yes', True),