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,
|
502 | 502 | except Exception: |
503 | 503 | meta = '<could not parse>' |
504 | 504 | 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>' % |
506 | 509 | (request.__class__.__name__, |
507 | 510 | path, |
| 511 | six.text_type(user), |
508 | 512 | six.text_type(get), |
509 | 513 | six.text_type(post), |
510 | 514 | six.text_type(cookies), |
diff --git a/tests/requests/tests.py b/tests/requests/tests.py
index b0598b1..47739ca 100644
a
|
b
|
class RequestsTests(SimpleTestCase):
|
59 | 59 | request.POST = {'post-key': 'post-value'} |
60 | 60 | request.COOKIES = {'post-key': 'post-value'} |
61 | 61 | request.META = {'post-key': 'post-value'} |
| 62 | request.user = None |
62 | 63 | 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'}>")) |
64 | 65 | 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 | |
66 | 68 | |
67 | 69 | def test_httprequest_repr_invalid_method_and_path(self): |
68 | 70 | request = HttpRequest() |
… |
… |
class RequestsTests(SimpleTestCase):
|
146 | 148 | request.POST = {'post-key': 'post-value'} |
147 | 149 | request.COOKIES = {'post-key': 'post-value'} |
148 | 150 | request.META = {'post-key': 'post-value'} |
| 151 | request.user = None |
149 | 152 | 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'}>")) |
151 | 154 | 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'}>")) |
153 | 156 | |
154 | 157 | def test_wsgirequest_path_info(self): |
155 | 158 | def wsgi_str(path_info): |