def setUp(self): """Sets up the objects needed for this test.""" output_mediator = self._CreateOutputMediator() self._output_writer = cli_test_lib.TestOutputWriter() self._output_module = rawpy.NativePythonOutputModule(output_mediator) self._output_module.SetOutputWriter(self._output_writer) self._event_object = test_lib.TestEventObject()
def setUp(self): """Makes preparations before running an individual test.""" output_mediator = self._CreateOutputMediator() self._output_writer = cli_test_lib.TestOutputWriter() self._output_module = rawpy.NativePythonOutputModule(output_mediator) self._output_module.SetOutputWriter(self._output_writer) self._event_object = test_lib.TestEventObject()
def testWriteEventBody(self): """Tests the WriteEventBody function.""" test_file_object = io.StringIO() output_mediator = self._CreateOutputMediator() output_module = rawpy.NativePythonOutputModule(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, None) if sys.platform.startswith('win'): # The dict comparison is very picky on Windows hence we # have to make sure the drive letter is in the same case. expected_os_location = os.path.abspath('\\{0:s}'.format( os.path.join('cases', 'image.dd'))) else: expected_os_location = '{0:s}{1:s}'.format( os.path.sep, os.path.join('cases', 'image.dd')) expected_event_body = ( '+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-' '+-+-+-+-+-+-\n' '[Timestamp]:\n' ' 2012-06-27T18:17:01.000000Z\n' '\n' '[Pathspec]:\n' ' type: OS, location: {0:s}\n' ' type: TSK, inode: 15, location: /var/log/syslog.1\n' '\n' '[Reserved attributes]:\n' ' {{data_type}} test:output\n' ' {{display_name}} TSK:/var/log/syslog.1\n' ' {{filename}} /var/log/syslog.1\n' ' {{hostname}} ubuntu\n' ' {{inode}} 15\n' ' {{username}} root\n' '\n' '[Additional attributes]:\n' ' {{text}} Reporter <CRON> PID: |8442| (pam_unix(cron:session): ' 'session\n' ' closed for user root)\n' '\n').format(expected_os_location) event_body = test_file_object.getvalue() # Compare the output as list of lines which makes it easier to spot # differences. self.assertEqual(event_body.split('\n'), expected_event_body.split('\n'))