mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
9900c7f00c
deprecated `ignore_extra` and `allow_extra` Config fields in favor of `extra`, fix #352 * refaactored extra types to use a single enum * slightly simplified * added tests * fixed most stuff * docs and some simplifications * better assert * changed enum and fixed logic * trying to capture deprecation warning * make format * fixing tests and moving exta logic to __new__ * set_extra tests * fox benchmarks * formatting * updated history * docs * added a negative tests * reverted format changes * format * matched casing * renamed values * more fixes * forgot values change * another one * weird stuff * linting issue * Update pydantic/main.py Co-Authored-By: liiight <4374581+liiight@users.noreply.github.com>
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
from datetime import datetime
|
|
from typing import List
|
|
|
|
from pydantic import BaseModel, Extra, PositiveInt, ValidationError, constr
|
|
|
|
|
|
class TestPydantic:
|
|
package = 'pydantic'
|
|
|
|
def __init__(self, allow_extra):
|
|
|
|
class Model(BaseModel):
|
|
id: int
|
|
client_name: constr(max_length=255)
|
|
sort_index: float
|
|
# client_email: EmailStr = None
|
|
client_phone: constr(max_length=255) = None
|
|
|
|
class Location(BaseModel):
|
|
latitude: float = None
|
|
longitude: float = None
|
|
location: Location = None
|
|
|
|
contractor: PositiveInt = None
|
|
upstream_http_referrer: constr(max_length=1023) = None
|
|
grecaptcha_response: constr(min_length=20, max_length=1000)
|
|
last_updated: datetime = None
|
|
|
|
class Skill(BaseModel):
|
|
subject: str
|
|
subject_id: int
|
|
category: str
|
|
qual_level: str
|
|
qual_level_id: int
|
|
qual_level_ranking: float = 0
|
|
skills: List[Skill] = []
|
|
|
|
class Config:
|
|
extra = Extra.allow if allow_extra else Extra.forbid
|
|
|
|
self.model = Model
|
|
|
|
def validate(self, data):
|
|
try:
|
|
return True, self.model(**data)
|
|
except ValidationError as e:
|
|
return False, str(e)
|