示例#1
0
    def finalize_response(self, request, response, *args, **kwargs):
        response = super(MockApiView, self).finalize_response(request, response, *args, **kwargs)

        access_log = http_utils.log_request_and_response(request, response)
        if self.api_endpoint:
            access_log.api_endpoint = self.api_endpoint
            access_log.save()

        logger.debug("Access log entry was added: %s", access_log)
        return response
示例#2
0
    def finalize_response(self, request, response, *args, **kwargs):
        response = super(MockApiView,
                         self).finalize_response(request, response, *args,
                                                 **kwargs)

        access_log = http_utils.log_request_and_response(request, response)
        if self.api_endpoint:
            access_log.api_endpoint = self.api_endpoint
            access_log.save()

        logger.debug("Access log entry was added: %s", access_log)
        return response
    def test_access_log_request_response(self):
        http_user_agent = "DJANGO TEST CLIENT"
        request = Request(self.factory.post("/api/?test_qs", data={"ABC": "ABC"}, HTTP_USER_AGENT=http_user_agent))
        response = Response(status=200, data={"status": "API_LOG_OK"}, headers={"X-TEST": "Test"})

        access_log = log_request_and_response(request, response)

        self.assertIsNotNone(access_log.request_time)
        self.assertEqual(access_log.user_agent, http_user_agent)
        self.assertEqual(access_log.path, request.path_info)
        self.assertEqual(access_log.request_method, "POST")
        self.assertEqual(access_log.request_query_string, "test_qs")
        self.assertIn(http_user_agent, access_log.request_headers)
        self.assertIn("ABC", access_log.request_data)
        self.assertEqual(access_log.response_status_code, response.status_code)
        self.assertIn("API_LOG_OK", access_log.response_content)
        self.assertIn("X-TEST", access_log.response_headers)
    def test_access_log_request_response(self):
        http_user_agent = "DJANGO TEST CLIENT"
        request = Request(
            self.factory.post('/api/?test_qs',
                              data={"ABC": "ABC"},
                              HTTP_USER_AGENT=http_user_agent))
        response = Response(status=200,
                            data={"status": "API_LOG_OK"},
                            headers={"X-TEST": "Test"})

        access_log = log_request_and_response(request, response)

        self.assertIsNotNone(access_log.request_time)
        self.assertEqual(access_log.user_agent, http_user_agent)
        self.assertEqual(access_log.path, request.path_info)
        self.assertEqual(access_log.request_method, "POST")
        self.assertEqual(access_log.request_query_string, "test_qs")
        self.assertIn(http_user_agent, access_log.request_headers)
        self.assertIn("ABC", access_log.request_data)
        self.assertEqual(access_log.response_status_code, response.status_code)
        self.assertIn("API_LOG_OK", access_log.response_content)
        self.assertIn("X-TEST", access_log.response_headers)