-
Notifications
You must be signed in to change notification settings - Fork 4
Formidable schema test on yml #295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,3 @@ | ||
[tool:pytest] | ||
; intentionally left blank | ||
; it voids the defaults that live in the setup.cfg file at the root of the repository. |
This file contains hidden or 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,52 @@ | ||
from os.path import abspath, join, dirname | ||
import json | ||
import collections | ||
|
||
from jsonschema import Draft4Validator | ||
import yaml | ||
|
||
ROOT_PATH = dirname(abspath(__file__)) | ||
|
||
|
||
def yaml2json(): | ||
""" | ||
Builds a dictionary of the BuilderForm definition out of the Swagger YAML. | ||
""" | ||
# Setup support for ordered dicts so we do not lose ordering | ||
# when importing from YAML | ||
_mapping_tag = yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG | ||
|
||
def dict_representer(dumper, data): | ||
return dumper.represent_mapping(_mapping_tag, data.iteritems()) | ||
|
||
def dict_constructor(loader, node): | ||
return collections.OrderedDict(loader.construct_pairs(node)) | ||
|
||
yaml.add_representer(collections.OrderedDict, dict_representer) | ||
yaml.add_constructor(_mapping_tag, dict_constructor) | ||
|
||
# Building raw data out of the Swagger Formidable definition | ||
swagger_file = join(ROOT_PATH, '..', 'swagger', 'formidable.yml') | ||
with open(swagger_file) as fd: | ||
data = yaml.load(fd) | ||
|
||
to_exclude = ( | ||
'BuilderForm', 'InputError', 'BuilderError', 'InputForm', 'InputField' | ||
) | ||
definitions = (item for item in data['definitions'].items()) | ||
definitions = filter(lambda item: item[0] not in to_exclude, definitions) | ||
|
||
new_data = {} | ||
new_data.update(data['definitions']['BuilderForm']) | ||
new_data.update({"definitions": dict(definitions)}) | ||
return new_data | ||
|
||
|
||
def _load_fixture(path): | ||
if not path.startswith('fixtures/'): | ||
path = 'fixtures/{}'.format(path) | ||
return json.load(open(join(ROOT_PATH, path))) | ||
|
||
|
||
schema = yaml2json() | ||
validator = Draft4Validator(schema) |
This file contains hidden or 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 @@ | ||
{} |
This file contains hidden or 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,3 @@ | ||
{ | ||
"id": 1 | ||
} |
This file contains hidden or 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,4 @@ | ||
{ | ||
"id": 1, | ||
"label": "This is my form title" | ||
} |
This file contains hidden or 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,5 @@ | ||
{ | ||
"id": "hello", | ||
"label": "This is my form title", | ||
"description": "Here's the description of my form." | ||
} |
This file contains hidden or 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,5 @@ | ||
{ | ||
"id": 1, | ||
"label": "This is my form title", | ||
"description": "Here's the description of my form." | ||
} |
This file contains hidden or 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,6 @@ | ||
{ | ||
"id": 1, | ||
"label": "This is my form title", | ||
"description": "Here's the description of my form.", | ||
"fields": {"hello": "world"} | ||
} |
This file contains hidden or 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,6 @@ | ||
{ | ||
"id": 1, | ||
"label": "This is my form title", | ||
"description": "Here's the description of my form.", | ||
"fields": 42 | ||
} |
This file contains hidden or 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,6 @@ | ||
{ | ||
"id": 1, | ||
"label": "This is my form title", | ||
"description": "Here's the description of my form.", | ||
"fields": [] | ||
} |
This file contains hidden or 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,8 @@ | ||
{ | ||
"id": 1, | ||
"label": "This is my form title", | ||
"description": "Here's the description of my form.", | ||
"fields": [ | ||
{} | ||
] | ||
} |
This file contains hidden or 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,15 @@ | ||
{ | ||
"id": 1, | ||
"label": "This is my form title", | ||
"description": "Here's the description of my form.", | ||
"fields": [ | ||
{ | ||
"id": 1, | ||
"label": "Name", | ||
"slug": "name", | ||
"type_id": "text", | ||
"description": "please put your name here", | ||
"accesses": [] | ||
} | ||
] | ||
} |
This file contains hidden or 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,16 @@ | ||
{ | ||
"id": 1, | ||
"label": "This is my form title", | ||
"description": "Here's the description of my form.", | ||
"fields": [ | ||
{ | ||
"id": 1, | ||
"label": "Name", | ||
"slug": "name", | ||
"type_id": "text", | ||
"description": "please put your name here", | ||
"accesses": [], | ||
"placeholder": "This is my placeholder" | ||
} | ||
] | ||
} |
This file contains hidden or 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,17 @@ | ||
{ | ||
"id": 1, | ||
"label": "This is my form title", | ||
"description": "Here's the description of my form.", | ||
"fields": [ | ||
{ | ||
"id": 1, | ||
"label": "Name", | ||
"slug": "name", | ||
"type_id": "text", | ||
"description": "please put your name here", | ||
"accesses": [], | ||
"placeholder": "This is my placeholder", | ||
"multiple": true | ||
} | ||
] | ||
} |
This file contains hidden or 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,21 @@ | ||
{ | ||
"id": 1, | ||
"label": "This is my form title", | ||
"description": "Here's the description of my form.", | ||
"fields": [ | ||
{ | ||
"id": 1, | ||
"label": "Name", | ||
"slug": "name", | ||
"type_id": "text", | ||
"description": "please put your name here", | ||
"accesses": [], | ||
"placeholder": "This is my placeholder", | ||
"multiple": true, | ||
"items": [ | ||
{"label": "first value", "value": "FIRST", "description": "This is my first value"}, | ||
{"label": "second value", "value": "SECOND", "description": "This is the last value"} | ||
] | ||
} | ||
] | ||
} |
This file contains hidden or 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,20 @@ | ||
{ | ||
"id": 1, | ||
"label": "This is my form title", | ||
"description": "Here's the description of my form.", | ||
"fields": [ | ||
{ | ||
"id": 1, | ||
"label": "Name", | ||
"slug": "name", | ||
"type_id": "text", | ||
"description": "please put your name here", | ||
"accesses": [], | ||
"placeholder": "This is my placeholder", | ||
"accesses": [ | ||
{"access_id": "JEDI", "level": "REQUIRED"}, | ||
{"access_id": "PADAWAN", "level": "EDITABLE"} | ||
] | ||
} | ||
] | ||
} |
This file contains hidden or 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,20 @@ | ||
{ | ||
"id": 1, | ||
"label": "This is my form title", | ||
"description": "Here's the description of my form.", | ||
"fields": [ | ||
{ | ||
"id": 1, | ||
"label": "Name", | ||
"slug": "name", | ||
"type_id": "text", | ||
"description": "please put your name here", | ||
"accesses": [], | ||
"placeholder": "This is my placeholder", | ||
"validations": [ | ||
{"type": "MINLENGTH", "value": "5", "message": "Your name is too short"}, | ||
{"type": "MAXLENGTH", "value": "100", "message": "Your name is too long"} | ||
] | ||
} | ||
] | ||
} |
This file contains hidden or 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,17 @@ | ||
{ | ||
"id": 1, | ||
"label": "This is my form title", | ||
"description": "Here's the description of my form.", | ||
"fields": [ | ||
{ | ||
"id": 1, | ||
"label": "Name", | ||
"slug": "name", | ||
"type_id": "text", | ||
"description": "please put your name here", | ||
"accesses": [], | ||
"placeholder": "This is my placeholder", | ||
"defaults": ["This is your default"] | ||
} | ||
] | ||
} |
This file contains hidden or 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,60 @@ | ||
{ | ||
"id": 1, | ||
"label": "The Game Form", | ||
"description": "A form to pick a cool game", | ||
"fields": [ | ||
{ | ||
"id": 1, | ||
"slug": "do-you-want-to-play-games", | ||
"label": "Do you want to play games?", | ||
"type_id": "checkbox", | ||
"description": "", | ||
"accesses": [] | ||
}, | ||
{ | ||
"id": 2, | ||
"slug": "favorite-game", | ||
"label": "Favorite game", | ||
"type_id": "dropdown", | ||
"description": "", | ||
"accesses": [], | ||
"items": [ | ||
{ | ||
"value": "BORING", | ||
"label": "Monopoly" | ||
}, | ||
{ | ||
"value": "YES", | ||
"label": "Magic Maze" | ||
} | ||
], | ||
"multiple": false | ||
}, | ||
{ | ||
"id": 3, | ||
"slug": "please-explain", | ||
"label": "Please, explain...", | ||
"type_id": "text", | ||
"description": "Please explain why it matters...", | ||
"accesses": [] | ||
} | ||
], | ||
"conditions": [ | ||
{ | ||
"name": "Jeux", | ||
"field_ids": [ | ||
"favorite-game" | ||
], | ||
"action": "display_iff", | ||
"tests": [ | ||
{ | ||
"field_id": "do-you-want-to-play-games", | ||
"operator": "eq", | ||
"values": [ | ||
"true" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains hidden or 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,7 @@ | ||
from jsonschema import Draft4Validator | ||
from . import schema | ||
|
||
|
||
def test_validate_schema(): | ||
# First, check Schema | ||
assert Draft4Validator.check_schema(schema) is None |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason the number in the file name goes from 0004 to 0010? (also some numbers are similar)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried to work using "blocks" of similar tests and "space" them to make sure I could squeeze more tests in the blocks without having to rename all my fixtures.
The numbers are following the schema definition logic, from the most basic to the most complicated.
On top of that, they haven't been written in order, I've jumped from one idea to another, so I've put "spaces" when I was starting to write a test that was a bit ahead, so sometimes there's a gap between fixture numbers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the answer :)