|
16 | 16 | merge_schema_new,
|
17 | 17 | )
|
18 | 18 |
|
| 19 | +class SchemaWithCombiningKeywords(TestCase): |
| 20 | + |
| 21 | + schema_allOf = { |
| 22 | + "$schema": JSON_SCHEMA_DRAFT_7, |
| 23 | + "allOf": [ |
| 24 | + { |
| 25 | + "properties": {"foo": {"type": "string"}}, |
| 26 | + "required": ["foo"], |
| 27 | + }, |
| 28 | + { |
| 29 | + "properties": {"bar": {"type": "number"}}, |
| 30 | + "required": ["bar"] |
| 31 | + } |
| 32 | + ] |
| 33 | + } |
| 34 | + |
| 35 | + schema_anyOf = { |
| 36 | + "$schema": JSON_SCHEMA_DRAFT_7, |
| 37 | + "anyOf": [ |
| 38 | + { |
| 39 | + "properties": {"foo": {"type": "string"}}, |
| 40 | + "required": ["foo"], |
| 41 | + }, |
| 42 | + { |
| 43 | + "properties": {"bar": {"type": "number"}}, |
| 44 | + "required": ["bar"] |
| 45 | + } |
| 46 | + ] |
| 47 | + } |
| 48 | + |
| 49 | + schema_oneOf = { |
| 50 | + "$schema": JSON_SCHEMA_DRAFT_7, |
| 51 | + "oneOf": [ |
| 52 | + { |
| 53 | + "properties": {"foo": {"type": "string"}}, |
| 54 | + "required": ["foo"], |
| 55 | + }, |
| 56 | + { |
| 57 | + "properties": {"bar": {"type": "number"}}, |
| 58 | + "required": ["bar"] |
| 59 | + } |
| 60 | + ] |
| 61 | + } |
| 62 | + |
| 63 | + def test_all_of_schema(self): |
| 64 | + |
| 65 | + class allOfItem(JsonSchemaItem): |
| 66 | + jsonschema = self.schema_allOf |
| 67 | + |
| 68 | + item = allOfItem() |
| 69 | + item['foo'] = 'foo' |
| 70 | + item['bar'] = 2 |
| 71 | + self.assertFalse(list(item.validator.iter_errors(dict(item)))) |
| 72 | + |
| 73 | + with pytest.raises(AssertionError): |
| 74 | + item = allOfItem() |
| 75 | + item['foo'] = 'foo' |
| 76 | + self.assertFalse(list(item.validator.iter_errors(dict(item)))) |
| 77 | + |
| 78 | + |
| 79 | + def test_any_of_schema(self): |
| 80 | + |
| 81 | + class anyOfItem(JsonSchemaItem): |
| 82 | + jsonschema = self.schema_anyOf |
| 83 | + |
| 84 | + item = anyOfItem() |
| 85 | + item['foo'] = 'foo' |
| 86 | + item['bar'] = 2 |
| 87 | + self.assertFalse(list(item.validator.iter_errors(dict(item)))) |
| 88 | + |
| 89 | + item = anyOfItem() |
| 90 | + item['foo'] = 'foo' |
| 91 | + self.assertFalse(list(item.validator.iter_errors(dict(item)))) |
| 92 | + |
| 93 | + item = anyOfItem() |
| 94 | + item['bar'] = 2 |
| 95 | + self.assertFalse(list(item.validator.iter_errors(dict(item)))) |
| 96 | + |
| 97 | + def test_one_of_schema(self): |
| 98 | + |
| 99 | + class oneOfItem(JsonSchemaItem): |
| 100 | + jsonschema = self.schema_oneOf |
| 101 | + |
| 102 | + item = oneOfItem() |
| 103 | + item['foo'] = 'foo' |
| 104 | + self.assertFalse(list(item.validator.iter_errors(dict(item)))) |
| 105 | + |
| 106 | + item = oneOfItem() |
| 107 | + item['bar'] = 2 |
| 108 | + self.assertFalse(list(item.validator.iter_errors(dict(item)))) |
| 109 | + |
| 110 | + with pytest.raises(AssertionError): |
| 111 | + item = oneOfItem() |
| 112 | + item['foo'] = 'foo' |
| 113 | + item['bar'] = 2 |
| 114 | + self.assertFalse(list(item.validator.iter_errors(dict(item)))) |
19 | 115 |
|
20 | 116 | class ValidSchemaTestCase(TestCase):
|
21 | 117 |
|
|
0 commit comments