Passed
Push — master ( e601a7...eb7115 )
by Humberto
02:04 queued 14s
created

TestWebSocketLog.test_no_requests_logging()   A

Complexity

Conditions 1

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nop 1
dl 0
loc 22
rs 9.8
c 0
b 0
f 0
1
"""Test kytos.core.websocket module."""
2
import logging
3
from copy import copy
4
from unittest import TestCase
5
from unittest.mock import Mock
6
7
from kytos.core.logs import LogManager
8
9
10
class TestWebSocketLog(TestCase):
11
    """Test special requirements for web socket logging."""
12
13
    def test_no_requests_logging(self):
14
        """Should not log web requests to avoid an infinite logging loop.
15
16
        Do not log any level below warning.
17
        """
18
        # Save original state
19
        handlers_bak = copy(logging.root.handlers)
20
21
        logging.root.handlers = []
22
        socket = Mock()
23
        LogManager.enable_websocket(socket)
24
        # Lower logger level simulating logging.ini config
25
        web_logger = logging.getLogger('werkzeug')
26
        web_logger.setLevel(logging.DEBUG)
27
28
        web_logger.info('should not log')
29
        self.assertEqual(0, socket.call_count)
30
        web_logger.warning('should log')
31
        self.assertEqual(1, socket.emit.call_count)
32
33
        # Restore original state
34
        logging.root.handlers = handlers_bak
35