예제 #1
0
    def test_Schema_with_type_key_validates_value_matching_pattern(self):
        schema = Schema({unicode: UnicodeField()})

        try:
            schema.validate({u'a': u'hello world'})
        except ValidationError:
            self.fail('Schema.validate() raised ValidationError unexpectedly')
예제 #2
0
    def test_Schema_with_type_key_validates_value_matching_pattern(self):
        schema = Schema({unicode: UnicodeField()})

        try:
            schema.validate({u'a': u'hello world'})
        except ValidationError:
            self.fail('Schema.validate() raised ValidationError unexpectedly')
예제 #3
0
 def test_list_fields(self):
     schema = Schema({'l': ListField(LongField())})
     # Empty lists
     schema.validate({u'l': []})
     # list with one correctly typed element
     schema.validate({u'l': [700L]})
     # list with one incorrectly typed element
     self.assertRaises(ValidationError, schema.validate, {u'l': [u'hello']})
예제 #4
0
    def test_additional_fields_in_nested_dictionary(self):
        # test whether a key in a nested dictionary not defined in the schema
        # causes a validation error. For testing whether recursion in schema
        # field access works properly.
        schema = Schema({'d': DictField({u'a': LongField()})})

        schema.validate({u'd': {'a': 50L}})
        self.assertRaises(ValidationError, schema.validate, {u'd': {'a': 50L, 'b': 20}})
예제 #5
0
    def test_nested_dictionaries(self):
        # Check if nested dictionaries are handled correctly
        schema = Schema({'d': {u'a': LongField()}})
        schema.validate({u'd': {'a': 50L}})

        # double-nested ...
        schema = Schema({'d': {u'a': {u'b': LongField()}}})
        schema.validate({u'd': {'a': {u'b': 50L}}})
예제 #6
0
    def test_optional_type_as_key(self):
        schema = Schema({u'text': UnicodeField(), unicode: LongField(optional=True)})

        schema.validate({u'text': u'hello world'})
예제 #7
0
    def test_type_as_key(self):
        schema = Schema({u'text': UnicodeField(), unicode: LongField()})

        schema.validate({u'text': u'hello world', u'a': 200L})
        self.assertRaises(ValidationError, schema.validate, {u'text': u'hello world'})
예제 #8
0
    def test_nested_fields(self):
        schema = Schema({u'text': UnicodeField(), u'd': DictField({u'a': UnicodeField()})})

        schema.validate({u'text': u'hello world', u'd': {u'a': u'bye bye world'}})
        self.assertRaises(ValidationError,schema.validate,
                {u'text': u'hello world', u'd': {u'a': u'bye bye world', u'b': u'oops'}})
예제 #9
0
 def test_empty_doc(self):
     schema = Schema({u'tag': UnicodeField(optional=True)})
     schema.validate({})
예제 #10
0
    def test_optional_field(self):
        schema = Schema({u'text': UnicodeField(), u'tag': UnicodeField(optional=True)})

        schema.validate({u'text': u'hello world'})
        schema.validate({u'text': u'hello world', u'tag': u'greeting'})
예제 #11
0
 def test_required_fields(self):
     schema = Schema({u'text': UnicodeField()})
     schema.validate({u'text': u'hello world'})
     self.assertRaises(ValidationError, schema.validate, {u'tag': u'greeting'})
예제 #12
0
 def test_Schema_validates_value_matching_pattern(self):
     schema = Schema({u'a': {u'b': UnicodeField()}})
     schema.validate({u'a': {u'b': u'hello world'}})
예제 #13
0
 def test_Schema_validates_value_matching_pattern(self):
     schema = Schema({u'a': {u'b': UnicodeField()}})
     schema.validate({u'a': {u'b': u'hello world'}})