Exemplo n.º 1
0
    def test_log_message(self):
        request = WSGIRequest(RequestFactory().get('/').environ)
        request.makefile = lambda *args, **kwargs: BytesIO()
        handler = WSGIRequestHandler(request, '192.168.0.2', None)

        with captured_stderr() as stderr:
            handler.log_message('GET %s %s', 'A', 'B')
        self.assertIn('] GET A B', stderr.getvalue())
    def test_log_message(self):
        request = WSGIRequest(RequestFactory().get('/').environ)
        request.makefile = lambda *args, **kwargs: BytesIO()
        handler = WSGIRequestHandler(request, '192.168.0.2', None)

        with captured_stderr() as stderr:
            handler.log_message('GET %s %s', 'A', 'B')
        self.assertIn('] GET A B', stderr.getvalue())
Exemplo n.º 3
0
    def test_https(self):
        request = WSGIRequest(RequestFactory().get('/').environ)
        request.makefile = lambda *args, **kwargs: BytesIO()

        handler = WSGIRequestHandler(request, '192.168.0.2', None)

        with captured_stderr() as stderr:
            handler.log_message("GET %s %s", str('\x16\x03'), "4")
            self.assertIn(
                "You're accessing the development server over HTTPS, "
                "but it only supports HTTP.", stderr.getvalue())
Exemplo n.º 4
0
    def test_https(self):
        request = WSGIRequest(RequestFactory().get('/').environ)
        request.makefile = lambda *args, **kwargs: BytesIO()

        handler = WSGIRequestHandler(request, '192.168.0.2', None)

        with patch_logger('django.server', 'error') as messages:
            handler.log_message("GET %s %s", str('\x16\x03'), "4")
        self.assertIn(
            "You're accessing the development server over HTTPS, "
            "but it only supports HTTP.", messages[0])
Exemplo n.º 5
0
    def test_https(self):
        request = WSGIRequest(RequestFactory().get('/').environ)
        request.makefile = lambda *args, **kwargs: BytesIO()

        handler = WSGIRequestHandler(request, '192.168.0.2', None)

        with self.assertLogs('django.server', 'ERROR') as cm:
            handler.log_message("GET %s %s", '\x16\x03', "4")
        self.assertIn(
            "You're accessing the development server over HTTPS, "
            "but it only supports HTTP.", cm.records[0].getMessage())
Exemplo n.º 6
0
    def test_https(self):
        request = WSGIRequest(RequestFactory().get('/').environ)
        request.makefile = lambda *args, **kwargs: BytesIO()

        handler = WSGIRequestHandler(request, '192.168.0.2', None)

        with captured_stderr() as stderr:
            handler.log_message("GET %s %s", str('\x16\x03'), "4")
            self.assertIn(
                "You're accessing the developement server over HTTPS, "
                "but it only supports HTTP.",
                stderr.getvalue()
            )
Exemplo n.º 7
0
    def test_https(self):
        request = WSGIRequest(RequestFactory().get('/').environ)
        request.makefile = lambda *args, **kwargs: BytesIO()

        handler = WSGIRequestHandler(request, '192.168.0.2', None)

        with patch_logger('django.server', 'error') as messages:
            handler.log_message("GET %s %s", '\x16\x03', "4")
        self.assertIn(
            "You're accessing the development server over HTTPS, "
            "but it only supports HTTP.",
            messages[0]
        )
Exemplo n.º 8
0
    def test_https(self):
        request = WSGIRequest(self.request_factory.get("/").environ)
        request.makefile = lambda *args, **kwargs: BytesIO()

        handler = WSGIRequestHandler(request, "192.168.0.2", None)

        with self.assertLogs("django.server", "ERROR") as cm:
            handler.log_message("GET %s %s", "\x16\x03", "4")
        self.assertEqual(
            "You're accessing the development server over HTTPS, "
            "but it only supports HTTP.",
            cm.records[0].getMessage(),
        )
Exemplo n.º 9
0
    def log_message(self, format, *args):
        duration = datetime.now() - self._start_request

        env = self.get_environ()

        for url in (getattr(settings, 'STATIC_URL', None), settings.MEDIA_URL):
            if not url:
                continue
            if self.path.startswith(url):
                return
            elif url.startswith('http:'):
                if ('http://%s%s' %
                    (env['HTTP_HOST'], self.path)).startswith(url):
                    return

        for path in getattr(settings, 'DEVSERVER_IGNORED_PREFIXES', []):
            if self.path.startswith(path):
                return

        format += " (time: %.2fs; sql: %dms (%dq))"
        queries = [
            q for alias in connections for q in connections[alias].queries
        ]
        args = list(args) + [
            ms_from_timedelta(duration) / 1000,
            sum(float(c.get('time', 0)) for c in queries) * 1000,
            len(queries),
        ]
        return WSGIRequestHandler.log_message(self, format, *args)
