Esempio n. 1
0
    def test_fatal_when_emit(self, collectd):
        # Given
        handler = CollectdLogHandler(collectd=collectd)
        record = make_record(msg="message", level=logging.FATAL)

        # When a fatal record is emitted
        handler.emit(record=record)

        # Then error hook is called
        collectd.error.assert_called_once_with("message")
Esempio n. 2
0
    def test_warning_when_emit(self, collectd):
        # Given
        handler = CollectdLogHandler(collectd=collectd)
        record = make_record(msg="message", level=logging.WARNING)

        # When a warning record is emitted
        handler.emit(record=record)

        # Then info warning is called
        collectd.warning.assert_called_once_with("message")
Esempio n. 3
0
    def test_info_when_emit(self, collectd):
        # Given
        handler = CollectdLogHandler(collectd=collectd)
        record = make_record(msg="message", level=logging.INFO)

        # When an info record is emitted
        handler.emit(record=record)

        # Then info hook is called
        collectd.info.assert_called_once_with("message")
Esempio n. 4
0
    def test_verbose_debug_when_emit(self, collectd):
        # Given
        handler = CollectdLogHandler(collectd=collectd)
        handler.verbose = True
        record = make_record(msg="message", level=logging.DEBUG)

        # When an info record is emitted
        handler.emit(record=record)

        # Then info hook is called
        collectd.info.assert_called_once_with("message")
Esempio n. 5
0
    def test_debug_when_emit(self, collectd):

        # Given
        handler = CollectdLogHandler(collectd=collectd)
        record = make_record(msg="message", level=logging.DEBUG)

        # When a debug record is emitted
        handler.emit(record=record)

        # Then debug hook is called
        collectd.debug.assert_called_once_with("message")
Esempio n. 6
0
    def test_long_message_when_emit(self, collectd):
        # Given
        long_message = "LONG " * 20 + "MESSAGE."
        handler = CollectdLogHandler(collectd=collectd)
        handler.max_message_length = 10
        record = make_record(msg=long_message)

        # When a long message is emitted
        handler.emit(record=record)

        # Then info hook is called n times with split message
        collectd.info.assert_has_calls([
            mock.call(long_message[i:i + 10])
            for i in range(0, len(long_message), 10)
        ])