예제 #1
0
    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?')
예제 #2
0
    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")
예제 #3
0
def send(message, settings):
    print timestampize(message)
예제 #4
0
def send(message, settings):
    with open(settings['FILE_SAVE'], 'a') as logfile:
        logfile.write(timestampize(message))
        logfile.write("\n")