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()
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)
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='******')
def create(i): with test_db.execution_context(): with test_db.execution_context() as ctx: User.create(username='******' % i) self.assertEqual(ctx.database.execution_context_depth(), 2)