Merge pull request #3038 from alphagov/add-more-info-when-creating-org

Require more information when creating organisations
This commit is contained in:
Chris Hill-Scott
2019-07-03 14:10:44 +01:00
committed by GitHub
7 changed files with 150 additions and 47 deletions

View File

@@ -1,4 +1,4 @@
from unittest.mock import Mock
from unittest.mock import ANY, Mock
import pytest
from bs4 import BeautifulSoup
@@ -75,24 +75,84 @@ def test_view_organisation_shows_the_correct_organisation(
assert normalize_spaces(page.select_one('h1').text) == 'Usage'
def test_create_new_organisation(
logged_in_platform_admin_client,
def test_page_to_create_new_organisation(
client_request,
platform_admin_user,
mocker,
):
client_request.login(platform_admin_user)
page = client_request.get('.add_organisation')
assert [
(input['type'], input['name'], input['value'])
for input in page.select('input')
] == [
('text', 'name', ''),
('radio', 'organisation_type', 'central'),
('radio', 'organisation_type', 'local'),
('radio', 'organisation_type', 'nhs'),
('radio', 'crown_status', 'crown'),
('radio', 'crown_status', 'non-crown'),
('hidden', 'csrf_token', ANY),
]
def test_create_new_organisation(
client_request,
platform_admin_user,
mocker,
):
mock_create_organisation = mocker.patch(
'app.organisations_client.create_organisation',
return_value=organisation_json(ORGANISATION_ID),
)
client_request.login(platform_admin_user)
client_request.post(
'.add_organisation',
_data={
'name': 'new name',
'organisation_type': 'local',
'crown_status': 'non-crown',
},
_expected_redirect=url_for(
'main.organisation_settings',
org_id=ORGANISATION_ID,
_external=True,
),
)
mock_create_organisation.assert_called_once_with(
name='new name',
organisation_type='local',
crown=False,
agreement_signed=False,
)
def test_create_new_organisation_validates(
client_request,
platform_admin_user,
mocker,
fake_uuid
):
mock_create_organisation = mocker.patch(
'app.organisations_client.create_organisation'
)
org = {'name': 'new name'}
logged_in_platform_admin_client.post(
url_for('.add_organisation'),
content_type='multipart/form-data',
data=org
client_request.login(platform_admin_user)
page = client_request.post(
'.add_organisation',
_expected_status=200,
)
mock_create_organisation.assert_called_once_with(name=org['name'])
assert [
(error['data-error-label'], normalize_spaces(error.text))
for error in page.select('.error-message')
] == [
('name', 'Cant be empty'),
('organisation_type', 'Not a valid choice'),
('crown_status', 'Not a valid choice'),
]
assert mock_create_organisation.called is False
def test_organisation_services_shows_live_services_only(