forked from pipermerriam/flex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes pipermerriam#131
- Loading branch information
Aniruddha Maru
committed
Dec 9, 2016
1 parent
2d8b48f
commit d493918
Showing
4 changed files
with
78 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
import pytest | ||
|
||
from flex.exceptions import ValidationError | ||
from flex.constants import ( | ||
STRING, | ||
INTEGER, | ||
) | ||
from flex.error_messages import MULTIPLE_OF_MESSAGES | ||
|
||
from tests.utils import ( | ||
generate_validator_from_schema, | ||
assert_message_in_errors | ||
) | ||
|
||
|
||
def test_oneof_simple(): | ||
# example taken from http://spacetelescope.github.io/understanding-json-schema/reference/combining.html | ||
schema = { | ||
"oneOf": [ | ||
{ "type": INTEGER, "multipleOf": 5 }, | ||
{ "type": INTEGER, "multipleOf": 3 }, | ||
] | ||
} | ||
validator = generate_validator_from_schema(schema) | ||
|
||
validator(10) | ||
validator(9) | ||
|
||
|
||
def test_one_of_complex_failure(): | ||
# example taken from http://spacetelescope.github.io/understanding-json-schema/reference/combining.html | ||
schema = { | ||
"oneOf": [ | ||
{ "type": INTEGER, "multipleOf": 5 }, | ||
{ "type": INTEGER, "multipleOf": 3 }, | ||
] | ||
} | ||
validator = generate_validator_from_schema(schema) | ||
|
||
with pytest.raises(ValidationError) as err: | ||
validator(2) | ||
|
||
assert_message_in_errors( | ||
MULTIPLE_OF_MESSAGES['invalid'], | ||
err.value.detail, | ||
) | ||
|
||
with pytest.raises(ValidationError) as err: | ||
validator(15) | ||
|
||
assert_message_in_errors( | ||
MULTIPLE_OF_MESSAGES['invalid'], | ||
err.value.detail, | ||
) | ||
|