Exemplo n.º 1
0
 def test_debugging_logger_logs_request(self):
     logger = self.useFixture(FakeLogger('maasserver', logging.DEBUG))
     request = factory.make_fake_request("/api/2.0/nodes/")
     request.content = "test content"
     DebuggingLoggerMiddleware().process_request(request)
     debug_output = DebuggingLoggerMiddleware._build_request_repr(request)
     self.assertThat(logger.output, Contains(debug_output))
Exemplo n.º 2
0
 def test_debugging_logger_does_not_log_response_if_info_level(self):
     logger = self.useFixture(FakeLogger('maasserver', logging.INFO))
     request = factory.make_fake_request("/api/2.0/nodes/")
     response = HttpResponse(content="test content",
                             content_type=b"text/plain; charset=utf-8")
     DebuggingLoggerMiddleware().process_response(request, response)
     debug_output = DebuggingLoggerMiddleware._build_request_repr(request)
     self.assertThat(logger.output, Not(Contains(debug_output)))
Exemplo n.º 3
0
 def test_debugging_logger_logs_binary_response(self):
     logger = self.useFixture(FakeLogger('maasserver', logging.DEBUG))
     request = factory.make_fake_request("foo")
     response = HttpResponse(content=sample_binary_data,
                             content_type=b"application/octet-stream")
     DebuggingLoggerMiddleware().process_response(request, response)
     self.assertThat(logger.output, Contains("non-utf-8 (binary?) content"))
Exemplo n.º 4
0
 def test_debugging_logger_does_not_log_request_if_info_level(self):
     logger = self.useFixture(FakeLogger('maasserver', logging.INFO))
     request = fake_request("/api/1.0/nodes/")
     DebuggingLoggerMiddleware().process_request(request)
     self.assertThat(
         logger.output,
         Not(Contains(build_request_repr(request))))
Exemplo n.º 5
0
 def test_debugging_logger_logs_request(self):
     self.patch(settings, "DEBUG_HTTP", True)
     logger = self.useFixture(FakeLogger("maasserver", logging.DEBUG))
     request = factory.make_fake_request("/MAAS/api/2.0/nodes/")
     request.content = "test content"
     self.process_request(request)
     debug_output = DebuggingLoggerMiddleware._build_request_repr(request)
     self.assertThat(logger.output, Contains(debug_output))
Exemplo n.º 6
0
    def process_request(self, request, response=None):
        def get_response(request):
            if response:
                return response
            else:
                return HttpResponse(status=200)

        middleware = DebuggingLoggerMiddleware(get_response)
        return middleware(request)
Exemplo n.º 7
0
 def test_debugging_logger_logs_response(self):
     logger = self.useFixture(FakeLogger('maasserver', logging.DEBUG))
     request = factory.make_fake_request("foo")
     response = HttpResponse(content="test content",
                             content_type=b"text/plain; charset=utf-8")
     DebuggingLoggerMiddleware().process_response(request, response)
     self.assertThat(
         logger.output,
         Contains(response.content.decode(settings.DEFAULT_CHARSET)))
Exemplo n.º 8
0
 def test_debugging_logger_logs_response(self):
     logger = self.useFixture(FakeLogger('maasserver', logging.DEBUG))
     request = fake_request("foo")
     response = HttpResponse(
         content="test content",
         status=httplib.OK,
         mimetype=b"text/plain; charset=utf-8")
     DebuggingLoggerMiddleware().process_response(request, response)
     self.assertThat(
         logger.output, Contains(response.content))