예제 #1
0
    def test_create_empty_doc(self):
        # Empty schema
        schema = Schema({})
        self.assertEquals({}, schema.create())

        # Schema with only optional fields
        schema = Schema({u'a': UnicodeField(optional=True)})
        self.assertEquals({}, schema.create())
예제 #2
0
    def test_create_empty_doc(self):
        # Empty schema
        schema = Schema({})
        self.assertEquals({}, schema.create())

        # Schema with only optional fields
        schema = Schema({u'a': UnicodeField(optional=True)})
        self.assertEquals({}, schema.create())
예제 #3
0
    def test_create_with_defaults(self):
        schema = Schema({u'a': UnicodeField(default=u'hello world')})
        self.assertEquals({u'a': u'hello world'}, schema.create())

        # test creating instance with given default value
        schema = Schema({u'a': UnicodeField(default=u'hello world'),
                         u'b': UnicodeField(default=u'hello good bye')})
        self.assertEquals({u'a': u'hello venus', u'b': u'hello good bye'},
                          schema.create({u'a': u'hello venus'}))
예제 #4
0
    def test_create_with_defaults(self):
        schema = Schema({u'a': UnicodeField(default=u'hello world')})
        self.assertEquals({u'a': u'hello world'}, schema.create())

        # test creating instance with given default value
        schema = Schema({
            u'a': UnicodeField(default=u'hello world'),
            u'b': UnicodeField(default=u'hello good bye')
        })
        self.assertEquals({
            u'a': u'hello venus',
            u'b': u'hello good bye'
        }, schema.create({u'a': u'hello venus'}))
예제 #5
0
    def test_create_with_callable_builds_dict_by_calling_function(self):
        global counter
        counter = 0
        def inc():
            global counter
            counter += 1
            return counter

        schema = Schema({u'counter': IntField(default=inc)})

        self.assertEquals({u'counter': 1}, schema.create())
        self.assertEquals({u'counter': 2}, schema.create())
예제 #6
0
 def test_create_nested(self):
     schema = Schema({u'a': {u'b': UnicodeField(default=u'hello world')}})
     self.assertEquals({u'a': {u'b': u'hello world'}}, schema.create())
예제 #7
0
 def test_create_nested(self):
     schema = Schema({u'a': {u'b': UnicodeField(default=u'hello world')}})
     self.assertEquals({u'a': {u'b': u'hello world'}}, schema.create())
예제 #8
0
    def test_create_builds_nested_dict_with_default_values(self):
        schema = Schema({u'a': {u'b': UnicodeField(default=u'hello world')}})

        self.assertEquals({u'a': {u'b': u'hello world'}}, schema.create())
예제 #9
0
    def test_create_with_type_key_builds_dict_with_default_values(self):
        schema = Schema({u'a': UnicodeField(default=u'hello world'), unicode: UnicodeField(default=u'aarrgghh')})

        self.assertEquals({u'a': u'hello world'}, schema.create())
        self.assertEquals({u'a': u'hello world', u'b': u'world'}, schema.create({u'b': u'world'}))