예제 #1
0
    def test_to_son(self):
        field = EmbeddedDocumentField(db_field="test", embedded_document_type=User)

        u = User(name="test")

        expect(field.to_son(u)).to_be_like({
            'name': 'test'
        })
예제 #2
0
    def test_from_son(self):
        field = EmbeddedDocumentField(db_field="test", embedded_document_type=User)

        user = field.from_son({
            'name': 'test2'
        })

        expect(user).to_be_instance_of(User)
        expect(user.name).to_equal("test2")
예제 #3
0
 def test_cant_create_embedded_field_of_wrong_embedded_type(self):
     try:
         EmbeddedDocumentField(embedded_document_type=10).validate(None)
     except ValueError:
         err = sys.exc_info()[1]
         expect(err).to_have_an_error_message_of("The field 'embedded_document_type' argument must be a subclass of Document, not '10'.")
     else:
         assert False, "Should not have gotten this far"
예제 #4
0
class User(Document):
    email = StringField(required=True)
    first_name = StringField(db_field="whatever",
                             max_length=50,
                             default=lambda: "Bernardo")
    last_name = StringField(max_length=50, default="Heynemann")
    is_admin = BooleanField(default=True)
    website = URLField(default="http://google.com/")
    updated_at = DateTimeField(required=True,
                               auto_now_on_insert=True,
                               auto_now_on_update=True)
    embedded = EmbeddedDocumentField(EmbeddedDocument,
                                     db_field="embedded_document")
    nullable = EmbeddedDocumentField(EmbeddedDocument,
                                     db_field="nullable_embedded_document")
    numbers = ListField(IntField())

    def __repr__(self):
        return "%s %s <%s>" % (self.first_name, self.last_name, self.email)
class Post(Document):
    title = StringField(required=True)
    body = StringField(required=True)

    comments = ListField(EmbeddedDocumentField(Comment))
예제 #6
0
class EmbeddedDocument(Document):
    test = StringField(db_field="other", required=True)
    embedded2 = EmbeddedDocumentField(EmbeddedDocument2)
예제 #7
0
 def test_create_embedded_document_field_with_string_type(self):
     field = EmbeddedDocumentField(embedded_document_type="tests.fields.test_embedded_document_field.User")
     expect(field.embedded_type).to_equal(User)
예제 #8
0
 def test_create_embedded_document_field(self):
     field = EmbeddedDocumentField(db_field="test", embedded_document_type=User)
     expect(field.db_field).to_equal("test")
     expect(field._embedded_document_type).to_equal(User)
예제 #9
0
 class Test(Document):
     __collection__ = "TestEmbeddedParent"
     test = EmbeddedDocumentField(TestEmbedded)
예제 #10
0
 class RawQueryDocument(Document):
     items = ListField(EmbeddedDocumentField(RawQueryEmbeddedDocument))
예제 #11
0
 class ElemMatchEmbeddedParentDocument(Document):
     items = ListField(EmbeddedDocumentField(ElemMatchEmbeddedDocument))