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())
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'}))
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'}))
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())
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())
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())
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'}))