Commit ac9293aa authored by Hamaker, Alec's avatar Hamaker, Alec
Browse files

Added unit tests for pandas

parent f40d89f1
Loading
Loading
Loading
Loading
+44 −29
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ from datetime import datetime
from webbrowser import get
from common.database import Database
from common.mixins.postgres import PostgresMixin
from common.mixins.pandas import PandasMixin
from common.mixins.mssql import MSSQLMixin
from common.mixins.postgres_logger import PostgresLoggerMixin
from common.logz import create_logger
@@ -267,35 +268,49 @@ class LogzTestCase(unittest.TestCase):
        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])
        send_email("TESTING RECIPIENT FIELD", "TEST RECIPENT FIELD", 
                    recipients='huihuijk@ornl.gov')
        #send_email("TESTING RECIPIENT FIELD MULTI ADDRESS", "TEST RECIPENT FIELD", 
        #            recipients='huihuijk@ornl.gov, jonathanhuihui@yahoo.com, jonathankhuihui@gmail.com')
# 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])
#         send_email("TESTING RECIPIENT FIELD", "TEST RECIPENT FIELD", 
#                     recipients='huihuijk@ornl.gov')
#         #send_email("TESTING RECIPIENT FIELD MULTI ADDRESS", "TEST RECIPENT FIELD", 
#         #            recipients='huihuijk@ornl.gov, jonathanhuihui@yahoo.com, jonathankhuihui@gmail.com')


class PandasTestCase(unittest.TestCase):
    class PandasDB(Database, PostgresMixin, PandasMixin):
        """Class to query postgresdb with pandas"""

    def test_query_pandas(self):
        with self.PandasDB() as db:
            # Query the database to get a dataframe
            df = db.query_pandas(query="SELECT * FROM public.test_table",
                                 table="test_table", schema="public")
            # Ensure the dataframe as expected values
            self.assertTrue(1 in df['id'].values)
            self.assertTrue("hello_world" in df['test_string'].values)


if __name__ == "__main__":