コード例 #1
0
 def test_logMessage_output_unpredictable_shared(self):
     """
         GIVEN I instantiate an instance of LogMessage
         WHEN I request a predictable unique log message to be shared
             Unique = "Y"
              Shared = 'Y"
         THEN each message from the output_string function
         should be unique and contain a random string
         It should also be the same for subsequent runs
     """
     logger1 = log_message.LogMessage("1", "Y", "Y", "Random2 Message",
                                      "10", "5")
     logger2 = log_message.LogMessage("1", "Y", "Y", "Random2 Message",
                                      "10", "5")
     self.assertEqual(logger1.output_string(), logger2.output_string())
     self.assertEqual(logger1.output_string(), logger2.output_string())
コード例 #2
0
    def test_logMessage_output_unpredictable_single(self):
        """
            GIVEN I instantiate an instance of LogMessage
            WHEN rquest a predictable unique log message
            Unique = "Y"
            Shared = 'N"
            THEN each message from the output_string function
            should be unique and contain a random string
        """
        logger1 = log_message.LogMessage("1", "Y", "N", "Random1 Message",
                                         "10", "5")
        logger2 = log_message.LogMessage("1", "Y", "N", "Random1 Message",
                                         "10", "5")
        result1 = logger1.output_string()
        time.sleep(1)
        result2 = logger2.output_string()

        self.assertNotEqual(result1, result2)
コード例 #3
0
 def test_logMessage_output_predict_single(self):
     """
         GIVEN I instantiate an instance of LogMessage
         WHEN rquest a predictable non-unique log message
         Unique = "N"
         Shared = 'N"
         THEN each message from the output_string function
         should be predictable and not contain a random string
     """
     result = log_message.LogMessage("0", "N", "N", "Error Message", "10",
                                     "5")
     self.assertEqual("Error Message", result.output_string())
コード例 #4
0
 def test_logMessage_validation_fail_message_type(self):
     """
         GIVEN I instantiate an instance of LogMessage
         WHEN I supply an invalid message_type value of 2
         THEN validation will fail and state that:
         "log entry:message_type must be 0 or 1"
     """
     result = None
     with self.assertRaises(Exception) as context:
         result = log_message.LogMessage("2", "Y:seed1", "Y",
                                         "Error Message", "10", "5")
     self.assertIsNone(result)
     self.assertEqual(
         "invalid parameters used to create" +
         " log entry:message_type must be 0 or 1", str(context.exception))
コード例 #5
0
 def test_logMessage_validation_fail_max_count(self):
     """
         GIVEN I instantiate an instance of LogMessage
         WHEN I supply an invalid value for the "max count" flag
         value = "N"
         THEN validation will fail and state that:
         "frequency and max_count must be positive integers"
     """
     result = None
     with self.assertRaises(Exception) as context:
         result = log_message.LogMessage("0", "Y:seed1", "Y",
                                         "Error Message", "10", "N")
     self.assertIsNone(result)
     self.assertEqual(
         "invalid parameters used to create log entry:" +
         " max_count must be a positive integer", str(context.exception))
コード例 #6
0
 def test_logMessage_validation_fail_unique(self):
     """
         GIVEN I instantiate an instance of LogMessage
         WHEN I supply an invalid value for the "unique" flag
         N:seed1
         THEN validation will fail and state that:
         "Supplied value is : N:SEED1 Expected Y|N
         with optional :seed for Y"
     """
     result = None
     with self.assertRaises(Exception) as context:
         result = log_message.LogMessage("0", "N:seed1", "Y",
                                         "Error Message", "10", "5")
     self.assertIsNone(result)
     self.assertEqual(
         "Invalid value for UNIQUE flag," +
         " Supplied value is : N:SEED1 Expected Y|N" +
         " with optional :seed for Y", str(context.exception))
コード例 #7
0
 def test_logMessage_validation_ok(self):
     """
         GIVEN I supply valid values for all message parameters
         WHEN I supply all valid values
         THEN no validation errors will be picked up
     """
     try:
         result = log_message.LogMessage("0", "Y:seed1", "Y",
                                         "Error Message", "10", "5")
         self.assertEqual(0, result.message_type)
         self.assertEqual('Y', result.unique)
         self.assertEqual('SEED1', result.seed)
         self.assertEqual('Error Message', result.message_text)
         self.assertEqual(10, result.frequency)
         self.assertEqual(5, result.max_count)
         self.assertEqual(0, result.counter)
     except Exception:
         self.assertTrue("Raised an exception and it should not have")
コード例 #8
0
    def test_logMessage_validation_fail_multiple(self):
        """
            GIVEN I instantiate an instance of LogMessage
            WHEN I supply multiple invalid values
            message_type = "n"
            max_count = 'N"
            THEN validation will fail and state multiple issues:
            "frequency and max_count must be positive integers"
            ""message_type must be 0 or 1"

        """
        result = None
        with self.assertRaises(Exception) as context:
            result = log_message.LogMessage("n", "Y:seed1", "Y",
                                            "Error Message", "10", "N")
        self.assertIsNone(result)
        self.assertEqual(
            "invalid parameters used to create log entry:" +
            " max_count must be a positive integer\n" +
            "message_type must be 0 or 1", str(context.exception))