mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-30 19:28:50 -04:00
Set crown if organisation_type is updated on service.
Add some tests. Update the initial values of crown.
This commit is contained in:
@@ -178,7 +178,11 @@ def update_service(service_id):
|
|||||||
service_going_live = fetched_service.restricted and not req_json.get('restricted', True)
|
service_going_live = fetched_service.restricted and not req_json.get('restricted', True)
|
||||||
current_data = dict(service_schema.dump(fetched_service).data.items())
|
current_data = dict(service_schema.dump(fetched_service).data.items())
|
||||||
current_data.update(request.get_json())
|
current_data.update(request.get_json())
|
||||||
|
|
||||||
update_dict = service_schema.load(current_data).data
|
update_dict = service_schema.load(current_data).data
|
||||||
|
org_type = req_json.get('organisation_type', None)
|
||||||
|
if org_type:
|
||||||
|
update_dict.crown = org_type == 'central'
|
||||||
dao_update_service(update_dict)
|
dao_update_service(update_dict)
|
||||||
|
|
||||||
# bridging code between frontend is deployed and data has not been migrated yet. Can only update current year
|
# bridging code between frontend is deployed and data has not been migrated yet. Can only update current year
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ def upgrade():
|
|||||||
update services set crown = True
|
update services set crown = True
|
||||||
where organisation_type = 'central'
|
where organisation_type = 'central'
|
||||||
""")
|
""")
|
||||||
|
op.execute("""
|
||||||
|
update services set crown = True
|
||||||
|
where organisation_type is null
|
||||||
|
""")
|
||||||
op.execute("""
|
op.execute("""
|
||||||
update services set crown = False
|
update services set crown = False
|
||||||
where crown is null
|
where crown is null
|
||||||
@@ -30,6 +34,10 @@ def upgrade():
|
|||||||
update services_history set crown = True
|
update services_history set crown = True
|
||||||
where organisation_type = 'central'
|
where organisation_type = 'central'
|
||||||
""")
|
""")
|
||||||
|
op.execute("""
|
||||||
|
update services_history set crown = True
|
||||||
|
where organisation_type is null
|
||||||
|
""")
|
||||||
op.execute("""
|
op.execute("""
|
||||||
update services_history set crown = False
|
update services_history set crown = False
|
||||||
where crown is null
|
where crown is null
|
||||||
|
|||||||
@@ -97,10 +97,13 @@ def test_create_service(sample_user):
|
|||||||
assert service_db.id == service.id
|
assert service_db.id == service.id
|
||||||
assert service_db.branding == BRANDING_GOVUK
|
assert service_db.branding == BRANDING_GOVUK
|
||||||
assert service_db.dvla_organisation_id == DVLA_ORG_HM_GOVERNMENT
|
assert service_db.dvla_organisation_id == DVLA_ORG_HM_GOVERNMENT
|
||||||
|
assert service_db.email_from == 'email_from'
|
||||||
assert service_db.research_mode is False
|
assert service_db.research_mode is False
|
||||||
assert service_db.prefix_sms is True
|
assert service_db.prefix_sms is True
|
||||||
assert service.active is True
|
assert service.active is True
|
||||||
assert sample_user in service_db.users
|
assert sample_user in service_db.users
|
||||||
|
assert service_db.free_sms_fragment_limit == 250000
|
||||||
|
assert service_db.organisation_type == 'central'
|
||||||
assert service_db.crown is True
|
assert service_db.crown is True
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -536,6 +536,26 @@ def test_update_service_flags(client, sample_service):
|
|||||||
assert set(result['data']['permissions']) == set([LETTER_TYPE, INTERNATIONAL_SMS_TYPE])
|
assert set(result['data']['permissions']) == set([LETTER_TYPE, INTERNATIONAL_SMS_TYPE])
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("org_type, expected",
|
||||||
|
[("central", True),
|
||||||
|
('local', False),
|
||||||
|
("nhs", False)])
|
||||||
|
def test_update_service_sets_crown(client, sample_service, org_type, expected):
|
||||||
|
data = {
|
||||||
|
'organisation_type': org_type,
|
||||||
|
}
|
||||||
|
auth_header = create_authorization_header()
|
||||||
|
|
||||||
|
resp = client.post(
|
||||||
|
'/service/{}'.format(sample_service.id),
|
||||||
|
data=json.dumps(data),
|
||||||
|
headers=[('Content-Type', 'application/json'), auth_header]
|
||||||
|
)
|
||||||
|
result = json.loads(resp.get_data(as_text=True))
|
||||||
|
assert resp.status_code == 200
|
||||||
|
assert result['data']['crown'] is expected
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def service_with_no_permissions(notify_db, notify_db_session):
|
def service_with_no_permissions(notify_db, notify_db_session):
|
||||||
return create_service(service_permissions=[])
|
return create_service(service_permissions=[])
|
||||||
|
|||||||
Reference in New Issue
Block a user