Loading test/test.py +67 −26 Original line number Diff line number Diff line Loading @@ -14,14 +14,55 @@ from common.mixins.mssql import MSSQLMixin from common.mixins.postgres_logger import PostgresLoggerMixin from common.logz import create_logger from common.mail import send_email from common.crud_table import CRUDTable class test_table(CRUDTable): def __init__(self, db): columns = {'id': int, 'test_string': str} super().__init__(columns, 'public', db) class DBPG(Database, PostgresMixin): """Create the Database and PostgresMixin class.""" def __init__(self): super().__init__() self.test_table = test_table(self) class DBMSAzure(MSSQLMixin, Database): """Create the Database and MSSQLMixin class.""" class CRUDTable_PGTestCase(unittest.TestCase): db = DBPG() def test_all(self): # read all the data from the test table result = self.db.test_table.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("hello_world" in result[0]) # attempt to delete the entry with id == 2 self.db.test_table.delete(id=2) # make sure the db is closed self.assertFalse(self.db.is_open()) # create an entry with id == 2 self.db.test_table.create(id=2, test_string="test_creation") # make sure the db is closed self.assertFalse(self.db.is_open()) # read the entry we created.. result = self.db.test_table.read(test_string="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.test_table.delete(id=2) # make sure the db is closed self.assertFalse(self.db.is_open()) class PostgresTestCase(unittest.TestCase): """Test the Postgres connection case.""" def test_open(self): Loading Loading @@ -225,32 +266,32 @@ class LogzTestCase(unittest.TestCase): # test empty list: plm.write_log_collection_to_database() class MailTestCase(unittest.TestCase): """MailTestCase.""" def test_send_email(self): """Test to make sure that then send_mail function can actually send mail""" send_email("TEST SUBJECT", "THIS IS A TEST MESSAGE") def test_send_email_attachment(self): """Test to make sure that we can send attachments..""" ATTACHMENT_PATHS = ["/test/test_attachments/test_attachment.txt", "/test/test_attachments/test_attachment2.txt"] ATTACHMENT_PATHS_W_BAD_FILE = [ "/test/test_attachments/test_attachment.txt", "/this/is/not/a/real/file/path.txt"] send_email( "TEST SUBJECT WITH ATTACHMENT", "THIS IS A TEST MESSAGE", files=[ATTACHMENT_PATHS[0]] ) send_email("TEST SUBJECT MULTI-ATTACHMENTS", "TEST MESSAGE", files=ATTACHMENT_PATHS) send_email("TEST SUBJECT WITH BAD PATH", "TEST MESSAGE", files=ATTACHMENT_PATHS_W_BAD_FILE) send_email("TEST SUBJECT WITH STRING FILE PATH", "TEST MESSAGE", files=ATTACHMENT_PATHS[0]) # class MailTestCase(unittest.TestCase): # """MailTestCase.""" # # def test_send_email(self): # """Test to make sure that then send_mail function can actually send # mail""" # send_email("TEST SUBJECT", "THIS IS A TEST MESSAGE") # # def test_send_email_attachment(self): # """Test to make sure that we can send attachments..""" # ATTACHMENT_PATHS = ["/test/test_attachments/test_attachment.txt", # "/test/test_attachments/test_attachment2.txt"] # ATTACHMENT_PATHS_W_BAD_FILE = [ # "/test/test_attachments/test_attachment.txt", # "/this/is/not/a/real/file/path.txt"] # send_email( # "TEST SUBJECT WITH ATTACHMENT", "THIS IS A TEST MESSAGE", # files=[ATTACHMENT_PATHS[0]] # ) # send_email("TEST SUBJECT MULTI-ATTACHMENTS", "TEST MESSAGE", # files=ATTACHMENT_PATHS) # send_email("TEST SUBJECT WITH BAD PATH", "TEST MESSAGE", # files=ATTACHMENT_PATHS_W_BAD_FILE) # send_email("TEST SUBJECT WITH STRING FILE PATH", "TEST MESSAGE", # files=ATTACHMENT_PATHS[0]) if __name__ == "__main__": unittest.main(verbosity=2) Loading
test/test.py +67 −26 Original line number Diff line number Diff line Loading @@ -14,14 +14,55 @@ from common.mixins.mssql import MSSQLMixin from common.mixins.postgres_logger import PostgresLoggerMixin from common.logz import create_logger from common.mail import send_email from common.crud_table import CRUDTable class test_table(CRUDTable): def __init__(self, db): columns = {'id': int, 'test_string': str} super().__init__(columns, 'public', db) class DBPG(Database, PostgresMixin): """Create the Database and PostgresMixin class.""" def __init__(self): super().__init__() self.test_table = test_table(self) class DBMSAzure(MSSQLMixin, Database): """Create the Database and MSSQLMixin class.""" class CRUDTable_PGTestCase(unittest.TestCase): db = DBPG() def test_all(self): # read all the data from the test table result = self.db.test_table.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("hello_world" in result[0]) # attempt to delete the entry with id == 2 self.db.test_table.delete(id=2) # make sure the db is closed self.assertFalse(self.db.is_open()) # create an entry with id == 2 self.db.test_table.create(id=2, test_string="test_creation") # make sure the db is closed self.assertFalse(self.db.is_open()) # read the entry we created.. result = self.db.test_table.read(test_string="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.test_table.delete(id=2) # make sure the db is closed self.assertFalse(self.db.is_open()) class PostgresTestCase(unittest.TestCase): """Test the Postgres connection case.""" def test_open(self): Loading Loading @@ -225,32 +266,32 @@ class LogzTestCase(unittest.TestCase): # test empty list: plm.write_log_collection_to_database() class MailTestCase(unittest.TestCase): """MailTestCase.""" def test_send_email(self): """Test to make sure that then send_mail function can actually send mail""" send_email("TEST SUBJECT", "THIS IS A TEST MESSAGE") def test_send_email_attachment(self): """Test to make sure that we can send attachments..""" ATTACHMENT_PATHS = ["/test/test_attachments/test_attachment.txt", "/test/test_attachments/test_attachment2.txt"] ATTACHMENT_PATHS_W_BAD_FILE = [ "/test/test_attachments/test_attachment.txt", "/this/is/not/a/real/file/path.txt"] send_email( "TEST SUBJECT WITH ATTACHMENT", "THIS IS A TEST MESSAGE", files=[ATTACHMENT_PATHS[0]] ) send_email("TEST SUBJECT MULTI-ATTACHMENTS", "TEST MESSAGE", files=ATTACHMENT_PATHS) send_email("TEST SUBJECT WITH BAD PATH", "TEST MESSAGE", files=ATTACHMENT_PATHS_W_BAD_FILE) send_email("TEST SUBJECT WITH STRING FILE PATH", "TEST MESSAGE", files=ATTACHMENT_PATHS[0]) # class MailTestCase(unittest.TestCase): # """MailTestCase.""" # # def test_send_email(self): # """Test to make sure that then send_mail function can actually send # mail""" # send_email("TEST SUBJECT", "THIS IS A TEST MESSAGE") # # def test_send_email_attachment(self): # """Test to make sure that we can send attachments..""" # ATTACHMENT_PATHS = ["/test/test_attachments/test_attachment.txt", # "/test/test_attachments/test_attachment2.txt"] # ATTACHMENT_PATHS_W_BAD_FILE = [ # "/test/test_attachments/test_attachment.txt", # "/this/is/not/a/real/file/path.txt"] # send_email( # "TEST SUBJECT WITH ATTACHMENT", "THIS IS A TEST MESSAGE", # files=[ATTACHMENT_PATHS[0]] # ) # send_email("TEST SUBJECT MULTI-ATTACHMENTS", "TEST MESSAGE", # files=ATTACHMENT_PATHS) # send_email("TEST SUBJECT WITH BAD PATH", "TEST MESSAGE", # files=ATTACHMENT_PATHS_W_BAD_FILE) # send_email("TEST SUBJECT WITH STRING FILE PATH", "TEST MESSAGE", # files=ATTACHMENT_PATHS[0]) if __name__ == "__main__": unittest.main(verbosity=2)