def test_0(self): """ When applied to an existing schema, an empty schema is returned. """ schema = Schema({'type': 'object', 'properties': {'normal': Schema({'type': 'string'})}, 'required': ['normal']}) schema.apply_func(self.validator.alter_schema) assert_equal(len(schema), 0)
def test_3(self): """ The schema is not altered if the required condition is only client side. """ schema = Schema({'type': 'object', 'properties': {'normal': Schema({'type': 'string'})}}) schema.apply_func(self.validator_conditional.alter_schema) assert_not_in('required', schema)
def _schema(self): """ On the fly schema computation """ schema = Schema() schema.apply_func(self._init_schema) # Apply modifiers for modifier in self.modifiers: if hasattr(modifier, 'alter_schema'): schema.apply_func(modifier.alter_schema) return schema.compile()
def test(self): """ Modify the type of the leaf object. """ schema = Schema( {"type": "object", "properties": {"normal": Schema({"type": "string"})}, "required": ["normal"]} ) schema.apply_func(self.validator.alter_schema) assert_equal("integer", schema["properties"]["normal"]["type"])
def test_2(self): """ Alter the schema by adding a required field to the schema for each named properties. """ schema = Schema({'type': 'object', 'properties': {'normal': Schema({'type': 'string'})}}) schema.apply_func(self.validator_default.alter_schema) assert_in('required', schema) assert_equal(schema['required'], ['normal'])
def test_4(self): """ The value of the pattern in the schema is not modified. If a schema is altered by the validator, only the leafs ared affected by the modifications. """ schema = Schema({'type': 'object', 'properties': {'normal': Schema({'type': 'string'})}, 'required': ['normal']}) schema.apply_func(self.validator.alter_schema) assert_in('[A-Z]{4}', schema['properties']['normal']['pattern'])
def test_3(self): """ Insert a pattern to the leaf objects. If a schema is altered by the validator, only the leafs ared affected by the modifications. """ schema = Schema({'type': 'object', 'properties': {'normal': Schema({'type': 'string'})}, 'required': ['normal']}) schema.apply_func(self.validator.alter_schema) assert_in('pattern', schema['properties']['normal'])
class TestPatternProperty(object): """ Tests are done with a schema having a variable with 'parent.child' as FQN; """ def setup(self): self.schema = Schema({'type': 'object', 'properties': {'parent': Schema({'type': 'object', 'properties': {'child': Schema({'type': 'string'})}})}}) def test_0(self): """PatternProperty does not set attributes.""" assert_equal(PatternProperty().attributes, {}) def test_1(self): """ The FQN redefinition can be partial and will not raise an exception. """ validator = PatternProperty(r'^[A-Z]{3}') self.schema.apply_func(validator.alter_schema) def test_2(self): """ The FQN redefinition add an asPatternProperty field to the object if the argument does not match the FQN. """ validator = PatternProperty(r'^[A-Z]{3}') self.schema.apply_func(validator.alter_schema) assert_in('asPatternProperty', self.schema['properties']['parent']) def test_3(self): """ The FQN redefinition set the asPatternProperty field value to the value of the argument if it does not match the FQN. """ validator = PatternProperty(r'^[A-Z]{3}') self.schema.apply_func(validator.alter_schema) assert_equal(self.schema['properties']['parent']['asPatternProperty'], r'^[A-Z]{3}') def test_4(self): """ If the FQN is not redefined, no modification is done. """ validator = PatternProperty('parent') self.schema.apply_func(validator.alter_schema) assert_not_in('asPatternProperty', self.schema['properties']['parent'])