diff options
| author | Thng Kai Yuan <thngkaiyuan@users.noreply.github.com> | 2018-07-18 19:07:02 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-07-21 18:14:39 -0400 |
| commit | 71a739f3d752015504d455bf6f01e63a04d1a383 (patch) | |
| tree | fa208d5837d17544221945bcc448e7a623c963da | |
| parent | 8d4ab0c41fa0c4243e7c762de6e6077bb884c048 (diff) | |
Fixed #29576 -- Corrected the test client's HTTP_COOKIE header.
| -rw-r--r-- | django/test/client.py | 5 | ||||
| -rw-r--r-- | tests/test_client_regress/tests.py | 6 |
2 files changed, 10 insertions, 1 deletions
diff --git a/django/test/client.py b/django/test/client.py index d961c2c282..386762e7aa 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -277,7 +277,10 @@ class RequestFactory: # - REMOTE_ADDR: often useful, see #8551. # See http://www.python.org/dev/peps/pep-3333/#environ-variables 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': '/', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_METHOD': 'GET', diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py index 36b28d3a92..7c41fa168e 100644 --- a/tests/test_client_regress/tests.py +++ b/tests/test_client_regress/tests.py @@ -1423,3 +1423,9 @@ class RequestFactoryEnvironmentTests(SimpleTestCase): self.assertEqual(request.META.get('SERVER_PORT'), '80') self.assertEqual(request.META.get('SERVER_PROTOCOL'), 'HTTP/1.1') 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"') |
