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"')