mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 12:00:12 +03:00
Add 'Request.http_request', deprecate '._request'
This commit is contained in:
parent
ef2208ccc6
commit
f457f3d906
|
@ -11,6 +11,7 @@ The wrapped request then offers a richer API, in particular :
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import warnings
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -159,7 +160,7 @@ class Request(object):
|
||||||
.format(request.__class__.__module__, request.__class__.__name__)
|
.format(request.__class__.__module__, request.__class__.__name__)
|
||||||
)
|
)
|
||||||
|
|
||||||
self._request = request
|
self.http_request = request
|
||||||
self.parsers = parsers or ()
|
self.parsers = parsers or ()
|
||||||
self.authenticators = authenticators or ()
|
self.authenticators = authenticators or ()
|
||||||
self.negotiator = negotiator or self._default_negotiator()
|
self.negotiator = negotiator or self._default_negotiator()
|
||||||
|
@ -181,6 +182,22 @@ class Request(object):
|
||||||
forced_auth = ForcedAuthentication(force_user, force_token)
|
forced_auth = ForcedAuthentication(force_user, force_token)
|
||||||
self.authenticators = (forced_auth,)
|
self.authenticators = (forced_auth,)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _request(self):
|
||||||
|
warnings.warn(
|
||||||
|
"`_request` has been deprecated in favor of `http_request`, and will be removed in 3.10",
|
||||||
|
PendingDeprecationWarning, stacklevel=2
|
||||||
|
)
|
||||||
|
return self.http_request
|
||||||
|
|
||||||
|
@_request.setter
|
||||||
|
def _request(self, value):
|
||||||
|
warnings.warn(
|
||||||
|
"`_request` has been deprecated in favor of `http_request`, and will be removed in 3.10",
|
||||||
|
PendingDeprecationWarning, stacklevel=2
|
||||||
|
)
|
||||||
|
self.http_request = value
|
||||||
|
|
||||||
def _default_negotiator(self):
|
def _default_negotiator(self):
|
||||||
return api_settings.DEFAULT_CONTENT_NEGOTIATION_CLASS()
|
return api_settings.DEFAULT_CONTENT_NEGOTIATION_CLASS()
|
||||||
|
|
||||||
|
|
|
@ -292,3 +292,22 @@ class TestHttpRequest(TestCase):
|
||||||
message = "'Request' object has no attribute 'inner_property'"
|
message = "'Request' object has no attribute 'inner_property'"
|
||||||
with self.assertRaisesMessage(AttributeError, message):
|
with self.assertRaisesMessage(AttributeError, message):
|
||||||
request.inner_property
|
request.inner_property
|
||||||
|
|
||||||
|
def test_request_deprecation(self):
|
||||||
|
with pytest.warns(PendingDeprecationWarning) as record:
|
||||||
|
Request(factory.get('/'))._request
|
||||||
|
|
||||||
|
assert len(record) == 1
|
||||||
|
assert str(record[0].message) == (
|
||||||
|
"`_request` has been deprecated in favor of "
|
||||||
|
"`http_request`, and will be removed in 3.10"
|
||||||
|
)
|
||||||
|
|
||||||
|
with pytest.warns(PendingDeprecationWarning) as record:
|
||||||
|
Request(factory.get('/'))._request = None
|
||||||
|
|
||||||
|
assert len(record) == 1
|
||||||
|
assert str(record[0].message) == (
|
||||||
|
"`_request` has been deprecated in favor of "
|
||||||
|
"`http_request`, and will be removed in 3.10"
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user