Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds benchmark tests for Schematics tool (#2381)
* Adds benchmark tests for Schematics tool * Removes the "to_json" method from the schematics benchmark tests * Fixs exception check in the Schematics benchmark * tweaks and cleanup Co-authored-by: Alvaro Mariano <alvaro.mariano@br.experian.com> Co-authored-by: Samuel Colvin <s@muelcolvin.com>
- Loading branch information
1 parent
ededd3e
commit f32832a
Showing
3 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ attr | |
cattrs | ||
cerberus | ||
voluptuous | ||
schematics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from schematics import __version__ | ||
from schematics.exceptions import DataError, ValidationError | ||
from schematics.models import Model as PModel | ||
from schematics.types import IntType, StringType | ||
from schematics.types.base import DateType, FloatType | ||
from schematics.types.compound import ListType, ModelType | ||
|
||
|
||
class TestSchematics: | ||
package = 'schematics' | ||
version = __version__ | ||
|
||
def __init__(self, allow_extra): | ||
class Model(PModel): | ||
id = IntType(required=True) | ||
client_name = StringType(max_length=255, required=True) | ||
sort_index = FloatType(required=True) | ||
client_phone = StringType(max_length=255, default=None) | ||
|
||
class Location(PModel): | ||
latitude = FloatType(default=None) | ||
longitude = FloatType(default=None) | ||
|
||
location = ModelType(model_spec=Location, default=None) | ||
|
||
contractor = IntType(min_value=1, default=None) | ||
upstream_http_referrer = StringType(max_length=1023, default=None) | ||
grecaptcha_response = StringType(min_length=20, max_length=1000, required=True) | ||
last_updated = DateType(formats='%Y-%m-%dT%H:%M:%S') | ||
|
||
class Skill(PModel): | ||
subject = StringType(required=True) | ||
subject_id = IntType(required=True) | ||
category = StringType(required=True) | ||
qual_level = StringType(required=True) | ||
qual_level_id = IntType(required=True) | ||
qual_level_ranking = FloatType(default=0, required=True) | ||
|
||
skills = ListType(ModelType(Skill), default=[]) | ||
|
||
self.model = Model | ||
|
||
def validate(self, data): | ||
try: | ||
obj = self.model(data) | ||
return True, obj.validate() | ||
except DataError as e: | ||
return False, e | ||
except ValidationError as e: | ||
return False, e |