mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
33b7d52d31
* moving docs to mkdocs * transfering readme to md and more * fixing build * splitting usage.md * improving schema.md and index.md * fix make_history.rst * models intro * working on data conversation and required fields * more fixes to models.md * list all standard types supported * list of pydantic types * tweaks * update links in code * Apply suggestions from code review incorporate @dmontagu's suggestions. Co-Authored-By: dmontagu <35119617+dmontagu@users.noreply.github.com> * Apply suggestions from code review more missed suggestions. Co-Authored-By: dmontagu <35119617+dmontagu@users.noreply.github.com> * Apply suggestions from code review more corrects. * cleanup * Field order warning * fix and regenerate benchmarks * format examples better, cleanup * improve schema mapping table * correct highlighting file types in schema.md * add redirects in javascript * add logo
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
from dateutil.parser import parse
|
|
import trafaret as t
|
|
|
|
|
|
class TestTrafaret:
|
|
package = 'trafaret'
|
|
version = '.'.join(map(str, t.__VERSION__))
|
|
|
|
def __init__(self, allow_extra):
|
|
self.schema = t.Dict({
|
|
'id': t.Int(),
|
|
'client_name': t.String(max_length=255),
|
|
'sort_index': t.Float,
|
|
# t.Key('client_email', optional=True): t.Or(t.Null | t.Email()),
|
|
t.Key('client_phone', optional=True): t.Or(t.Null | t.String(max_length=255)),
|
|
|
|
t.Key('location', optional=True): t.Or(t.Null | t.Dict({
|
|
'latitude': t.Or(t.Float | t.Null),
|
|
'longitude': t.Or(t.Float | t.Null),
|
|
})),
|
|
|
|
t.Key('contractor', optional=True): t.Or(t.Null | t.Int(gt=0)),
|
|
t.Key('upstream_http_referrer', optional=True): t.Or(t.Null | t.String(max_length=1023)),
|
|
t.Key('grecaptcha_response'): t.String(min_length=20, max_length=1000),
|
|
|
|
t.Key('last_updated', optional=True): t.Or(t.Null | t.String >> parse),
|
|
|
|
t.Key('skills', default=[]): t.List(t.Dict({
|
|
'subject': t.String,
|
|
'subject_id': t.Int,
|
|
'category': t.String,
|
|
'qual_level': t.String,
|
|
'qual_level_id': t.Int,
|
|
t.Key('qual_level_ranking', default=0): t.Float,
|
|
})),
|
|
})
|
|
if allow_extra:
|
|
self.schema.allow_extra('*')
|
|
|
|
def validate(self, data):
|
|
try:
|
|
return True, self.schema.check(data)
|
|
except t.DataError:
|
|
return False, None
|
|
except ValueError:
|
|
return False, None
|