def process_request(self, request: HttpRequest) -> None: if not hasattr(request, 'audit_log') and not self.exempt_request(request): audit_log = DjangoAuditLogger() audit_log.set_django_http_request(request) audit_log.set_user_from_request(request) request.audit_log = audit_log
def test_set_django_http_request(self): audit_log = DjangoAuditLogger() request = self.request_factory.get("/", SERVER_NAME="localhost", HTTP_USER_AGENT='test_agent') audit_log.set_django_http_request(request) self.assertEqual(audit_log.http_request['method'], 'GET') self.assertEqual(audit_log.http_request['url'], 'http://localhost/') self.assertEqual(audit_log.http_request['user_agent'], 'test_agent')