Reraise integrity errors on org name unique contraints as 400

- currently being raised as 500s, but should really be 400s as the request data has the duplicate name
This commit is contained in:
Ken Tsang
2018-02-13 14:47:03 +00:00
parent d80c7d4f65
commit 4576bdd64f
2 changed files with 53 additions and 1 deletions

View File

@@ -53,6 +53,24 @@ def test_post_create_organisation(admin_request, notify_db_session):
assert len(organisation) == 1
def test_post_create_organisation_existing_name_raises_400(admin_request, sample_organisation):
data = {
'name': sample_organisation.name,
'active': True
}
response = admin_request.post(
'organisation.create_organisation',
_data=data,
_expected_status=400
)
organisation = Organisation.query.all()
assert len(organisation) == 1
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
@@ -91,6 +109,24 @@ def test_post_update_organisation_updates_fields(admin_request, notify_db_sessio
assert organisation[0].active == data['active']
def test_post_update_organisation_raises_400_on_existing_org_name(
admin_request, notify_db_session, sample_organisation):
org = create_organisation()
data = {
'name': sample_organisation.name,
'active': False
}
response = admin_request.post(
'organisation.update_organisation',
_data=data,
organisation_id=org.id,
_expected_status=400
)
assert response['message'] == 'Organisation name already exists'
def test_post_update_organisation_gives_404_status_if_org_does_not_exist(admin_request, notify_db_session):
data = {'name': 'new organisation name'}