@@ -529,6 +529,80 @@ def test_unambiguous_one_of(self, value, validator_factory):
529529
530530 assert result is None
531531
532+ @pytest .mark .parametrize ('value' , [Model (), ])
533+ def test_object_multiple_any_of (self , value , validator_factory ):
534+ any_of = [
535+ Schema ('object' ), Schema ('object' ),
536+ ]
537+ schema = Schema ('object' , any_of = any_of )
538+
539+ with pytest .raises (InvalidSchemaValue ):
540+ validator_factory (schema ).validate (value )
541+
542+ @pytest .mark .parametrize ('value' , [{}, ])
543+ def test_object_different_type_any_of (self , value , validator_factory ):
544+ any_of = [
545+ Schema ('integer' ), Schema ('string' ),
546+ ]
547+ schema = Schema ('object' , any_of = any_of )
548+
549+ with pytest .raises (InvalidSchemaValue ):
550+ validator_factory (schema ).validate (value )
551+
552+ @pytest .mark .parametrize ('value' , [{}, ])
553+ def test_object_no_any_of (self , value , validator_factory ):
554+ any_of = [
555+ Schema (
556+ 'object' ,
557+ properties = {'test1' : Schema ('string' )},
558+ required = ['test1' , ],
559+ ),
560+ Schema (
561+ 'object' ,
562+ properties = {'test2' : Schema ('string' )},
563+ required = ['test2' , ],
564+ ),
565+ ]
566+ schema = Schema ('object' , any_of = any_of )
567+
568+ with pytest .raises (InvalidSchemaValue ):
569+ validator_factory (schema ).validate (value )
570+
571+ @pytest .mark .parametrize ('value' , [
572+ {
573+ 'foo' : u ("FOO" ),
574+ },
575+ {
576+ 'foo' : u ("FOO" ),
577+ 'bar' : u ("BAR" ),
578+ },
579+ ])
580+ def test_unambiguous_any_of (self , value , validator_factory ):
581+ any_of = [
582+ Schema (
583+ 'object' ,
584+ properties = {
585+ 'foo' : Schema ('string' ),
586+ },
587+ additional_properties = False ,
588+ required = ['foo' ],
589+ ),
590+ Schema (
591+ 'object' ,
592+ properties = {
593+ 'foo' : Schema ('string' ),
594+ 'bar' : Schema ('string' ),
595+ },
596+ additional_properties = False ,
597+ required = ['foo' , 'bar' ],
598+ ),
599+ ]
600+ schema = Schema ('object' , any_of = any_of )
601+
602+ result = validator_factory (schema ).validate (value )
603+
604+ assert result is None
605+
532606 @pytest .mark .parametrize ('value' , [{}, ])
533607 def test_object_default_property (self , value , validator_factory ):
534608 schema = Schema ('object' , default = 'value1' )
0 commit comments