From f679731af80e30a51821588f4d410d306ca3e374 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 14 Feb 2019 23:57:08 +0000 Subject: [PATCH] Also store consent to research against a service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It makes most sense to collect this at the same time as the estimated volumes. Which means we need to store it somewhere; we can’t put it straight into the ticket. --- app/models.py | 1 + migrations/versions/0260_service_volumes.py | 18 +++++++++------- tests/app/service/test_rest.py | 24 +++++++++++++++++++++ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/app/models.py b/app/models.py index c2c93d015..3d95ab42f 100644 --- a/app/models.py +++ b/app/models.py @@ -364,6 +364,7 @@ class Service(db.Model, Versioned): volume_sms = db.Column(db.Integer(), nullable=True, unique=False) volume_email = db.Column(db.Integer(), nullable=True, unique=False) volume_letter = db.Column(db.Integer(), nullable=True, unique=False) + consent_to_research = db.Column(db.Boolean, nullable=False, default=False) organisation = db.relationship( 'Organisation', diff --git a/migrations/versions/0260_service_volumes.py b/migrations/versions/0260_service_volumes.py index 276901f5f..4b9d68ac6 100644 --- a/migrations/versions/0260_service_volumes.py +++ b/migrations/versions/0260_service_volumes.py @@ -14,17 +14,19 @@ revision = '0260_service_volumes' down_revision = '0259_remove_service_postage' -TABLES_AND_CHANNELS = product( - ('services', 'services_history'), - ('volume_{}'.format(channel) for channel in ('email', 'letter', 'sms')), -) +TABLES = ['services', 'services_history'] +CHANNELS = ['volume_{}'.format(channel) for channel in ('email', 'letter', 'sms')] def upgrade(): - for table, channel in TABLES_AND_CHANNELS: - op.add_column(table, sa.Column(channel, sa.Integer(), nullable=True)) + for table in TABLES: + op.add_column(table, sa.Column('consent_to_research', sa.Boolean(), nullable=False, server_default=sa.false())) + for channel in CHANNELS: + op.add_column(table, sa.Column(channel, sa.Integer(), nullable=True)) def downgrade(): - for table, channel in TABLES_AND_CHANNELS: - op.drop_column(table, channel) + for table in TABLES: + op.drop_column(table, 'consent_to_research') + for channel in CHANNELS: + op.drop_column(table, channel) diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index b4504ab2c..e001317c1 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -644,6 +644,30 @@ def test_update_service_sets_volumes( assert getattr(sample_service, field) == expected_persisted +@pytest.mark.parametrize('value, expected_status, expected_persisted', ( + (True, 200, True), + (False, 200, False), + ('Yes', 400, False), +)) +def test_update_service_sets_research_consent( + admin_request, + sample_service, + value, + expected_status, + expected_persisted, +): + assert sample_service.consent_to_research is False + admin_request.post( + 'service.update_service', + service_id=sample_service.id, + _data={ + 'consent_to_research': value, + }, + _expected_status=expected_status, + ) + assert sample_service.consent_to_research is expected_persisted + + @pytest.fixture(scope='function') def service_with_no_permissions(notify_db, notify_db_session): return create_service(service_permissions=[])