def test_drop_tables(self): """ Make sure the tables are dropped. """ self.assertEqual(Manager.table_exists().run_sync(), True) self.assertEqual(Band.table_exists().run_sync(), True) drop_tables(Manager, Band) self.assertEqual(Manager.table_exists().run_sync(), False) self.assertEqual(Band.table_exists().run_sync(), False)
def test_succeeds(self): async def run_transaction(): async with Band._meta.db.transaction(): await Manager.create_table().run() await Band.create_table().run() asyncio.run(run_transaction()) self.assertTrue(Band.table_exists().run_sync()) self.assertTrue(Manager.table_exists().run_sync())
def test_succeeds(self): transaction = Band._meta.db.atomic() transaction.add(Manager.create_table(), Band.create_table()) transaction.run_sync() self.assertTrue(Band.table_exists().run_sync()) self.assertTrue(Manager.table_exists().run_sync()) transaction.add(Band.alter().drop_table(), Manager.alter().drop_table()) transaction.run_sync()
def test_error(self): """ Make sure queries in a transaction aren't committed if a query fails. """ transaction = Band._meta.db.atomic() transaction.add( Manager.create_table(), Band.create_table(), Band.raw("MALFORMED QUERY ... SHOULD ERROR"), ) try: transaction.run_sync() except Exception: pass self.assertTrue(not Band.table_exists().run_sync()) self.assertTrue(not Manager.table_exists().run_sync())
def test_error(self): """ Make sure queries in a transaction aren't committed if a query fails. """ async def run_transaction(): try: async with Band._meta.db.transaction(): Manager.create_table() Band.create_table() Band.raw("MALFORMED QUERY ... SHOULD ERROR") except Exception: pass asyncio.run(run_transaction()) self.assertTrue(not Band.table_exists().run_sync()) self.assertTrue(not Manager.table_exists().run_sync())
def test_table_exists(self): response = Manager.table_exists().run_sync() self.assertTrue(response)
def test_create_table(self): Manager.create_table().run_sync() self.assertTrue(Manager.table_exists().run_sync()) Manager.alter().drop_table().run_sync()
def test_create_tables(self): create_tables(Manager, Band, if_not_exists=False) self.assertTrue(Manager.table_exists().run_sync()) self.assertTrue(Band.table_exists().run_sync())