Ticket #25037: 25037.diff

File 25037.diff, 4.2 KB (added by Grigoriy Kramarenko, 9 years ago)
  • django/http/request.py

    diff --git a/django/http/request.py b/django/http/request.py
    index fbd355e..b8a6383 100644
    a b def build_request_repr(request, path_override=None, GET_override=None,  
    502502    except Exception:
    503503        meta = '<could not parse>'
    504504    path = path_override if path_override is not None else request.path
    505     return force_str('<%s\npath:%s,\nGET:%s,\nPOST:%s,\nCOOKIES:%s,\nMETA:%s>' %
     505    user = getattr(request, 'user', None)
     506    if user and hasattr(user, 'is_authenticated') and user.is_authenticated():
     507        user = getattr(user, 'username', None)
     508    return force_str('<%s\npath:%s,\nuser:%s,\nGET:%s,\nPOST:%s,\nCOOKIES:%s,\nMETA:%s>' %
    506509                     (request.__class__.__name__,
    507510                      path,
     511                      six.text_type(user),
    508512                      six.text_type(get),
    509513                      six.text_type(post),
    510514                      six.text_type(cookies),
  • tests/requests/tests.py

    diff --git a/tests/requests/tests.py b/tests/requests/tests.py
    index b0598b1..47739ca 100644
    a b class RequestsTests(SimpleTestCase):  
    5959        request.POST = {'post-key': 'post-value'}
    6060        request.COOKIES = {'post-key': 'post-value'}
    6161        request.META = {'post-key': 'post-value'}
     62        request.user = None
    6263        self.assertEqual(repr(request), str_prefix("<HttpRequest: GET '/somepath/'>"))
    63         self.assertEqual(build_request_repr(request), str_prefix("<HttpRequest\npath:/somepath/,\nGET:{%(_)s'get-key': %(_)s'get-value'},\nPOST:{%(_)s'post-key': %(_)s'post-value'},\nCOOKIES:{%(_)s'post-key': %(_)s'post-value'},\nMETA:{%(_)s'post-key': %(_)s'post-value'}>"))
     64        self.assertEqual(build_request_repr(request), str_prefix("<HttpRequest\npath:/somepath/,\nuser:None,\nGET:{%(_)s'get-key': %(_)s'get-value'},\nPOST:{%(_)s'post-key': %(_)s'post-value'},\nCOOKIES:{%(_)s'post-key': %(_)s'post-value'},\nMETA:{%(_)s'post-key': %(_)s'post-value'}>"))
    6465        self.assertEqual(build_request_repr(request, path_override='/otherpath/', GET_override={'a': 'b'}, POST_override={'c': 'd'}, COOKIES_override={'e': 'f'}, META_override={'g': 'h'}),
    65                          str_prefix("<HttpRequest\npath:/otherpath/,\nGET:{%(_)s'a': %(_)s'b'},\nPOST:{%(_)s'c': %(_)s'd'},\nCOOKIES:{%(_)s'e': %(_)s'f'},\nMETA:{%(_)s'g': %(_)s'h'}>"))
     66                         str_prefix("<HttpRequest\npath:/otherpath/,\nuser:None,\nGET:{%(_)s'a': %(_)s'b'},\nPOST:{%(_)s'c': %(_)s'd'},\nCOOKIES:{%(_)s'e': %(_)s'f'},\nMETA:{%(_)s'g': %(_)s'h'}>"))
     67
    6668
    6769    def test_httprequest_repr_invalid_method_and_path(self):
    6870        request = HttpRequest()
    class RequestsTests(SimpleTestCase):  
    146148        request.POST = {'post-key': 'post-value'}
    147149        request.COOKIES = {'post-key': 'post-value'}
    148150        request.META = {'post-key': 'post-value'}
     151        request.user = None
    149152        self.assertEqual(repr(request), str_prefix("<WSGIRequest: GET '/somepath/'>"))
    150         self.assertEqual(build_request_repr(request), str_prefix("<WSGIRequest\npath:/somepath/,\nGET:{%(_)s'get-key': %(_)s'get-value'},\nPOST:{%(_)s'post-key': %(_)s'post-value'},\nCOOKIES:{%(_)s'post-key': %(_)s'post-value'},\nMETA:{%(_)s'post-key': %(_)s'post-value'}>"))
     153        self.assertEqual(build_request_repr(request), str_prefix("<WSGIRequest\npath:/somepath/,\nuser:None,\nGET:{%(_)s'get-key': %(_)s'get-value'},\nPOST:{%(_)s'post-key': %(_)s'post-value'},\nCOOKIES:{%(_)s'post-key': %(_)s'post-value'},\nMETA:{%(_)s'post-key': %(_)s'post-value'}>"))
    151154        self.assertEqual(build_request_repr(request, path_override='/otherpath/', GET_override={'a': 'b'}, POST_override={'c': 'd'}, COOKIES_override={'e': 'f'}, META_override={'g': 'h'}),
    152                          str_prefix("<WSGIRequest\npath:/otherpath/,\nGET:{%(_)s'a': %(_)s'b'},\nPOST:{%(_)s'c': %(_)s'd'},\nCOOKIES:{%(_)s'e': %(_)s'f'},\nMETA:{%(_)s'g': %(_)s'h'}>"))
     155                         str_prefix("<WSGIRequest\npath:/otherpath/,\nuser:None,\nGET:{%(_)s'a': %(_)s'b'},\nPOST:{%(_)s'c': %(_)s'd'},\nCOOKIES:{%(_)s'e': %(_)s'f'},\nMETA:{%(_)s'g': %(_)s'h'}>"))
    153156
    154157    def test_wsgirequest_path_info(self):
    155158        def wsgi_str(path_info):
Back to Top