From a4e2a40134c721f75a1de02b0228a19c3382d008 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Fri, 1 Dec 2017 17:10:25 +0000 Subject: [PATCH] update dao tests to pass in free sms fragment limit, remove command --- app/commands.py | 26 --------------------- app/schemas.py | 1 - tests/app/dao/test_services_dao.py | 36 +++++++++++++++++------------- tests/app/service/test_rest.py | 5 +++-- 4 files changed, 23 insertions(+), 45 deletions(-) diff --git a/app/commands.py b/app/commands.py index 4b8f2b37f..ee92f4c2b 100644 --- a/app/commands.py +++ b/app/commands.py @@ -335,32 +335,6 @@ def populate_service_letter_contact(): print("Populated letter contacts for {} services".format(result.rowcount)) -@notify_command() -def populate_service_and_service_history_free_sms_fragment_limit(): - """ - DEPRECATED. Set services to have 250k sms limit. - """ - services_to_update = """ - UPDATE services - SET free_sms_fragment_limit = 250000 - WHERE free_sms_fragment_limit IS NULL - """ - - services_history_to_update = """ - UPDATE services_history - SET free_sms_fragment_limit = 250000 - WHERE free_sms_fragment_limit IS NULL - """ - - services_result = db.session.execute(services_to_update) - services_history_result = db.session.execute(services_history_to_update) - - db.session.commit() - - print("Populated free sms fragment limits for {} services".format(services_result.rowcount)) - print("Populated free sms fragment limits for {} services history".format(services_history_result.rowcount)) - - @notify_command() def populate_annual_billing(): """ diff --git a/app/schemas.py b/app/schemas.py index 12ffa4da1..2afa6270d 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -290,7 +290,6 @@ class DetailedServiceSchema(BaseSchema): 'letter_contact_block', # new exclude from here 'message_limit', 'email_from', - # 'free_sms_fragment_limit', 'inbound_api', 'dvla_organisation', 'whitelist', diff --git a/tests/app/dao/test_services_dao.py b/tests/app/dao/test_services_dao.py index 2caf092fe..abeb06c32 100644 --- a/tests/app/dao/test_services_dao.py +++ b/tests/app/dao/test_services_dao.py @@ -51,6 +51,7 @@ from app.models import ( Service, ServicePermission, ServicePermissionTypes, + AnnualBilling, BRANDING_GOVUK, DVLA_ORG_HM_GOVERNMENT, KEY_TYPE_NORMAL, @@ -89,10 +90,10 @@ def test_create_service(sample_user): restricted=False, organisation_type='central', created_by=sample_user) - dao_create_service(service, sample_user) + dao_create_service(service, sample_user, 12345) assert Service.query.count() == 1 - service_db = Service.query.first() + service_db = Service.query.one() assert service_db.name == "service_name" assert service_db.id == service.id assert service_db.branding == BRANDING_GOVUK @@ -105,6 +106,9 @@ def test_create_service(sample_user): assert service_db.free_sms_fragment_limit == 250000 assert service_db.organisation_type == 'central' assert service_db.crown is True + annual_billing = AnnualBilling.query.one() + assert annual_billing.service == service_db + assert annual_billing.free_sms_fragment_limit == 12345 def test_cannot_create_two_services_with_same_name(sample_user): @@ -121,8 +125,8 @@ def test_cannot_create_two_services_with_same_name(sample_user): restricted=False, created_by=sample_user) with pytest.raises(IntegrityError) as excinfo: - dao_create_service(service1, sample_user) - dao_create_service(service2, sample_user) + dao_create_service(service1, sample_user, 12345) + dao_create_service(service2, sample_user, 12345) assert 'duplicate key value violates unique constraint "services_name_key"' in str(excinfo.value) @@ -139,8 +143,8 @@ def test_cannot_create_two_services_with_same_email_from(sample_user): restricted=False, created_by=sample_user) with pytest.raises(IntegrityError) as excinfo: - dao_create_service(service1, sample_user) - dao_create_service(service2, sample_user) + dao_create_service(service1, sample_user, 12345) + dao_create_service(service2, sample_user, 12345) assert 'duplicate key value violates unique constraint "services_email_from_key"' in str(excinfo.value) @@ -152,7 +156,7 @@ def test_cannot_create_service_with_no_user(notify_db_session, sample_user): restricted=False, created_by=sample_user) with pytest.raises(FlushError) as excinfo: - dao_create_service(service, None) + dao_create_service(service, None, 12345) assert "Can't flush None value found in collection Service.users" in str(excinfo.value) @@ -162,7 +166,7 @@ def test_should_add_user_to_service(sample_user): message_limit=1000, restricted=False, created_by=sample_user) - dao_create_service(service, sample_user) + dao_create_service(service, sample_user, 12345) assert sample_user in Service.query.first().users new_user = User( name='Test User', @@ -181,7 +185,7 @@ def test_should_remove_user_from_service(sample_user): message_limit=1000, restricted=False, created_by=sample_user) - dao_create_service(service, sample_user) + dao_create_service(service, sample_user, 12345) new_user = User( name='Test User', email_address='new_user@digital.cabinet-office.gov.uk', @@ -333,7 +337,7 @@ def test_create_service_creates_a_history_record_with_current_data(sample_user): message_limit=1000, restricted=False, created_by=sample_user) - dao_create_service(service, sample_user) + dao_create_service(service, sample_user, 12345) assert Service.query.count() == 1 assert Service.get_history_model().query.count() == 1 @@ -360,7 +364,7 @@ def test_update_service_creates_a_history_record_with_current_data(sample_user): message_limit=1000, restricted=False, created_by=sample_user) - dao_create_service(service, sample_user) + dao_create_service(service, sample_user, 12345) assert Service.query.count() == 1 assert Service.query.first().version == 1 @@ -388,7 +392,7 @@ def test_update_service_permission_creates_a_history_record_with_current_data(sa message_limit=1000, restricted=False, created_by=sample_user) - dao_create_service(service, sample_user) + dao_create_service(service, sample_user, 12345) service.permissions.append(ServicePermission(service_id=service.id, permission='letter')) dao_update_service(service) @@ -431,7 +435,7 @@ def test_create_service_and_history_is_transactional(sample_user): created_by=sample_user) with pytest.raises(IntegrityError) as excinfo: - dao_create_service(service, sample_user) + dao_create_service(service, sample_user, 12345) assert 'column "name" violates not-null constraint' in str(excinfo.value) assert Service.query.count() == 0 @@ -480,7 +484,7 @@ def test_add_existing_user_to_another_service_doesnot_change_old_permissions(sam restricted=False, created_by=sample_user) - dao_create_service(service_one, sample_user) + dao_create_service(service_one, sample_user, 12345) assert sample_user.id == service_one.users[0].id test_user_permissions = Permission.query.filter_by(service=service_one, user=sample_user).all() assert len(test_user_permissions) == 8 @@ -497,7 +501,7 @@ def test_add_existing_user_to_another_service_doesnot_change_old_permissions(sam message_limit=1000, restricted=False, created_by=other_user) - dao_create_service(service_two, other_user) + dao_create_service(service_two, other_user, 12345) assert other_user.id == service_two.users[0].id other_user_permissions = Permission.query.filter_by(service=service_two, user=other_user).all() @@ -526,7 +530,7 @@ def test_fetch_stats_filters_on_service(sample_notification): email_from="hello", restricted=False, message_limit=1000) - dao_create_service(service_two, sample_notification.service.created_by) + dao_create_service(service_two, sample_notification.service.created_by, 12345) stats = dao_fetch_stats_for_service(service_two.id) assert len(stats) == 0 diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index 90f82da5d..765e64e2f 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -1432,12 +1432,13 @@ def test_set_sms_prefixing_for_service_cant_be_none( admin_request, sample_service, ): - admin_request.post( + resp = admin_request.post( 'service.update_service', service_id=sample_service.id, _data={'prefix_sms': None}, - _expected_status=500, + _expected_status=400, ) + assert resp['message'] == {'prefix_sms': ['Field may not be null.']} @pytest.mark.parametrize('today_only,stats', [