Added unit test for EmbeddedDocument
This commit is contained in:
parent
5a87534c22
commit
0bb0ec0114
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
class ValidationError(Exception):
|
class ValidationError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -69,7 +70,7 @@ class DocumentMetaclass(type):
|
|||||||
|
|
||||||
def __new__(cls, name, bases, attrs):
|
def __new__(cls, name, bases, attrs):
|
||||||
metaclass = attrs.get('__metaclass__')
|
metaclass = attrs.get('__metaclass__')
|
||||||
super_new = super(DocumentMetaclass, cls).__new__
|
super_new = super(DocumentMetaclass, cls).__new__
|
||||||
if metaclass and issubclass(metaclass, DocumentMetaclass):
|
if metaclass and issubclass(metaclass, DocumentMetaclass):
|
||||||
return super_new(cls, name, bases, attrs)
|
return super_new(cls, name, bases, attrs)
|
||||||
|
|
||||||
@ -98,9 +99,12 @@ class TopLevelDocumentMetaclass(DocumentMetaclass):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __new__(cls, name, bases, attrs):
|
def __new__(cls, name, bases, attrs):
|
||||||
|
super_new = super(TopLevelDocumentMetaclass, cls).__new__
|
||||||
# Classes defined in this package are abstract and should not have
|
# Classes defined in this package are abstract and should not have
|
||||||
# their own metadata with DB collection, etc.
|
# their own metadata with DB collection, etc.
|
||||||
super_new = super(TopLevelDocumentMetaclass, cls).__new__
|
# __metaclass__ is only set on the class with the __metaclass__
|
||||||
|
# attribute (i.e. it is not set on subclasses). This differentiates
|
||||||
|
# 'real' documents from the 'Document' class
|
||||||
if attrs.get('__metaclass__') == TopLevelDocumentMetaclass:
|
if attrs.get('__metaclass__') == TopLevelDocumentMetaclass:
|
||||||
return super_new(cls, name, bases, attrs)
|
return super_new(cls, name, bases, attrs)
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from mongomap import Document, StringField, IntField
|
from mongomap import *
|
||||||
|
|
||||||
|
|
||||||
class DocumentTest(unittest.TestCase):
|
class DocumentTest(unittest.TestCase):
|
||||||
@ -61,6 +61,14 @@ class DocumentTest(unittest.TestCase):
|
|||||||
person['name'] = 'Another User'
|
person['name'] = 'Another User'
|
||||||
self.assertEquals(person['name'], 'Another User')
|
self.assertEquals(person['name'], 'Another User')
|
||||||
|
|
||||||
|
def test_embedded_document(self):
|
||||||
|
"""Ensure that embedded documents are set up correctly.
|
||||||
|
"""
|
||||||
|
class Comment(EmbeddedDocument):
|
||||||
|
content = StringField()
|
||||||
|
|
||||||
|
self.assertTrue('content' in Comment._fields)
|
||||||
|
self.assertFalse(hasattr(Comment, '_meta'))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user