def test_HtmlFileLoggerNoAppendTest(self):
        html_logger = HtmlFileLogger("", False, MessageType.INFORMATION,
                                     "WriteToHtmlFileLogger")
        html_logger.log_message(MessageType.WARNING, "Hello, this is a test.")

        file_path = html_logger.get_file_path(
        ) + "\\" + html_logger.get_file_name()
        self.assertTrue(path.exists(file_path))
 def test_HtmlFileLoggerLogMessage(self):
     html_logger = HtmlFileLogger("", True, MessageType.INFORMATION,
                                  "HtmlFileLoggerLogMessage")
     html_logger.log_message("Test to ensure LogMessage works as expected.")
     html_text = self.readTextFile(html_logger.get_file_path())
     # os.remove(html_logger.get_file_path())
     self.assertFalse(path.exists(html_logger.get_file_path()))
     self.assertTrue(self.Log_Message in html_text,
                     "Expected Log Message to be contained in log.")
    def test_WriteToExistingHtmlFileLogger(self):
        html_logger = HtmlFileLogger("", True, MessageType.GENERIC,
                                     "WriteToExistingHtmlFileLogger")
        html_logger.log_message(MessageType.WARNING, "This is a test.")
        html_logger.log_message(
            MessageType.WARNING,
            "This is a test to write to an existing file.")

        file_path = html_logger.get_file_path(
        ) + "\\" + html_logger.get_file_name()
        self.assertFalse(path.exists(file_path))
    def test_HtmlFileLoggerAppendFileTest(self):
        html_logger = HtmlFileLogger("", True, "WriteToExistingHtmlFileLogger")
        html_logger.log_message(
            MessageType.WARNING,
            "This is a test to write to an existing file.")
        html_logger.log_message(MessageType.WARNING,
                                "This is a test to append to current file.")

        file_path = html_logger.get_file_path(
        ) + "\\" + html_logger.get_file_name()
        self.assertTrue(path.exists(file_path))
    def test_HtmlFileLoggerCatchThrownException(self):
        html_logger = HtmlFileLogger(True, "",
                                     "HtmlFileLoggerCatchThrownException",
                                     MessageType.GENERIC)
        html_logger.set_file_path("<>")
        html_logger.log_message(MessageType.GENERIC,
                                "Test throws error as expected.")

        file_path = html_logger.get_file_path(
        ) + "\\" + html_logger.get_file_name()
        self.assertTrue(path.exists(file_path))
    def test_HtmlFileLoggerConstructorCreateDirectory(self):
        html_logger = HtmlFileLogger(True,
                                     LoggingConfig().get_log_directory(),
                                     "HtmlFileLoggerCreateDirectory",
                                     MessageType.GENERIC)
        html_logger.log_message(
            MessageType.WARNING,
            "Test to ensure that the file in the created directory can be written to."
        )
        file = html_logger.get_file_path()
        self.assertTrue(
            self.readTextFile(
                self.Test_Message in html_logger.get_file_path()))
        file.delete()
        self.assertTrue(path.exists(html_logger.get_file_path()))
        file = html_logger.get_directory()

        try:
            os.remove(file)
        except IOError as e:
            e.printStackTrace()