Esempio n. 1
0
    def test_patch_async_connections(self):
        # here we create one SanicMongo connection
        with monkey.MonkeyPatcher() as p:
            p.patch_sync_connections()
            connect()

            with monkey.MonkeyPatcher() as patcher:
                # the patcher will remove all SanicMongo connections
                patcher.patch_async_connections()

                self.assertEqual(len(me_connection._connections), 0)

            self.assertEqual(len(me_connection._connections), 1)
Esempio n. 2
0
    def test_patch_db_clients(self):
        client = Mock()
        with monkey.MonkeyPatcher() as patcher:
            patcher.patch_db_clients(client)
            self.assertEqual(client, me_connection.MongoClient)

        self.assertNotEqual(client, me_connection.MongoClient)
Esempio n. 3
0
    def test_patch_item_without_undo(self):
        something = Mock()
        something.attr = 'Bla'

        with monkey.MonkeyPatcher() as patcher:
            patcher.patch_item(something, 'attr', 'ble', undo=False)

        self.assertEqual(something.attr, 'ble')
    def test_synchronize(self):
        class TestClass(Document):
            @metaprogramming.synchronize
            def some_method(self):
                self._get_collection()

        # as we are testing synchronize, we remove all sync connections
        # so it does not interfere in our test
        with monkey.MonkeyPatcher() as patcher:
            patcher.patch_sync_connections()
            connect()
            self.assertEqual(len(connection._connections), 1)
            TestClass().some_method()
            self.assertEqual(len(connection._connections), 2)
Esempio n. 5
0
    def test_patch_sync_connections(self):
        # here we create one SanicMongo connection
        connect()

        class TestClass(Document):
            @metaprogramming.synchronize
            def some_method(self):
                self._get_collection()

        # here we create a sync connection
        TestClass().some_method()
        with monkey.MonkeyPatcher() as patcher:
            # the patcher will remove all pymongo connections
            patcher.patch_sync_connections()

            self.assertEqual(len(me_connection._connections), 1)

        self.assertEqual(len(me_connection._connections), 2)
Esempio n. 6
0
    def test_patch_dereference(self):
        with monkey.MonkeyPatcher() as patcher:
            patcher.patch_dereference()

        from mongoengine.dereference import DeReference
        self.assertIs(DeReference, monkey.SanicMongoDeReference)