Skip to content

Instantly share code, notes, and snippets.

@mcreenan
Created February 27, 2015 15:16
Show Gist options
  • Save mcreenan/ce366cbb3c5fea17007e to your computer and use it in GitHub Desktop.
Save mcreenan/ce366cbb3c5fea17007e to your computer and use it in GitHub Desktop.
Eve validation failures
from eve import Eve
app = Eve()
app.run()
DATE_FORMAT = '%Y-%m-%dT%H:%M:%SZ'
RESOURCE_METHODS = ['GET', 'POST', 'DELETE']
ITEM_METHODS = ['GET', 'PATCH', 'DELETE']
# Failure #1:
# With the following payload:
# {"location": {
# "_id": "test" },
# "extract_time": "2015-02-28T00:00:00Z",
# "date": "2015-02-28T00:00:00Z",
# "total": "r123" }
# The follow response is received
# {"_status": "ERR",
# "_issues": { "total": "must be of integer type",
# "extract_time": "must be of datetime type" },
# "_error": { "message": "Insertion failure: 1 document(s) contain(s) error(s)",
# "code": 422 } }
# The "total" error is expected, the "extract_time" one is not
# If "total" is changed to 123, then the document is created successfully,
# despite there being no change to extract_time
# Failure #2:
# With the following payload:
# {"location": {
# "_id": "test" },
# "extract_time": "2015-02-28T00:00:00Z",
# "date": "2015-02-28T00:00:00Z",
# "total": "123" }
# A 200 OK is received, which is not expected
# The "total" field is actually a string, when an integer is expected
DOMAIN = {
'attendance': {
'schema': {
'extract_time': {
'required': True,
'type': 'datetime'
},
'location': {
'required': True,
'type': 'dict',
'schema': {
'_id': {
'required': True,
'type': 'string',
},
}
},
'date': {
'required': True,
'type': 'datetime',
},
'total': {
'required': True,
'type': 'integer',
},
},
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment