-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from pennyfx/controller_validation
Add validation
- Loading branch information
Showing
11 changed files
with
229 additions
and
24 deletions.
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
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
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
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
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,44 @@ | ||
""" | ||
Tests for file_storage.py | ||
""" | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
import tempfile | ||
import platform | ||
import os | ||
from io import open | ||
try: | ||
to_unicode = unicode | ||
except NameError: | ||
to_unicode = str | ||
|
||
from datmo.core.util.validation import validate | ||
from datmo.core.util.exceptions import ValidationFailed, ValidationSchemaMissing | ||
|
||
|
||
class TestJSONStore(): | ||
def test_validate_success(self): | ||
assert validate("create_project", { | ||
"name": "foobar", | ||
"description": "barbaz" | ||
}) | ||
|
||
def test_validate_fail(self): | ||
failed = False | ||
try: | ||
validate("create_project", {"name": 3}) | ||
except ValidationFailed as e: | ||
failed = True | ||
assert e.errors | ||
assert isinstance(e.errors, dict) | ||
assert failed | ||
|
||
def test_invalid_scheme(self): | ||
failed = False | ||
try: | ||
validate("invalid_schema", {"name": "foobar"}) | ||
except ValidationSchemaMissing as e: | ||
failed = True | ||
assert failed |
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,24 @@ | ||
import os | ||
import yaml | ||
from cerberus import Validator | ||
from cerberus.schema import SchemaError | ||
from datmo.core.util.exceptions import ValidationFailed, ValidationSchemaMissing | ||
|
||
# http://docs.python-cerberus.org/en/stable/usage.html | ||
|
||
schema_yaml = open( | ||
os.path.join(os.path.split(__file__)[0], "validation/schemas.yml")) | ||
|
||
schemas = yaml.load(schema_yaml) | ||
|
||
|
||
def validate(schema_name, values): | ||
try: | ||
v = Validator(schemas.get(schema_name)) | ||
response = v.validate(values) | ||
|
||
if response == False: | ||
raise ValidationFailed(v.errors) | ||
return True | ||
except SchemaError: | ||
raise ValidationSchemaMissing(schema_name) |
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,76 @@ | ||
# http://docs.python-cerberus.org/en/stable/validation-rules.html | ||
|
||
create_project: | ||
name: | ||
empty: False | ||
required: True | ||
type: string | ||
description: | ||
required: True | ||
type: string | ||
|
||
create_session: | ||
name: | ||
required: True | ||
type: string | ||
current: | ||
type: boolean | ||
|
||
create_snapshot: | ||
code_id: | ||
type: string | ||
commit_id: | ||
type: string | ||
|
||
environment_id: | ||
type: string | ||
environment_definition_filepath: | ||
type: string | ||
|
||
file_collection_id: | ||
type: string | ||
filepaths: | ||
type: list | ||
|
||
config: | ||
type: dict | ||
config_filepath: | ||
type: string | ||
config_filename: | ||
type: string | ||
|
||
stats: | ||
type: dict | ||
stats_filepath: | ||
type: string | ||
stats_filename: | ||
type: string | ||
|
||
message: | ||
type: string | ||
session_id: | ||
type: string | ||
task_id: | ||
type: string | ||
label: | ||
type: string | ||
language: | ||
type: string | ||
|
||
visible: | ||
type: boolean | ||
|
||
create_snapshot_from_task: | ||
message: | ||
type: string | ||
task_id: | ||
type: string | ||
label: | ||
nullable: true | ||
type: string | ||
config: | ||
nullable: true | ||
type: dict | ||
stats: | ||
nullable: true | ||
type: dict |
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