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_HtmlFileLoggerSetFilePath(self):
     html_logger = HtmlFileLogger("", True, MessageType.GENERIC,
                                  "HtmlFileLoggerSetFilePath")
     html_logger.set_file_path("test file path")
     file_path = html_logger.get_file_path()
     # os.remove(html_logger.get_file_path())
     self.assertFalse(path.exists(html_logger.get_file_path()))
     self.assertEquals(file_path, "test file path",
                       "Expected 'test file path' as file path")
 def test_HierarchicalHtmlFileLogger(self):
     log_level, levels = self.data()
     html_logger = HtmlFileLogger(
         True,
         LoggingConfig().get_log_directory(),
         self.get_file_name(self._testMethodName + log_level, "html"),
         MessageType.GENERIC.value)
     self.hierarchical_logging(html_logger, html_logger.get_file_path(),
                               log_level, levels)
     os.remove(html_logger.get_file_path())
     self.assertTrue(path.exists(html_logger.get_file_path()))
    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_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()
    def test_FileLoggerMessageTypeOnly(self):
        html_logger = HtmlFileLogger("", False, MessageType.WARNING)
        self.assertEquals(
            html_logger.DEFAULT_LOG_FOLDER, html_logger.get_directory(),
            StringProcessor.safe_formatter("Expected Directory '{}'.",
                                           html_logger.DEFAULT_LOG_FOLDER))
        self.assertEquals("FileLog.html", html_logger.get_file_name(),
                          "Expected correct File Name.")
        self.assertEquals(MessageType.WARNING, html_logger.get_message_type(),
                          "Expected Warning Message Type.")

        file_path = html_logger.get_file_path(
        ) + "\\" + html_logger.get_file_name()
        self.assertTrue(path.exists(file_path))
    def test_FileLoggerAppendOnly(self):
        html_logger = HtmlFileLogger("", True)
        self.assertEquals(
            html_logger.DEFAULT_LOG_FOLDER, html_logger.get_directory(),
            StringProcessor.safe_formatter("Expected Directory '{}'.",
                                           html_logger.DEFAULT_LOG_FOLDER))
        self.assertEquals("FileLog.html", html_logger.get_file_name(),
                          "Expected correct File Name.")
        self.assertEquals(MessageType.INFORMATION.name,
                          html_logger.get_message_type(),
                          "Expected Information Message Type.")

        file_path = html_logger.get_file_path(
        ) + "\\" + html_logger.get_file_name()
        self.assertFalse(path.exists(file_path))
    def test_FileLoggerAppendLogFolderMessagingLevel(self):
        append_log_folder_file_name_directory = LoggingConfig.get_log_directory() + "\\" \
                                                + "AppendLogFolderFileNameDirectory "
        html_logger = HtmlFileLogger(append_log_folder_file_name_directory,
                                     True, MessageType.WARNING)
        self.assertEquals(
            append_log_folder_file_name_directory, html_logger.get_directory(),
            "Expected Directory AppendLogFolderFileNameDirectory")
        self.assertEquals("FileLog.html", html_logger.get_file_name(),
                          "Expected correct File Name.")
        self.assertEquals(MessageType.WARNING.name,
                          html_logger.get_message_type(),
                          "Expected Warning Message Type.")

        file_path = html_logger.get_file_path(
        ) + "\\" + html_logger.get_file_name()
        self.assertFalse(path.exists(file_path))
    def test_FileLoggerLogFolderFileNameMessagingLevel(self):
        log_folder_file_name_messaging_level_directory_path = LoggingConfig.get_log_directory() \
                                                              + "/" + "LogFolderFileNameMessagingLevelDirectory"
        html_logger = HtmlFileLogger(
            log_folder_file_name_messaging_level_directory_path,
            "LogFolderFileNameMessagingLevel.html", MessageType.WARNING)
        self.assertEquals(
            log_folder_file_name_messaging_level_directory_path,
            html_logger.get_directory(),
            "Expected Directory 'LogFolderFileNameMessagingLevelDirectory'")
        self.assertEquals("LogFolderFileNameMessagingLevel.html",
                          html_logger.get_file_name(),
                          "Expected correct File Name.")
        self.assertEquals(MessageType.WARNING, html_logger.get_message_type(),
                          "Expected Warning Message Type.")

        file_path = html_logger.get_file_path(
        ) + "\\" + html_logger.get_file_name()
        self.assertTrue(path.exists(file_path))