コード例 #1
0
    def test_save_max_recursion_not_hit(self):

        _document_registry.clear()

        class Person(Document):
            name = StringField()
            parent = ReferenceField('self')
            friend = ReferenceField('self')

        Person.drop_collection()

        p1 = Person(name="Wilson Snr")
        p1.parent = None
        p1.save()

        p2 = Person(name="Wilson Jr")
        p2.parent = p1
        p2.save()

        p1.friend = p2
        p1.save()

        # Confirm can save and it resets the changed fields without hitting
        # max recursion error
        p0 = Person.find_one({})
        p0.name = 'wpjunior'
        p0.save()
コード例 #2
0
ファイル: document.py プロジェクト: andrew-cl/mongoengine
    def test_save_max_recursion_not_hit(self):

        _document_registry.clear()
        class Person(Document):
            name = StringField()
            parent = ReferenceField('self')
            friend = ReferenceField('self')

        Person.drop_collection()

        p1 = Person(name="Wilson Snr")
        p1.parent = None
        p1.save()

        p2 = Person(name="Wilson Jr")
        p2.parent = p1
        p2.save()

        p1.friend = p2
        p1.save()

        # Confirm can save and it resets the changed fields without hitting
        # max recursion error
        p0 = Person.find_one({})
        p0.name = 'wpjunior'
        p0.save()
コード例 #3
0
    def test_collection_name(self):
        """Ensure that a collection with a specified name may be used.
        """
        collection = 'personCollTest'
        if collection in self.db.collection_names():
            self.db.drop_collection(collection)

        _document_registry.clear()

        class Person(Document):
            name = StringField()
            meta = {'collection': collection}

        user = Person(name="Test User")
        user.save()
        self.assertTrue(collection in self.db.collection_names())

        user_obj = self.db[collection].find_one()
        self.assertEqual(user_obj['name'], "Test User")

        user_obj = Person.objects[0]
        self.assertEqual(user_obj.name, "Test User")

        Person.drop_collection()
        self.assertFalse(collection in self.db.collection_names())
コード例 #4
0
ファイル: document.py プロジェクト: andrew-cl/mongoengine
    def test_collection_name_and_primary(self):
        """Ensure that a collection with a specified name may be used.
        """

        _document_registry.clear()
        class Person(Document):
            name = StringField(primary_key=True)
            meta = {'collection': 'app'}

        user = Person(name="Test User")
        user.save()

        user_obj = Person.objects[0]
        self.assertEqual(user_obj.name, "Test User")

        Person.drop_collection()
コード例 #5
0
    def test_collection_name_and_primary(self):
        """Ensure that a collection with a specified name may be used.
        """

        _document_registry.clear()

        class Person(Document):
            name = StringField(primary_key=True)
            meta = {'collection': 'app'}

        user = Person(name="Test User")
        user.save()

        user_obj = Person.objects[0]
        self.assertEqual(user_obj.name, "Test User")

        Person.drop_collection()
コード例 #6
0
ファイル: document.py プロジェクト: andrew-cl/mongoengine
    def test_definition(self):
        """Ensure that document may be defined using fields.
        """
        name_field = StringField()
        age_field = IntField()

        _document_registry.clear()
        class Person(Document):
            name = name_field
            age = age_field
            non_field = True

        self.assertEqual(Person._fields['name'], name_field)
        self.assertEqual(Person._fields['age'], age_field)
        self.assertFalse('non_field' in Person._fields)
        self.assertTrue('id' in Person._fields)
        # Test iteration over fields
        fields = list(Person())
        self.assertTrue('name' in fields and 'age' in fields)
        # Ensure Document isn't treated like an actual document
        self.assertFalse(hasattr(Document, '_fields'))
コード例 #7
0
    def test_definition(self):
        """Ensure that document may be defined using fields.
        """
        name_field = StringField()
        age_field = IntField()

        _document_registry.clear()

        class Person(Document):
            name = name_field
            age = age_field
            non_field = True

        self.assertEqual(Person._fields['name'], name_field)
        self.assertEqual(Person._fields['age'], age_field)
        self.assertFalse('non_field' in Person._fields)
        self.assertTrue('id' in Person._fields)
        # Test iteration over fields
        fields = list(Person())
        self.assertTrue('name' in fields and 'age' in fields)
        # Ensure Document isn't treated like an actual document
        self.assertFalse(hasattr(Document, '_fields'))
コード例 #8
0
ファイル: document.py プロジェクト: andrew-cl/mongoengine
    def test_collection_name(self):
        """Ensure that a collection with a specified name may be used.
        """
        collection = 'personCollTest'
        if collection in self.db.collection_names():
            self.db.drop_collection(collection)

        _document_registry.clear()
        class Person(Document):
            name = StringField()
            meta = {'collection': collection}

        user = Person(name="Test User")
        user.save()
        self.assertTrue(collection in self.db.collection_names())

        user_obj = self.db[collection].find_one()
        self.assertEqual(user_obj['name'], "Test User")

        user_obj = Person.objects[0]
        self.assertEqual(user_obj.name, "Test User")

        Person.drop_collection()
        self.assertFalse(collection in self.db.collection_names())
コード例 #9
0
 def tearDown(self):
     _document_registry.clear()
     self.person_cls.drop_collection()
コード例 #10
0
ファイル: document.py プロジェクト: andrew-cl/mongoengine
    def tearDown(self):
        self.Person.drop_collection()
        _document_registry.clear()

        Citizen.drop_collection()
コード例 #11
0
    def tearDown(self):
        self.Person.drop_collection()
        _document_registry.clear()

        Citizen.drop_collection()
コード例 #12
0
 def tearDown(self):
     _document_registry.clear()
     self.person_cls.drop_collection()
コード例 #13
0
ファイル: fields.py プロジェクト: fygao-wish/mongoengine
 def tearDown(self):
     _document_registry.clear()