Fixed #29576 -- Corrected the test client's HTTP_COOKIE header.

This commit is contained in:
Thng Kai Yuan 2018-07-18 19:07:02 -07:00 committed by Tim Graham
parent 8d4ab0c41f
commit 71a739f3d7
2 changed files with 10 additions and 1 deletions

View File

@ -277,7 +277,10 @@ class RequestFactory:
# - REMOTE_ADDR: often useful, see #8551. # - REMOTE_ADDR: often useful, see #8551.
# See http://www.python.org/dev/peps/pep-3333/#environ-variables # See http://www.python.org/dev/peps/pep-3333/#environ-variables
return { return {
'HTTP_COOKIE': self.cookies.output(header='', sep='; '), 'HTTP_COOKIE': '; '.join(sorted(
'%s=%s' % (morsel.key, morsel.coded_value)
for morsel in self.cookies.values()
)),
'PATH_INFO': '/', 'PATH_INFO': '/',
'REMOTE_ADDR': '127.0.0.1', 'REMOTE_ADDR': '127.0.0.1',
'REQUEST_METHOD': 'GET', 'REQUEST_METHOD': 'GET',

View File

@ -1423,3 +1423,9 @@ class RequestFactoryEnvironmentTests(SimpleTestCase):
self.assertEqual(request.META.get('SERVER_PORT'), '80') self.assertEqual(request.META.get('SERVER_PORT'), '80')
self.assertEqual(request.META.get('SERVER_PROTOCOL'), 'HTTP/1.1') self.assertEqual(request.META.get('SERVER_PROTOCOL'), 'HTTP/1.1')
self.assertEqual(request.META.get('SCRIPT_NAME') + request.META.get('PATH_INFO'), '/path/') self.assertEqual(request.META.get('SCRIPT_NAME') + request.META.get('PATH_INFO'), '/path/')
def test_cookies(self):
factory = RequestFactory()
factory.cookies.load('A="B"; C="D"; Path=/; Version=1')
request = factory.get('/')
self.assertEqual(request.META['HTTP_COOKIE'], 'A="B"; C="D"')