Example #1
0
    def test_context_multithreaded(self):
        conn = test_db.get_conn()
        evt = threading.Event()
        evt2 = threading.Event()

        def create():
            with test_db.execution_context() as ctx:
                database = ctx.database
                self.assertEqual(database.execution_context_depth(), 1)
                evt2.set()
                evt.wait()
                self.assertNotEqual(conn, ctx.connection)
                User.create(username='******')

        create_t = threading.Thread(target=create)
        create_t.daemon = True
        create_t.start()

        evt2.wait()
        self.assertEqual(test_db.execution_context_depth(), 0)
        evt.set()
        create_t.join()

        self.assertEqual(test_db.execution_context_depth(), 0)
        self.assertEqual(User.select().count(), 1)
    def test_context_multithreaded(self):
        conn = test_db.get_conn()
        evt = threading.Event()
        evt2 = threading.Event()

        def create():
            with test_db.execution_context() as ctx:
                database = ctx.database
                self.assertEqual(database.execution_context_depth(), 1)
                evt2.set()
                evt.wait()
                self.assertNotEqual(conn, ctx.connection)
                User.create(username='******')

        create_t = threading.Thread(target=create)
        create_t.daemon = True
        create_t.start()

        evt2.wait()
        self.assertEqual(test_db.execution_context_depth(), 0)
        evt.set()
        create_t.join()

        self.assertEqual(test_db.execution_context_depth(), 0)
        self.assertEqual(User.select().count(), 1)
Example #3
0
    def test_context_simple(self):
        with test_db.execution_context():
            User.create(username="******")
            self.assertEqual(test_db.execution_context_depth(), 1)
        self.assertEqual(test_db.execution_context_depth(), 0)

        with test_db.execution_context():
            self.assertTrue(User.select().where(User.username == "charlie").exists())
            self.assertEqual(test_db.execution_context_depth(), 1)
        self.assertEqual(test_db.execution_context_depth(), 0)
        queries = self.queries()
    def test_context_simple(self):
        with test_db.execution_context():
            User.create(username='******')
            self.assertEqual(test_db.execution_context_depth(), 1)
        self.assertEqual(test_db.execution_context_depth(), 0)

        with test_db.execution_context():
            self.assertTrue(
                User.select().where(User.username == 'charlie').exists())
            self.assertEqual(test_db.execution_context_depth(), 1)
        self.assertEqual(test_db.execution_context_depth(), 0)
        queries = self.queries()
Example #5
0
    def test_context_ext(self):
        with test_db.execution_context():
            with test_db.execution_context() as inner_ctx:
                with test_db.execution_context():
                    User.create(username="******")
                    self.assertEqual(test_db.execution_context_depth(), 3)

                conn = test_db.get_conn()
                self.assertEqual(conn, inner_ctx.connection)

                self.assertTrue(User.select().where(User.username == "huey").exists())

        self.assertEqual(test_db.execution_context_depth(), 0)
    def test_context_ext(self):
        with test_db.execution_context():
            with test_db.execution_context() as inner_ctx:
                with test_db.execution_context():
                    User.create(username='******')
                    self.assertEqual(test_db.execution_context_depth(), 3)

                conn = test_db.get_conn()
                self.assertEqual(conn, inner_ctx.connection)

                self.assertTrue(
                    User.select().where(User.username == 'huey').exists())

        self.assertEqual(test_db.execution_context_depth(), 0)