1-
21import pytest
32
43import python_jsonschema_objects as pjo
@@ -10,27 +9,64 @@ def arrayClass():
109 "title" : "ArrayVal" ,
1110 "type" : "object" ,
1211 "properties" : {
13- "min" : {"type" : "array" , "items" : {"type" : "string" }, "default" : [], "minItems" : 1 },
14- "max" : {"type" : "array" , "items" : {"type" : "string" }, "default" : [], "maxItems" : 1 },
15- "both" : {"type" : "array" , "items" : {"type" : "string" }, "default" : [], "maxItems" : 2 , "minItems" : 1 },
16- "unique" : {"type" : "array" , "items" : {"type" : "string" }, "default" : [], "uniqueItems" : True }
12+ "min" : {
13+ "type" : "array" ,
14+ "items" : {"type" : "string" },
15+ "default" : [],
16+ "minItems" : 1 ,
17+ },
18+ "max" : {
19+ "type" : "array" ,
20+ "items" : {"type" : "string" },
21+ "default" : [],
22+ "maxItems" : 1 ,
23+ },
24+ "both" : {
25+ "type" : "array" ,
26+ "items" : {"type" : "string" },
27+ "default" : [],
28+ "maxItems" : 2 ,
29+ "minItems" : 1 ,
30+ },
31+ "unique" : {
32+ "type" : "array" ,
33+ "items" : {"type" : "string" },
34+ "default" : [],
35+ "uniqueItems" : True ,
36+ },
37+ "reffed" : {
38+ "type" : "array" ,
39+ "items" : {"$ref" : "#/definitions/myref" },
40+ "minItems" : 1 ,
41+ },
1742 },
43+ "definitions" : {"myref" : {"type" : "string" }},
1844 }
1945
2046 ns = pjo .ObjectBuilder (schema ).build_classes ()
21- return ns ['Arrayval' ](min = ["1" ], both = ["1" ])
47+ return ns ["Arrayval" ](min = ["1" ], both = ["1" ])
48+
49+
50+ def test_validators_work_with_reference (arrayClass ):
51+ arrayClass .reffed = ["foo" ]
52+
53+ with pytest .raises (pjo .ValidationError ):
54+ arrayClass .reffed = []
2255
2356
2457def test_array_length_validates (markdown_examples ):
2558
2659 builder = pjo .ObjectBuilder (
27- markdown_examples [' Example Schema' ],
28- resolved = markdown_examples )
60+ markdown_examples [" Example Schema" ], resolved = markdown_examples
61+ )
2962 ns = builder .build_classes ()
3063
3164 with pytest .raises (pjo .ValidationError ):
32- ns .ExampleSchema (firstName = "Fred" , lastName = "Huckstable" ,
33- dogs = ["Fido" , "Spot" , "Jasper" , "Lady" , "Tramp" ])
65+ ns .ExampleSchema (
66+ firstName = "Fred" ,
67+ lastName = "Huckstable" ,
68+ dogs = ["Fido" , "Spot" , "Jasper" , "Lady" , "Tramp" ],
69+ )
3470
3571
3672def test_minitems (arrayClass ):
0 commit comments