M src/groceries/web/api.py => src/groceries/web/api.py +1 -1
@@ 42,7 42,7 @@ def create_item():
try:
item = Item(**request.json)
except TypeError:
- abort(400, description="Missing fields in request")
+ abort(400, description="Invalid fields in request")
grocery_list = GroceryList(current_app.config["BACKEND"])
M tests/test_rest_server.py => tests/test_rest_server.py +11 -1
@@ 99,7 99,17 @@ def test_create_item_with_missing_fields(client):
response = client.post("/api/items/", json={"name": "turkey"})
assert response.status_code == 400
assert response.get_json() == {
- "error": "400 Bad Request: Missing fields in request"
+ "error": "400 Bad Request: Invalid fields in request"
+ }
+
+
+def test_create_item_with_extra_fields(client):
+ response = client.post(
+ "/api/items/", json={"name": "turkey", "origin": "new world"}
+ )
+ assert response.status_code == 400
+ assert response.get_json() == {
+ "error": "400 Bad Request: Invalid fields in request"
}