From 17e32fa5f68d145b8bc23c10ce476783d4d533a0 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 13 Feb 2019 14:00:52 +0000 Subject: [PATCH] =?UTF-8?q?Add=20fields=20to=20record=20a=20service?= =?UTF-8?q?=E2=80=99s=20estimated=20volumes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a service go live we ask people for their estimated sending volumes. At the moment we only put this in the ticket, and store it in a spreadsheet. This means that a service can - say they want to go live - say they are sending 100,000 emails per year - not have created any email templates - still see ‘create templates’ as ‘completed’ in the go live checklist If we store this data against the service we can collect it earlier, and then use it to determine automatically what kind of templates the user needs to create before their go live checklist can be considered complete. --- app/models.py | 3 +++ migrations/versions/0260_service_volumes.py | 30 +++++++++++++++++++++ tests/app/service/test_rest.py | 26 ++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 migrations/versions/0260_service_volumes.py diff --git a/app/models.py b/app/models.py index 0760eb750..b099e14c5 100644 --- a/app/models.py +++ b/app/models.py @@ -361,6 +361,9 @@ class Service(db.Model, Versioned): crown = db.Column(db.Boolean, index=False, nullable=False, default=True) rate_limit = db.Column(db.Integer, index=False, nullable=False, default=3000) contact_link = db.Column(db.String(255), nullable=True, unique=False) + volume_sms = db.Column(db.String(255), nullable=True, unique=False) + volume_email = db.Column(db.String(255), nullable=True, unique=False) + volume_letter = db.Column(db.String(255), nullable=True, unique=False) organisation = db.relationship( 'Organisation', diff --git a/migrations/versions/0260_service_volumes.py b/migrations/versions/0260_service_volumes.py new file mode 100644 index 000000000..ad5d43035 --- /dev/null +++ b/migrations/versions/0260_service_volumes.py @@ -0,0 +1,30 @@ +""" + +Revision ID: 0260_service_volumes +Revises: 0259_remove_service_postage +Create Date: 2019-02-13 13:45:00.782500 + +""" +from alembic import op +from itertools import product +import sqlalchemy as sa + + +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')), +) + + +def upgrade(): + for table, channel in TABLES_AND_CHANNELS: + op.add_column(table, sa.Column(channel, sa.String(length=255), nullable=True)) + + +def downgrade(): + for table, channel in TABLES_AND_CHANNELS: + op.drop_column(table, channel) diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index c8aaee67f..8220fc8f7 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -615,6 +615,32 @@ def test_update_service_sets_crown(client, sample_service, org_type, expected): assert result['data']['crown'] is expected +@pytest.mark.parametrize('field', ( + 'volume_email', + 'volume_sms', + 'volume_letter', +)) +@pytest.mark.parametrize('value', ( + 'ABC123', + None, +)) +def test_update_service_sets_volumes( + admin_request, + sample_service, + field, + value, +): + admin_request.post( + 'service.update_service', + service_id=sample_service.id, + _data={ + field: value, + }, + _expected_status=200, + ) + assert getattr(sample_service, field) == value + + @pytest.fixture(scope='function') def service_with_no_permissions(notify_db, notify_db_session): return create_service(service_permissions=[])