update dao tests to pass in free sms fragment limit, remove command

This commit is contained in:
Leo Hemsted
2017-12-01 17:10:25 +00:00
parent 664187f878
commit a4e2a40134
4 changed files with 23 additions and 45 deletions

View File

@@ -335,32 +335,6 @@ def populate_service_letter_contact():
print("Populated letter contacts for {} services".format(result.rowcount)) 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() @notify_command()
def populate_annual_billing(): def populate_annual_billing():
""" """

View File

@@ -290,7 +290,6 @@ class DetailedServiceSchema(BaseSchema):
'letter_contact_block', # new exclude from here 'letter_contact_block', # new exclude from here
'message_limit', 'message_limit',
'email_from', 'email_from',
# 'free_sms_fragment_limit',
'inbound_api', 'inbound_api',
'dvla_organisation', 'dvla_organisation',
'whitelist', 'whitelist',

View File

@@ -51,6 +51,7 @@ from app.models import (
Service, Service,
ServicePermission, ServicePermission,
ServicePermissionTypes, ServicePermissionTypes,
AnnualBilling,
BRANDING_GOVUK, BRANDING_GOVUK,
DVLA_ORG_HM_GOVERNMENT, DVLA_ORG_HM_GOVERNMENT,
KEY_TYPE_NORMAL, KEY_TYPE_NORMAL,
@@ -89,10 +90,10 @@ def test_create_service(sample_user):
restricted=False, restricted=False,
organisation_type='central', organisation_type='central',
created_by=sample_user) 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.count() == 1
service_db = Service.query.first() service_db = Service.query.one()
assert service_db.name == "service_name" assert service_db.name == "service_name"
assert service_db.id == service.id assert service_db.id == service.id
assert service_db.branding == BRANDING_GOVUK 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.free_sms_fragment_limit == 250000
assert service_db.organisation_type == 'central' assert service_db.organisation_type == 'central'
assert service_db.crown is True 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): 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, restricted=False,
created_by=sample_user) created_by=sample_user)
with pytest.raises(IntegrityError) as excinfo: with pytest.raises(IntegrityError) as excinfo:
dao_create_service(service1, sample_user) dao_create_service(service1, sample_user, 12345)
dao_create_service(service2, sample_user) dao_create_service(service2, sample_user, 12345)
assert 'duplicate key value violates unique constraint "services_name_key"' in str(excinfo.value) 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, restricted=False,
created_by=sample_user) created_by=sample_user)
with pytest.raises(IntegrityError) as excinfo: with pytest.raises(IntegrityError) as excinfo:
dao_create_service(service1, sample_user) dao_create_service(service1, sample_user, 12345)
dao_create_service(service2, sample_user) dao_create_service(service2, sample_user, 12345)
assert 'duplicate key value violates unique constraint "services_email_from_key"' in str(excinfo.value) 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, restricted=False,
created_by=sample_user) created_by=sample_user)
with pytest.raises(FlushError) as excinfo: 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) 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, message_limit=1000,
restricted=False, restricted=False,
created_by=sample_user) 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 assert sample_user in Service.query.first().users
new_user = User( new_user = User(
name='Test User', name='Test User',
@@ -181,7 +185,7 @@ def test_should_remove_user_from_service(sample_user):
message_limit=1000, message_limit=1000,
restricted=False, restricted=False,
created_by=sample_user) created_by=sample_user)
dao_create_service(service, sample_user) dao_create_service(service, sample_user, 12345)
new_user = User( new_user = User(
name='Test User', name='Test User',
email_address='new_user@digital.cabinet-office.gov.uk', 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, message_limit=1000,
restricted=False, restricted=False,
created_by=sample_user) 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.count() == 1
assert Service.get_history_model().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, message_limit=1000,
restricted=False, restricted=False,
created_by=sample_user) 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.count() == 1
assert Service.query.first().version == 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, message_limit=1000,
restricted=False, restricted=False,
created_by=sample_user) 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')) service.permissions.append(ServicePermission(service_id=service.id, permission='letter'))
dao_update_service(service) dao_update_service(service)
@@ -431,7 +435,7 @@ def test_create_service_and_history_is_transactional(sample_user):
created_by=sample_user) created_by=sample_user)
with pytest.raises(IntegrityError) as excinfo: 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 'column "name" violates not-null constraint' in str(excinfo.value)
assert Service.query.count() == 0 assert Service.query.count() == 0
@@ -480,7 +484,7 @@ def test_add_existing_user_to_another_service_doesnot_change_old_permissions(sam
restricted=False, restricted=False,
created_by=sample_user) 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 assert sample_user.id == service_one.users[0].id
test_user_permissions = Permission.query.filter_by(service=service_one, user=sample_user).all() test_user_permissions = Permission.query.filter_by(service=service_one, user=sample_user).all()
assert len(test_user_permissions) == 8 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, message_limit=1000,
restricted=False, restricted=False,
created_by=other_user) 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 assert other_user.id == service_two.users[0].id
other_user_permissions = Permission.query.filter_by(service=service_two, user=other_user).all() 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", email_from="hello",
restricted=False, restricted=False,
message_limit=1000) 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) stats = dao_fetch_stats_for_service(service_two.id)
assert len(stats) == 0 assert len(stats) == 0

View File

@@ -1432,12 +1432,13 @@ def test_set_sms_prefixing_for_service_cant_be_none(
admin_request, admin_request,
sample_service, sample_service,
): ):
admin_request.post( resp = admin_request.post(
'service.update_service', 'service.update_service',
service_id=sample_service.id, service_id=sample_service.id,
_data={'prefix_sms': None}, _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', [ @pytest.mark.parametrize('today_only,stats', [