def test_database_tableexists(self): """ Makes sure that database.tableexists functions the same as the base sql.Table.tableexists function """ ## Real table tablename = "testtable" ## This will fail automatically if table doesn't exist table = self.connection.gettable(tablename) self.assertEqual(self.connection.tableexists(tablename), Table.tableexists(self.connection, tablename)) ## Fake Table tablename = "notarealtable" self.assertRaises(ValueError, self.connection.gettable, tablename) self.assertEqual(self.connection.tableexists(tablename), Table.tableexists(self.connection, tablename))
def tableexists(self,tablename): """ Tests that a table exists """ if isinstance(tablename,(Table.Table,Table.TableConstructor)): tablename = tablename.fullname if not isinstance(tablename,str): raise ValueError("tablename must be a string or a table") return Table.tableexists(self,tablename)
def test_removetable(self): """ Tests that remove table can remove a table based on its table name """ tablename = "testtable" ## This will fail if the table was not already created (thus rendering this test invalid) self.connection.gettable(tablename) self.connection.removetable(tablename) self.assertFalse(Table.tableexists(self.connection, tablename)) self.assertRaisesRegex(ValueError, "Table .* does not exist", self.connection.gettable, tablename)
def test_removetable_object(self): """ Tests that tables can be removed using Tables and Table Subclasses """ for table in [ self.connection.gettable("testtable"), self.connection.getadvancedtable("testtable") ]: with self.subTest(table=table): self.connection.removetable(table) self.assertFalse(Table.tableexists(self.connection, table)) self.assertRaisesRegex(ValueError, "Table .* does not exist", self.connection.gettable, table)
def test_tableexists_object(self): """ Tests that tableexists accepts Tables and Table Subclasses """ for table in [self.connection.gettable("testtable"), self.connection.getadvancedtable("testtable")]: self.assertTrue(Table.tableexists(self.connection,table))
def test_tableexists(self): """ Tests that tableexists works as expected""" self.assertTrue(Table.tableexists(self.connection,"testtable"))
def test_remove(self): """ Tests that AdvancedTables can use their parents to remove themselves """ table = self.connection.getadvancedtable("testtable") table.remove() self.assertFalse(Table.tableexists(self.connection,table),table) self.assertRaisesRegex(ValueError,"Table .* does not exist.",self.connection.gettable,table)