Exemple #1
0
class TestFallbackPerson(Model):
    age = IntegerField('The Age')
    name = TextField('The name',
                     fallbacks=[
                         SingleFieldFallback('nick'),
                         SingleFieldFallback('obsolete'),
                     ])
    nick = TextField('The nickname', required=False)
    obsolete = TextField('Some obsolete field', required=False)
 def test_creating_uuids(self):
     model_class = self.mk_model({
         'age': IntegerField('An age'),
         'name': TextField('A name'),
     })
     data = {'age': 1, 'name': 'foo'}
     model = model_class(data)
     self.assertTrue(model.uuid)
 def test_to_dict(self):
     model_class = self.mk_model({
         'age': IntegerField('An age'),
         'name': TextField('A name'),
     })
     data = {'age': 1, 'name': 'foo', '_version': version_info}
     model = model_class(data)
     self.assertEqual(dict(model), data)
 def test_respecting_uuids(self):
     model_class = self.mk_model({
         'uuid': 'foo',
         'age': IntegerField('An age'),
         'name': TextField('A name'),
     })
     data = {'age': 1, 'name': 'foo'}
     model = model_class(data)
     self.assertEqual(model.uuid, 'foo')
 def test_doc_generation(self):
     model_class = self.mk_model({
         'age': IntegerField('An age'),
         'name': TextField('A name'),
     })
     model = model_class({'age': 1, 'name': 'foo'})
     self.assertTrue(':param int age:' in model_class.__doc__)
     self.assertTrue(':param int age:' in model.__doc__)
     self.assertTrue(':param str name:' in model_class.__doc__)
     self.assertTrue(':param str name:' in model.__doc__)
 def test_dict_field(self):
     model_class = self.mk_model({
         'foo':
         DictField('dict field',
                   fields=(
                       TextField('a', name='a'),
                       TextField('b', name='b'),
                   ))
     })
     self.assertEqual(
         model_class._fields['foo'].mapping, {
             'type': 'nested',
             'properties': {
                 'a': {
                     'type': 'string'
                 },
                 'b': {
                     'type': 'string'
                 },
             }
         })
 def test_update(self):
     model_class = self.mk_model({
         'uuid': 'foo',
         'age': IntegerField('An age'),
         'name': TextField('A name'),
     })
     data = {'age': 1, 'name': 'foo'}
     model = model_class(data)
     self.assertFalse(model.is_read_only())
     new_model = model.update({'age': 20})
     self.assertEqual(new_model.age, 20)
     self.assertEqual(new_model.uuid, model.uuid)
     self.assertEqual(new_model.name, model.name)
     self.assertTrue(model.is_read_only())
     self.assertFalse(new_model.is_read_only())
Exemple #8
0
class TestPage(Model):
    title = TextField('The title')
    slug = TextField('The slug', mapping={'index': 'not_analyzed'})
    language = TextField('The language', mapping={'index': 'not_analyzed'})
Exemple #9
0
class TestPerson(Model):
    age = IntegerField('The Age')
    name = TextField('The name')