Skip to content

Commit

Permalink
added unit test for fail_fast behavior with type lists
Browse files Browse the repository at this point in the history
unit tests that tests for the error fixed in the last commit.
  • Loading branch information
CD3 committed Jun 9, 2015
1 parent dc78cf3 commit c9ff1a1
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions validictory/tests/test_fail_fast.py
@@ -1,5 +1,8 @@
from unittest import TestCase

import sys, os
sys.path = [ os.path.join( os.path.dirname( __file__ ), '..' ) ] + sys.path

import validictory


Expand Down Expand Up @@ -75,3 +78,45 @@ def test_multi_error_with_format(self):
validictory.validate(data, schema, fail_fast=False)
except validictory.MultipleValidationError as mve:
assert len(mve.errors) == 2

def test_no_error_with_type_list(self):
schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer"},
"sibling" : { "type" : ["string", "null" ] }
},
}
data = {"name": "john doe", "age": 42, "sibling" : None }

# this should not raise an error
validictory.validate( data, schema, fail_fast=True)

# and nieter should this...fixed by dc78c
validictory.validate( data, schema, fail_fast=False)

def test_multi_error_with_type_list(self):
schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer"},
"sibling" : { "type" : ["string", "null" ] }
},
}
data = {"name": 2, "age": "fourty-two", "sibling" : 0 }

# ensure it raises an error
self.assertRaises(validictory.ValidationError, validictory.validate,
data, schema, fail_fast=True)

# ensure it raises a MultiError
self.assertRaises(validictory.MultipleValidationError, validictory.validate,
data, schema, fail_fast=False)

# ensure that the MultiError has 3 errors
try:
validictory.validate(data, schema, fail_fast=False)
except validictory.MultipleValidationError as mve:
assert len(mve.errors) == 3

0 comments on commit c9ff1a1

Please sign in to comment.