From 8ef581de69b8ee266d94ae7b4bebf50aabb0d29e Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Mon, 11 Feb 2019 18:20:34 +0000 Subject: [PATCH] Remove service.postage and choose_postage permission from the code and tests --- app/dao/templates_dao.py | 1 + tests/app/conftest.py | 6 ++---- tests/app/dao/test_services_dao.py | 27 +-------------------------- tests/app/dao/test_templates_dao.py | 10 ++++++++-- tests/app/db.py | 4 +--- tests/app/service/test_rest.py | 1 - 6 files changed, 13 insertions(+), 36 deletions(-) diff --git a/app/dao/templates_dao.py b/app/dao/templates_dao.py index 66cbe865a..7861e20e1 100644 --- a/app/dao/templates_dao.py +++ b/app/dao/templates_dao.py @@ -64,6 +64,7 @@ def dao_update_template_reply_to(template_id, reply_to): "content": template.content, "service_id": template.service_id, "subject": template.subject, + "postage": template.postage, "created_by_id": template.created_by_id, "version": template.version, "archived": template.archived, diff --git a/tests/app/conftest.py b/tests/app/conftest.py index b3c2627a8..a48e8d673 100644 --- a/tests/app/conftest.py +++ b/tests/app/conftest.py @@ -163,8 +163,7 @@ def sample_service( limit=1000, email_from=None, permissions=None, - research_mode=None, - postage="second", + research_mode=None ): if user is None: user = create_user() @@ -176,8 +175,7 @@ def sample_service( 'message_limit': limit, 'restricted': restricted, 'email_from': email_from, - 'created_by': user, - "postage": postage, + 'created_by': user } service = Service.query.filter_by(name=service_name).first() if not service: diff --git a/tests/app/dao/test_services_dao.py b/tests/app/dao/test_services_dao.py index d17b91529..90eb50086 100644 --- a/tests/app/dao/test_services_dao.py +++ b/tests/app/dao/test_services_dao.py @@ -3,7 +3,7 @@ from datetime import datetime import pytest from freezegun import freeze_time -from sqlalchemy.exc import IntegrityError, SQLAlchemyError +from sqlalchemy.exc import IntegrityError from sqlalchemy.orm.exc import FlushError, NoResultFound from app import db @@ -95,7 +95,6 @@ def test_create_service(notify_db_session): assert service_db.email_from == 'email_from' assert service_db.research_mode is False assert service_db.prefix_sms is True - assert service_db.postage == 'second' assert service.active is True assert user in service_db.users assert service_db.organisation_type == 'central' @@ -380,12 +379,10 @@ def test_create_service_creates_a_history_record_with_current_data(notify_db_ses assert service_from_db.name == service_history.name assert service_from_db.version == 1 assert service_from_db.version == service_history.version - assert service_from_db.postage == 'second' assert user.id == service_history.created_by_id assert service_from_db.created_by.id == service_history.created_by_id assert service_from_db.dvla_organisation_id == DVLA_ORG_HM_GOVERNMENT assert service_history.dvla_organisation_id == DVLA_ORG_HM_GOVERNMENT - assert service_history.postage == 'second' def test_update_service_creates_a_history_record_with_current_data(notify_db_session): @@ -463,28 +460,6 @@ def test_update_service_permission_creates_a_history_record_with_current_data(no assert Service.get_history_model().query.filter_by(name='service_name').all()[2].version == 3 -def test_service_postage_constraint_on_create(notify_db_session): - user = create_user() - assert Service.query.count() == 0 - assert Service.get_history_model().query.count() == 0 - service = Service(name="service_name", - email_from="email_from", - message_limit=1000, - restricted=False, - created_by=user, - postage='third') - with pytest.raises(expected_exception=SQLAlchemyError): - dao_create_service(service, user) - - -def test_service_postage_constraint_on_update(notify_db_session): - create_service() - service_from_db = Service.query.first() - service_from_db.postage = 'third' - with pytest.raises(expected_exception=SQLAlchemyError): - dao_update_service(service_from_db) - - def test_create_service_and_history_is_transactional(notify_db_session): user = create_user() assert Service.query.count() == 0 diff --git a/tests/app/dao/test_templates_dao.py b/tests/app/dao/test_templates_dao.py index f585e2b5d..3f528e1fd 100644 --- a/tests/app/dao/test_templates_dao.py +++ b/tests/app/dao/test_templates_dao.py @@ -37,6 +37,8 @@ def test_create_template(sample_service, sample_user, template_type, subject): 'service': sample_service, 'created_by': sample_user } + if template_type == 'letter': + data['postage'] = 'second' if subject: data.update({'subject': subject}) template = Template(**data) @@ -69,6 +71,7 @@ def test_create_template_with_reply_to(sample_service, sample_user): 'service': sample_service, 'created_by': sample_user, 'reply_to': letter_contact.id, + 'postage': 'second' } template = Template(**data) dao_create_template(template) @@ -132,6 +135,7 @@ def test_dao_update_template_reply_to_none_to_some(sample_service, sample_user): 'content': "Template content", 'service': sample_service, 'created_by': sample_user, + 'postage': 'second' } template = Template(**data) dao_create_template(template) @@ -162,7 +166,8 @@ def test_dao_update_template_reply_to_some_to_some(sample_service, sample_user): 'content': "Template content", 'service': sample_service, 'created_by': sample_user, - 'service_letter_contact_id': letter_contact.id + 'service_letter_contact_id': letter_contact.id, + 'postage': 'second', } template = Template(**data) dao_create_template(template) @@ -186,7 +191,8 @@ def test_dao_update_template_reply_to_some_to_none(sample_service, sample_user): 'content': "Template content", 'service': sample_service, 'created_by': sample_user, - 'service_letter_contact_id': letter_contact.id + 'service_letter_contact_id': letter_contact.id, + 'postage': 'second' } template = Template(**data) dao_create_template(template) diff --git a/tests/app/db.py b/tests/app/db.py index 7932ffb87..2aa6e3ae1 100644 --- a/tests/app/db.py +++ b/tests/app/db.py @@ -83,7 +83,6 @@ def create_service( prefix_sms=True, message_limit=1000, organisation_type='central', - postage='second', check_if_service_exists=False ): if check_if_service_exists: @@ -96,8 +95,7 @@ def create_service( email_from=email_from if email_from else service_name.lower().replace(' ', '.'), created_by=user if user else create_user(email='{}@digital.cabinet-office.gov.uk'.format(uuid.uuid4())), prefix_sms=prefix_sms, - organisation_type=organisation_type, - postage=postage + organisation_type=organisation_type ) dao_create_service(service, service.created_by, service_id, service_permissions=service_permissions) diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index a1a0622ee..c99e9df64 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -141,7 +141,6 @@ def test_get_service_by_id(admin_request, sample_service): assert 'branding' not in json_resp['data'] assert json_resp['data']['dvla_organisation'] == '001' assert json_resp['data']['prefix_sms'] is True - assert json_resp['data']['postage'] == 'second' assert json_resp['data']['letter_logo_filename'] == 'hm-government'