def setUp(self): """Sets up the objects needed for this test.""" self._output_writer = cli_test_lib.TestOutputWriter() output_mediator = self._CreateOutputMediator() self._output_module = tln.TLNOutputModule( output_mediator, output_writer=self._output_writer) self._event_object = TLNTestEvent()
def testWriteEventBody(self): """Tests the WriteEventBody function.""" test_file_object = io.StringIO() output_mediator = self._CreateOutputMediator() formatters_directory_path = self._GetTestFilePath(['formatters']) output_mediator.ReadMessageFormattersFromDirectory( formatters_directory_path) output_module = tln.TLNOutputModule(output_mediator) output_module._file_object = test_file_object event, event_data, event_data_stream = ( containers_test_lib.CreateEventFromValues(self._TEST_EVENTS[0])) output_module.WriteEventBody( event, event_data, event_data_stream, event_data_stream) expected_event_body = ( '1340821021|FILE|ubuntu|root|2012-06-27T18:17:01.000000+00:00; ' 'Unknown Time; ' 'Reporter <CRON> PID: 8442 (pam_unix(cron:session): ' 'session closed for user root)\n') event_body = test_file_object.getvalue() self.assertEqual(event_body, expected_event_body) self.assertEqual(event_body.count('|'), 4)
def setUp(self): """Makes preparations before running an individual test.""" self._output_writer = cli_test_lib.TestOutputWriter() output_mediator = self._CreateOutputMediator() self._output_module = tln.TLNOutputModule(output_mediator) self._output_module.SetOutputWriter(self._output_writer) self._event_object = test_lib.TestEventObject()
def testWriteHeader(self): """Tests the WriteHeader function.""" test_file_object = io.StringIO() output_mediator = self._CreateOutputMediator() output_module = tln.TLNOutputModule(output_mediator) output_module._file_object = test_file_object output_module.WriteHeader() header = test_file_object.getvalue() self.assertEqual(header, 'Time|Source|Host|User|Description\n')