Skip to content
Snippets Groups Projects
Commit c29671e3 authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Test TypeError in create_generic_model

parent 642a9b8c
No related branches found
No related tags found
No related merge requests found
...@@ -68,7 +68,7 @@ def create_generic_model(model, mandatory_fields=('name',)): ...@@ -68,7 +68,7 @@ def create_generic_model(model, mandatory_fields=('name',)):
instance = model(**data) instance = model(**data)
except TypeError as e: except TypeError as e:
message = str(e).replace('__init__() got an ', '') message = str(e).replace('__init__() got an ', '')
raise utils.CSEntryError(message) raise utils.CSEntryError(message, status_code=422)
except ValueError as e: except ValueError as e:
raise utils.CSEntryError(str(e), status_code=422) raise utils.CSEntryError(str(e), status_code=422)
db.session.add(instance) db.session.add(instance)
......
...@@ -185,6 +185,12 @@ def test_create_generic_model(endpoint, client, user_token): ...@@ -185,6 +185,12 @@ def test_create_generic_model(endpoint, client, user_token):
check_names(response, ('Foo', 'Bar')) check_names(response, ('Foo', 'Bar'))
@pytest.mark.parametrize('endpoint', GENERIC_CREATE_ENDPOINTS)
def test_create_generic_model_invalid_param(endpoint, client, user_token):
response = post(client, f'/api/{endpoint}', data={'name': 'foo', 'hello': 'world'}, token=user_token)
check_response_message(response, "unexpected keyword argument 'hello'", 422)
def test_create_item(client, user_token): def test_create_item(client, user_token):
# check that serial_number is mandatory # check that serial_number is mandatory
response = post(client, '/api/items', data={}, token=user_token) response = post(client, '/api/items', data={}, token=user_token)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment