mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 23:43:43 +00:00
Django 1.10: Deprecate request.REQUEST.
This commit is contained in:
@@ -124,8 +124,10 @@ def get_client_name(request, is_json_view):
|
||||
# If the API request specified a client in the request content,
|
||||
# that has priority. Otherwise, extract the client from the
|
||||
# User-Agent.
|
||||
if 'client' in request.REQUEST:
|
||||
return request.REQUEST['client']
|
||||
if 'client' in request.GET:
|
||||
return request.GET['client']
|
||||
elif 'client' in request.POST:
|
||||
return request.POST['client']
|
||||
elif "HTTP_USER_AGENT" in request.META:
|
||||
user_agent = parse_user_agent(request.META["HTTP_USER_AGENT"])
|
||||
# We could check for a browser's name being "Mozilla", but
|
||||
|
||||
@@ -129,7 +129,9 @@ def has_request_variables(view_func):
|
||||
|
||||
default_assigned = False
|
||||
try:
|
||||
val = request.REQUEST[param.post_var_name]
|
||||
query_params = request.GET.copy()
|
||||
query_params.update(request.POST)
|
||||
val = query_params[param.post_var_name]
|
||||
except KeyError:
|
||||
if param.default is REQ.NotSpecified:
|
||||
raise RequestVariableMissingError(param.post_var_name)
|
||||
|
||||
@@ -199,7 +199,8 @@ class POSTRequestMock(object):
|
||||
|
||||
def __init__(self, post_data, user_profile):
|
||||
# type: (Dict[str, Any], UserProfile) -> None
|
||||
self.REQUEST = self.POST = post_data
|
||||
self.GET = {} # type: Dict[str, Any]
|
||||
self.POST = post_data
|
||||
self.user = user_profile
|
||||
self._tornado_handler = DummyHandler()
|
||||
self._log_data = {} # type: Dict[str, Any]
|
||||
|
||||
@@ -34,12 +34,14 @@ import ujson
|
||||
class DecoratorTestCase(TestCase):
|
||||
def test_get_client_name(self):
|
||||
class Request(object):
|
||||
def __init__(self, REQUEST, META):
|
||||
self.REQUEST = REQUEST
|
||||
def __init__(self, GET, POST, META):
|
||||
self.GET = GET
|
||||
self.POST = POST
|
||||
self.META = META
|
||||
|
||||
req = Request(
|
||||
REQUEST=dict(),
|
||||
GET=dict(),
|
||||
POST=dict(),
|
||||
META=dict(),
|
||||
)
|
||||
|
||||
@@ -47,7 +49,8 @@ class DecoratorTestCase(TestCase):
|
||||
self.assertEqual(get_client_name(req, is_json_view=False), 'Unspecified')
|
||||
|
||||
req = Request(
|
||||
REQUEST=dict(),
|
||||
GET=dict(),
|
||||
POST=dict(),
|
||||
META=dict(HTTP_USER_AGENT='Mozilla/bla bla bla'),
|
||||
)
|
||||
|
||||
@@ -56,7 +59,8 @@ class DecoratorTestCase(TestCase):
|
||||
|
||||
|
||||
req = Request(
|
||||
REQUEST=dict(),
|
||||
GET=dict(),
|
||||
POST=dict(),
|
||||
META=dict(HTTP_USER_AGENT='ZulipDesktop/bla bla bla'),
|
||||
)
|
||||
|
||||
@@ -64,7 +68,8 @@ class DecoratorTestCase(TestCase):
|
||||
self.assertEqual(get_client_name(req, is_json_view=False), 'ZulipDesktop')
|
||||
|
||||
req = Request(
|
||||
REQUEST=dict(client='fancy phone'),
|
||||
GET=dict(client='fancy phone'),
|
||||
POST=dict(),
|
||||
META=dict(),
|
||||
)
|
||||
|
||||
@@ -87,24 +92,25 @@ class DecoratorTestCase(TestCase):
|
||||
return sum(numbers)
|
||||
|
||||
class Request(object):
|
||||
REQUEST = {} # type: Dict[str, str]
|
||||
GET = {} # type: Dict[str, str]
|
||||
POST = {} # type: Dict[str, str]
|
||||
|
||||
request = Request()
|
||||
|
||||
with self.assertRaises(RequestVariableMissingError):
|
||||
get_total(request)
|
||||
|
||||
request.REQUEST['numbers'] = 'bad_value'
|
||||
request.POST['numbers'] = 'bad_value'
|
||||
with self.assertRaises(RequestVariableConversionError) as cm:
|
||||
get_total(request)
|
||||
self.assertEqual(str(cm.exception), "Bad value for 'numbers': bad_value")
|
||||
|
||||
request.REQUEST['numbers'] = ujson.dumps([2, 3, 5, 8, 13, 21])
|
||||
request.POST['numbers'] = ujson.dumps([2, 3, 5, 8, 13, 21])
|
||||
with self.assertRaises(JsonableError) as cm:
|
||||
get_total(request)
|
||||
self.assertEqual(str(cm.exception), "13 is an unlucky number!")
|
||||
|
||||
request.REQUEST['numbers'] = ujson.dumps([1, 2, 3, 4, 5, 6])
|
||||
request.POST['numbers'] = ujson.dumps([1, 2, 3, 4, 5, 6])
|
||||
result = get_total(request)
|
||||
self.assertEqual(result, 21)
|
||||
|
||||
@@ -115,24 +121,25 @@ class DecoratorTestCase(TestCase):
|
||||
return sum(numbers)
|
||||
|
||||
class Request(object):
|
||||
REQUEST = {} # type: Dict[str, str]
|
||||
GET = {} # type: Dict[str, str]
|
||||
POST = {} # type: Dict[str, str]
|
||||
|
||||
request = Request()
|
||||
|
||||
with self.assertRaises(RequestVariableMissingError):
|
||||
get_total(request)
|
||||
|
||||
request.REQUEST['numbers'] = 'bad_value'
|
||||
request.POST['numbers'] = 'bad_value'
|
||||
with self.assertRaises(JsonableError) as cm:
|
||||
get_total(request)
|
||||
self.assertEqual(str(cm.exception), 'argument "numbers" is not valid json.')
|
||||
|
||||
request.REQUEST['numbers'] = ujson.dumps([1, 2, "what?", 4, 5, 6])
|
||||
request.POST['numbers'] = ujson.dumps([1, 2, "what?", 4, 5, 6])
|
||||
with self.assertRaises(JsonableError) as cm:
|
||||
get_total(request)
|
||||
self.assertEqual(str(cm.exception), 'numbers[2] is not an integer')
|
||||
|
||||
request.REQUEST['numbers'] = ujson.dumps([1, 2, 3, 4, 5, 6])
|
||||
request.POST['numbers'] = ujson.dumps([1, 2, 3, 4, 5, 6])
|
||||
result = get_total(request)
|
||||
self.assertEqual(result, 21)
|
||||
|
||||
@@ -168,7 +175,8 @@ class DecoratorTestCase(TestCase):
|
||||
return user_profile.email
|
||||
|
||||
class Request(HostRequestMock):
|
||||
REQUEST = {} # type: Dict[str, str]
|
||||
GET = {} # type: Dict[str, str]
|
||||
POST = {} # type: Dict[str, str]
|
||||
COOKIES = {}
|
||||
META = {'PATH_INFO': ''}
|
||||
|
||||
@@ -179,12 +187,12 @@ class DecoratorTestCase(TestCase):
|
||||
request = Request()
|
||||
request.host = settings.EXTERNAL_HOST
|
||||
|
||||
request.REQUEST['api_key'] = 'not_existing_api_key'
|
||||
request.POST['api_key'] = 'not_existing_api_key'
|
||||
with self.assertRaisesRegexp(JsonableError, "Invalid API key"):
|
||||
my_webhook(request)
|
||||
|
||||
# Start a valid request here
|
||||
request.REQUEST['api_key'] = webhook_bot_api_key
|
||||
request.POST['api_key'] = webhook_bot_api_key
|
||||
|
||||
with self.settings(REALMS_HAVE_SUBDOMAINS=True):
|
||||
with mock.patch('logging.warning') as mock_warning:
|
||||
|
||||
Reference in New Issue
Block a user