Loading test/test_mssql.py +39 −1 Original line number Diff line number Diff line Loading @@ -6,15 +6,22 @@ from datetime import datetime from webbrowser import get from common.database import Database from common.mixins.mssql import MSSQLMixin from common.crud_table import CRUDTable from common.logz import create_logger logger = create_logger() class TestDBTable(CRUDTable): def __init__(self, db): columns = {'TestTableID': int, 'TestTableString': str} super().__init__(columns, 'dbo', db) class DBMSAzure(MSSQLMixin, Database): """ Create the Database with MSSQLMixin class. """ def __init__(self, **kwargs): super().__init__() self.TestDBTable = TestDBTable(self) def access(self): if DBMSAzure.is_open(self): Loading @@ -32,6 +39,37 @@ class DBMS_TestCase(unittest.TestCase): with DBMSAzure() as db: res = db.query("SELECT * FROM CommonDB.dbo.TestDBTable") self.assertEqual(len(res), 7) res = db.query("SELECT * FROM CommonDB.dbo.TestDBTable") class CRUDTable_MSSQLTestCase(unittest.TestCase): db = DBMSAzure() def test_all(self): # read all the data from the test table result = self.db.TestDBTable.read() # make sure the db was closed properly self.assertFalse(self.db.is_open()) # make sure the results from db are as expected self.assertTrue("pos" in result[0]) # attempt to delete the entry with id == 2 self.db.TestDBTable.delete(TestTableID=2) # make sure the db is closed self.assertFalse(self.db.is_open()) # create an entry with id == 2 self.db.TestDBTable.create(TestTableID=2, TestTableString="test_creation") # make sure the db is closed self.assertFalse(self.db.is_open()) # read the entry we created.. result = self.db.TestDBTable.read(TestTableString="test_creation") # make sure the db is closed self.assertFalse(self.db.is_open()) # make sure the results from db are as expected self.assertTrue("test_creation" in result[0]) # delete the entry we made self.db.TestDBTable.delete(id=2) # make sure the db is closed self.assertFalse(self.db.is_open()) if __name__ == "__main__": with DBMSAzure() as db: Loading Loading
test/test_mssql.py +39 −1 Original line number Diff line number Diff line Loading @@ -6,15 +6,22 @@ from datetime import datetime from webbrowser import get from common.database import Database from common.mixins.mssql import MSSQLMixin from common.crud_table import CRUDTable from common.logz import create_logger logger = create_logger() class TestDBTable(CRUDTable): def __init__(self, db): columns = {'TestTableID': int, 'TestTableString': str} super().__init__(columns, 'dbo', db) class DBMSAzure(MSSQLMixin, Database): """ Create the Database with MSSQLMixin class. """ def __init__(self, **kwargs): super().__init__() self.TestDBTable = TestDBTable(self) def access(self): if DBMSAzure.is_open(self): Loading @@ -32,6 +39,37 @@ class DBMS_TestCase(unittest.TestCase): with DBMSAzure() as db: res = db.query("SELECT * FROM CommonDB.dbo.TestDBTable") self.assertEqual(len(res), 7) res = db.query("SELECT * FROM CommonDB.dbo.TestDBTable") class CRUDTable_MSSQLTestCase(unittest.TestCase): db = DBMSAzure() def test_all(self): # read all the data from the test table result = self.db.TestDBTable.read() # make sure the db was closed properly self.assertFalse(self.db.is_open()) # make sure the results from db are as expected self.assertTrue("pos" in result[0]) # attempt to delete the entry with id == 2 self.db.TestDBTable.delete(TestTableID=2) # make sure the db is closed self.assertFalse(self.db.is_open()) # create an entry with id == 2 self.db.TestDBTable.create(TestTableID=2, TestTableString="test_creation") # make sure the db is closed self.assertFalse(self.db.is_open()) # read the entry we created.. result = self.db.TestDBTable.read(TestTableString="test_creation") # make sure the db is closed self.assertFalse(self.db.is_open()) # make sure the results from db are as expected self.assertTrue("test_creation" in result[0]) # delete the entry we made self.db.TestDBTable.delete(id=2) # make sure the db is closed self.assertFalse(self.db.is_open()) if __name__ == "__main__": with DBMSAzure() as db: Loading