Update service type and crown when service is added to organisation

This commit is contained in:
Pea Tyczynska
2019-07-15 14:39:21 +01:00
parent 9dfc550f46
commit 8a3ac8400f
4 changed files with 14 additions and 15 deletions

View File

@@ -8,7 +8,7 @@ post_create_organisation_schema = {
"properties": { "properties": {
"name": {"type": "string"}, "name": {"type": "string"},
"active": {"type": ["boolean", "null"]}, "active": {"type": ["boolean", "null"]},
"crown": {"type": "boolean"}, "crown": {"type": ["boolean", "null"]},
"organisation_type": {"enum": ORGANISATION_TYPES}, "organisation_type": {"enum": ORGANISATION_TYPES},
}, },
"required": ["name", "crown", "organisation_type"] "required": ["name", "crown", "organisation_type"]

View File

@@ -158,19 +158,23 @@ def test_update_organisation_updates_the_service_org_type_if_org_type_is_provide
def test_add_service_to_organisation(sample_service, sample_organisation): def test_add_service_to_organisation(sample_service, sample_organisation):
sample_service.organisation_type = 'local'
sample_organisation.organisation_type = 'central'
assert sample_organisation.services == [] assert sample_organisation.services == []
sample_service.organisation_type = "central"
sample_organisation.organisation_type = "local"
sample_organisation.crown = False
dao_add_service_to_organisation(sample_service, sample_organisation.id) dao_add_service_to_organisation(sample_service, sample_organisation.id)
assert len(sample_organisation.services) == 1 assert len(sample_organisation.services) == 1
assert sample_organisation.services[0].id == sample_service.id assert sample_organisation.services[0].id == sample_service.id
assert sample_organisation.services[0].organisation_type == 'central'
assert sample_service.organisation_type == sample_organisation.organisation_type
assert sample_service.crown == sample_organisation.crown
assert Service.get_history_model().query.filter_by( assert Service.get_history_model().query.filter_by(
id=sample_service.id, id=sample_service.id,
version=2 version=2
).one().organisation_type == 'central' ).one().organisation_type == sample_organisation.organisation_type
def test_add_service_to_multiple_organisation_raises_error(sample_service, sample_organisation): def test_add_service_to_multiple_organisation_raises_error(sample_service, sample_organisation):

View File

@@ -132,11 +132,12 @@ def test_get_organisation_by_domain(
assert response['result'] == 'error' assert response['result'] == 'error'
def test_post_create_organisation(admin_request, notify_db_session): @pytest.mark.parametrize('crown', [True, False, None])
def test_post_create_organisation(admin_request, notify_db_session, crown):
data = { data = {
'name': 'test organisation', 'name': 'test organisation',
'active': True, 'active': True,
'crown': False, 'crown': crown,
'organisation_type': 'local', 'organisation_type': 'local',
} }
@@ -192,20 +193,14 @@ def test_post_create_organisation_existing_name_raises_400(admin_request, sample
'name': 'Service name', 'name': 'Service name',
'crown': True, 'crown': True,
}, 'organisation_type is a required property'), }, 'organisation_type is a required property'),
({
'active': False,
'name': 'Service name',
'crown': None,
'organisation_type': 'central',
}, 'crown None is not of type boolean'),
({ ({
'active': False, 'active': False,
'name': 'Service name', 'name': 'Service name',
'crown': False, 'crown': False,
'organisation_type': 'foo', 'organisation_type': 'foo',
}, 'organisation_type foo is not one of [central, local, nhs]'), }, 'organisation_type foo is not one of [central, local, nhs_central, nhs_local, emergency_services, school_or_college, other]'), # noqa
)) ))
def test_post_create_organisation_with_missing_name_gives_validation_error( def test_post_create_organisation_with_missing_data_gives_validation_error(
admin_request, admin_request,
notify_db_session, notify_db_session,
data, data,