def test_timestampize(self, mock_strftime): text = "line1\nline2\nline3" mock_strftime.return_value = '2014-05-13 21:00:00' text_timestamped = timestampize(text) self.assertEqual(text_timestamped, '[2014-05-13 21:00:00] line1\n[2014-05-13 21:00:00] line2\n[2014-05-13 21:00:00] line3', 'Timestampize returns result in wrong format. No timestamps?')
def test_sender_file(self, mock_strftime): mo = mock.mock_open() test_message = 'This is a test message.' mock_strftime.return_value = '2014-05-13 21:00:00' with mock.patch('senders.file.open', mo, create=True): s_file.send(message=test_message, settings=settings_default) mo.assert_called_once_with(settings_default['FILE_SAVE'], 'a') mo().write.assert_any_call(timestampize(test_message)) mo().write.assert_any_call("\n")
def send(message, settings): print timestampize(message)
def send(message, settings): with open(settings['FILE_SAVE'], 'a') as logfile: logfile.write(timestampize(message)) logfile.write("\n")