diff --git a/app/models.py b/app/models.py index 320aa33de..93401de98 100644 --- a/app/models.py +++ b/app/models.py @@ -61,6 +61,8 @@ DELIVERY_STATUS_CALLBACK_TYPE = 'delivery_status' COMPLAINT_CALLBACK_TYPE = 'complaint' SERVICE_CALLBACK_TYPES = [DELIVERY_STATUS_CALLBACK_TYPE, COMPLAINT_CALLBACK_TYPE] +ORGANISATION_TYPES = ['central', 'local', 'nhs'] + def filter_null_value_fields(obj): return dict( diff --git a/app/organisation/organisation_schema.py b/app/organisation/organisation_schema.py index 4b560fecc..44018385e 100644 --- a/app/organisation/organisation_schema.py +++ b/app/organisation/organisation_schema.py @@ -1,4 +1,4 @@ -from app.models import INVITED_USER_STATUS_TYPES +from app.models import INVITED_USER_STATUS_TYPES, ORGANISATION_TYPES from app.schema_validation.definitions import uuid post_create_organisation_schema = { @@ -7,9 +7,11 @@ post_create_organisation_schema = { "type": "object", "properties": { "name": {"type": "string"}, - "active": {"type": ["boolean", "null"]} + "active": {"type": ["boolean", "null"]}, + "crown": {"type": "boolean"}, + "organisation_type": {"enum": ORGANISATION_TYPES}, }, - "required": ["name"] + "required": ["name", "crown", "organisation_type"] } post_update_organisation_schema = { @@ -18,7 +20,9 @@ post_update_organisation_schema = { "type": "object", "properties": { "name": {"type": ["string", "null"]}, - "active": {"type": ["boolean", "null"]} + "active": {"type": ["boolean", "null"]}, + "crown": {"type": ["boolean", "null"]}, + "organisation_type": {"enum": ORGANISATION_TYPES}, }, "required": [] } diff --git a/tests/app/organisation/test_rest.py b/tests/app/organisation/test_rest.py index d99670d7a..1c9e156d3 100644 --- a/tests/app/organisation/test_rest.py +++ b/tests/app/organisation/test_rest.py @@ -133,7 +133,9 @@ def test_get_organisation_by_domain( def test_post_create_organisation(admin_request, notify_db_session): data = { 'name': 'test organisation', - 'active': True + 'active': True, + 'crown': False, + 'organisation_type': 'local', } response = admin_request.post( @@ -146,13 +148,18 @@ def test_post_create_organisation(admin_request, notify_db_session): assert data['name'] == response['name'] assert data['active'] == response['active'] + assert data['crown'] == response['crown'] + assert data['organisation_type'] == response['organisation_type'] + assert len(organisation) == 1 def test_post_create_organisation_existing_name_raises_400(admin_request, sample_organisation): data = { 'name': sample_organisation.name, - 'active': True + 'active': True, + 'crown': True, + 'organisation_type': 'central', } response = admin_request.post( @@ -167,11 +174,41 @@ def test_post_create_organisation_existing_name_raises_400(admin_request, sample assert response['message'] == 'Organisation name already exists' -def test_post_create_organisation_with_missing_name_gives_validation_error(admin_request, notify_db_session): - data = { - 'active': False - } - +@pytest.mark.parametrize('data, expected_error', ( + ({ + 'active': False, + 'crown': True, + 'organisation_type': 'central', + }, 'name is a required property'), + ({ + 'active': False, + 'name': 'Service name', + 'organisation_type': 'central', + }, 'crown is a required property'), + ({ + 'active': False, + 'name': 'Service name', + 'crown': True, + }, '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, + 'name': 'Service name', + 'crown': False, + 'organisation_type': 'foo', + }, 'organisation_type foo is not one of [central, local, nhs]'), +)) +def test_post_create_organisation_with_missing_name_gives_validation_error( + admin_request, + notify_db_session, + data, + expected_error, +): response = admin_request.post( 'organisation.create_organisation', _data=data, @@ -180,7 +217,7 @@ def test_post_create_organisation_with_missing_name_gives_validation_error(admin assert len(response['errors']) == 1 assert response['errors'][0]['error'] == 'ValidationError' - assert response['errors'][0]['message'] == 'name is a required property' + assert response['errors'][0]['message'] == expected_error @pytest.mark.parametrize('agreement_signed', ( @@ -203,6 +240,7 @@ def test_post_update_organisation_updates_fields( 'crown': crown, 'agreement_signed_on_behalf_of_name': 'Firstname Lastname', 'agreement_signed_on_behalf_of_email_address': 'test@example.com', + 'organisation_type': 'central', } assert org.agreement_signed is None assert org.crown is None @@ -225,6 +263,7 @@ def test_post_update_organisation_updates_fields( assert organisation[0].domains == [] assert organisation[0].agreement_signed_on_behalf_of_name == 'Firstname Lastname' assert organisation[0].agreement_signed_on_behalf_of_email_address == 'test@example.com' + assert organisation[0].organisation_type == 'central' @pytest.mark.parametrize('domain_list', (