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())
Ejemplo n.º 2
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()
            )
Ejemplo 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 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]
        )
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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())
Ejemplo n.º 7
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)
Ejemplo n.º 8
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())
Ejemplo n.º 9
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())
Ejemplo n.º 10
0
 def handle(self, *args, **kwargs):
     self._start_request = datetime.now()
     return WSGIRequestHandler.handle(self, *args, **kwargs)
Ejemplo n.º 11
0
 def handle(self, *args, **kwargs):
     self._start_request = datetime.now()
     return WSGIRequestHandler.handle(self, *args, **kwargs)