def test_log_message(self):
        # Silence the django.server logger by replacing its StreamHandler with
        # NullHandler.
        logger = logging.getLogger('django.server')
        original_handlers = logger.handlers
        logger.handlers = [logging.NullHandler()]
        try:
            request = WSGIRequest(RequestFactory().get('/').environ)
            request.makefile = lambda *args, **kwargs: BytesIO()
            handler = WSGIRequestHandler(request, '192.168.0.2', None)
            level_status_codes = {
                'info': [200, 301, 304],
                'warning': [400, 403, 404],
                'error': [500, 503],
            }

            def _log_level_code(level, status_code):
                with patch_logger('django.server', level) as messages:
                    handler.log_message('GET %s %s', 'A', str(status_code))
                return messages

            for level, status_codes in level_status_codes.items():
                for status_code in status_codes:
                    # The correct level gets the message.
                    messages = _log_level_code(level, status_code)
                    self.assertIn('GET A %d' % status_code, messages[0])

                    # Incorrect levels shouldn't have any messages.
                    for wrong_level in level_status_codes.keys():
                        if wrong_level != level:
                            messages = _log_level_code(wrong_level, status_code)
                            self.assertEqual(len(messages), 0)
        finally:
            logger.handlers = original_handlers
dataset/ETHPy150Open django/django/tests/servers/test_basehttp.py/WSGIRequestHandlerTestCase.test_log_message/original