Exemplo n.º 10
0
    def log_message(self, format, *args):
        duration = datetime.now() - self._start_request

        env = self.get_environ()

        for url in (getattr(settings, "STATIC_URL", None), settings.MEDIA_URL):
            if not url:
                continue
            if self.path.startswith(url):
                return
            elif url.startswith("http:"):
                if ("http://%s%s" % (env["HTTP_HOST"], self.path)).startswith(url):
                    return

        for path in getattr(settings, "DEVSERVER_IGNORED_PREFIXES", []):
            if self.path.startswith(path):
                return

        format += " (time: %.2fs; sql: %dms (%dq))"
        args = list(args) + [
            ms_from_timedelta(duration) / 1000,
            sum(float(c.get("time", 0)) for c in connection.queries) * 1000,
            len(connection.queries),
        ]
        return WSGIRequestHandler.log_message(self, format, *args)
Exemplo n.º 11
0
    def log_message(self, format, *args):
        duration = datetime.now() - self._start_request

        env = self.get_environ()

        for url in (getattr(settings, 'STATIC_URL', None), settings.MEDIA_URL):
            if not url:
                continue
            if self.path.startswith(url):
                return
            elif url.startswith('http:'):
                if ('http://%s%s' % (env['HTTP_HOST'], self.path)).startswith(url):
                    return

        for path in getattr(settings, 'DEVSERVER_IGNORED_PREFIXES', []):
            if self.path.startswith(path):
                return

        format += " (time: %.2fs; sql: %dms (%dq))"
        queries = [
            q for alias in connections
            for q in connections[alias].queries
        ]
        args = list(args) + [
            ms_from_timedelta(duration) / 1000,
            sum(float(c.get('time', 0)) for c in queries) * 1000,
            len(queries),
        ]
        return WSGIRequestHandler.log_message(self, format, *args)
Exemplo n.º 12
0
 def test_log_message(self):
     request = WSGIRequest(self.request_factory.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],
     }
     for level, status_codes in level_status_codes.items():
         for status_code in status_codes:
             # The correct level gets the message.
             with self.assertLogs('django.server', level.upper()) as cm:
                 handler.log_message('GET %s %s', 'A', str(status_code))
             self.assertIn('GET A %d' % status_code, cm.output[0])
             # Incorrect levels don't have any messages.
             for wrong_level in level_status_codes:
                 if wrong_level != level:
                     with self.assertLogs('django.server', 'INFO') as cm:
                         handler.log_message('GET %s %s', 'A', str(status_code))
                     self.assertNotEqual(cm.records[0].levelname, wrong_level.upper())
Exemplo n.º 13
0
 def test_log_message(self):
     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],
     }
     for level, status_codes in level_status_codes.items():
         for status_code in status_codes:
             # The correct level gets the message.
             with self.assertLogs('django.server', level.upper()) as cm:
                 handler.log_message('GET %s %s', 'A', str(status_code))
             self.assertIn('GET A %d' % status_code, cm.output[0])
             # Incorrect levels don't have any messages.
             for wrong_level in level_status_codes:
                 if wrong_level != level:
                     with self.assertLogs('django.server', 'INFO') as cm:
                         handler.log_message('GET %s %s', 'A', str(status_code))
                     self.assertNotEqual(cm.records[0].levelname, wrong_level.upper())
Exemplo n.º 14
0
 def test_log_message(self):
     request = WSGIRequest(self.request_factory.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],
     }
     for level, status_codes in level_status_codes.items():
         for status_code in status_codes:
             # The correct level gets the message.
             with self.assertLogs("django.server", level.upper()) as cm:
                 handler.log_message("GET %s %s", "A", str(status_code))
             self.assertIn("GET A %d" % status_code, cm.output[0])
             # Incorrect levels don't have any messages.
             for wrong_level in level_status_codes:
                 if wrong_level != level:
                     with self.assertLogs("django.server", "INFO") as cm:
                         handler.log_message("GET %s %s", "A",
                                             str(status_code))
                     self.assertNotEqual(cm.records[0].levelname,
                                         wrong_level.upper())
Exemplo n.º 15
0
 def log_message(self, format, *args):
     duration = datetime.now() - self._start_request
     
     # if self.path.startswith(settings.MEDIA_URL):
     #     return
     for path in getattr(settings, 'DEVSERVER_IGNORED_PREFIXES', []):
         if self.path.startswith(path):
             return
     
     format += " (time: %.2fs; sql: %dms (%dq))"
     args = list(args) + [
         ms_from_timedelta(duration) / 1000,
         sum(float(c.get('time', 0)) for c in connection.queries) * 1000,
         len(connection.queries),
     ]
     return WSGIRequestHandler.log_message(self, format, *args)
Exemplo n.º 16
0
    def log_message(self, format, *args):
        duration = datetime.now() - self._start_request

        # if self.path.startswith(settings.MEDIA_URL):
        #     return
        for path in getattr(settings, 'DEVSERVER_IGNORED_PREFIXES', []):
            if self.path.startswith(path):
                return

        format += " (time: %.2fs; sql: %dms (%dq))"
        args = list(args) + [
            ms_from_timedelta(duration) / 1000,
            sum(float(c.get('time', 0)) for c in connection.queries) * 1000,
            len(connection.queries),
        ]
        return WSGIRequestHandler.log_message(self, format, *args)