Added document mixin support
For extendable / reusable documents Fixes #204
This commit is contained in:
parent
e04e5f42ef
commit
1b0323bc22
4 changed files with 36 additions and 2 deletions
|
|
@ -1380,6 +1380,36 @@ class DocumentTest(unittest.TestCase):
|
|||
promoted_employee.reload()
|
||||
self.assertEqual(promoted_employee.details, None)
|
||||
|
||||
def test_mixins_dont_add_to_types(self):
|
||||
|
||||
class Bob(Document): name = StringField()
|
||||
|
||||
Bob.drop_collection()
|
||||
|
||||
p = Bob(name="Rozza")
|
||||
p.save()
|
||||
Bob.drop_collection()
|
||||
|
||||
class Person(Document, Mixin):
|
||||
pass
|
||||
|
||||
Person.drop_collection()
|
||||
|
||||
p = Person(name="Rozza")
|
||||
p.save()
|
||||
self.assertEquals(p._fields.keys(), ['name', 'id'])
|
||||
|
||||
collection = self.db[Person._meta['collection']]
|
||||
obj = collection.find_one()
|
||||
self.assertEquals(obj['_cls'], 'Person')
|
||||
self.assertEquals(obj['_types'], ['Person'])
|
||||
|
||||
|
||||
|
||||
self.assertEquals(Person.objects.count(), 1)
|
||||
rozza = Person.objects.get(name="Rozza")
|
||||
|
||||
Person.drop_collection()
|
||||
|
||||
def test_save_reference(self):
|
||||
"""Ensure that a document reference field may be saved in the database.
|
||||
|
|
|
|||
|
|
@ -18,8 +18,7 @@ class PickleTest(Document):
|
|||
|
||||
|
||||
class Mixin(object):
|
||||
number = IntField()
|
||||
string = StringField(choices=(('One', '1'), ('Two', '2')))
|
||||
name = StringField()
|
||||
|
||||
|
||||
class Base(Document):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue