def test_emit_system(self): """ This is a system test to check that handler.emit() reached windows event log. """ # Source name is static to know where to look at. # We will use event_id and content to identity an emited log. source_name = 'chevah-server-test-suite' # Unique string/number are only unique inside a single test run. # Since we interact with external system we need to generate # some more random values. event_id = random.randint(0, 50000) text = unicode(manufacture.uuid4()) handler = WindowsEventLogHandler(source_name) record = LogEntry(event_id, text) handler.emit(record) event = self.getWindowsEvent( source_name=source_name, event_id=event_id) # We got an event from our static source with a random ID. # Now check that content is right. self.assertEqual(1, len(event.StringInserts)) self.assertEqual(text, event.StringInserts[0])
def test_getMessageID_no_id(self): """ 1 is returned if log_entry/record does not have an id. """ source_name = manufacture.getUniqueString() handler = WindowsEventLogHandler(source_name) record = self.Bunch() result = handler.getMessageID(record) self.assertEqual(1, result)
def test_getMessageID_no_integer(self): """ 1 is returned if log_entry/record does not have a valid integer ID. """ source_name = manufacture.getUniqueString() handler = WindowsEventLogHandler(source_name) record = LogEntry('no_int', 'don-t care') result = handler.getMessageID(record) self.assertEqual(1, result)
def test_getMessageID_valid(self): """ The event id is returned if log_entry/record has a valid id. """ source_name = manufacture.getUniqueString() handler = WindowsEventLogHandler(source_name) record = self.Bunch(message_id='2') result = handler.getMessageID(record) self.assertEqual(2, result) # Let's try with an int. record = self.Bunch(message_id=3) result = handler.getMessageID(record) self.assertEqual(3, result)