Add Request repr (#7239)

This commit is contained in:
Ryan P Kilby 2020-03-29 04:01:14 -07:00 committed by GitHub
parent 57e7cc21e1
commit dd33ebb4e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -179,6 +179,13 @@ class Request:
forced_auth = ForcedAuthentication(force_user, force_token)
self.authenticators = (forced_auth,)
def __repr__(self):
return '<%s.%s: %s %r>' % (
self.__class__.__module__,
self.__class__.__name__,
self.method,
self.get_full_path())
def _default_negotiator(self):
return api_settings.DEFAULT_CONTENT_NEGOTIATION_CLASS()

View File

@ -272,6 +272,12 @@ class TestSecure(TestCase):
class TestHttpRequest(TestCase):
def test_repr(self):
http_request = factory.get('/path')
request = Request(http_request)
assert repr(request) == "<rest_framework.request.Request: GET '/path'>"
def test_attribute_access_proxy(self):
http_request = factory.get('/')
request = Request(http_request)