From c9ff1a1110c66db4c0770ef70bb1edfbc0027e2f Mon Sep 17 00:00:00 2001 From: "C.D. Clark III" Date: Tue, 9 Jun 2015 16:52:16 -0500 Subject: [PATCH] added unit test for fail_fast behavior with type lists unit tests that tests for the error fixed in the last commit. --- validictory/tests/test_fail_fast.py | 45 +++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/validictory/tests/test_fail_fast.py b/validictory/tests/test_fail_fast.py index 3ebb3e6..67c4bae 100644 --- a/validictory/tests/test_fail_fast.py +++ b/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 @@ -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