Ticket #17067: restore_remote_addr_to_test_client_env.diff

File restore_remote_addr_to_test_client_env.diff, 1.6 KB (added by jsdalton, 4 years ago)
  • django/test/client.py

    diff --git a/django/test/client.py b/django/test/client.py
    index a5ef075..d6857cf 100644
    a b class RequestFactory(object): 
    188188        environ = {
    189189            'HTTP_COOKIE':       self.cookies.output(header='', sep='; '),
    190190            'REQUEST_METHOD':    'GET',
     191            'REMOTE_ADDR':       '127.0.0.1',
    191192            'SERVER_NAME':       'testserver',
    192193            'SERVER_PORT':       '80',
    193194            'SERVER_PROTOCOL':   'HTTP/1.1',
  • tests/regressiontests/test_client_regress/models.py

    diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py
    index 18ffffd..ce3d481 100644
    a b class RequestFactoryStateTest(TestCase): 
    994994    def test_request_after_client_2(self):
    995995        # This test is executed after the previous one
    996996        self.common_test_that_should_always_pass()
     997
     998
     999class RequestFactoryEnvironmentTests(TestCase):
     1000    """
     1001    Ensure that environment variables are set correctly in the RequestFactory
     1002    to prevent future regressions.
     1003    """
     1004
     1005    def setUp(self):
     1006        self.factory = RequestFactory()
     1007
     1008    def test_should_set_correct_env_variables(self):
     1009        request = self.factory.get('/')
     1010
     1011        self.assertEqual(request.META.get('REMOTE_ADDR'), '127.0.0.1')
     1012        self.assertEqual(request.META.get('SERVER_NAME'), 'testserver')
     1013        self.assertEqual(request.META.get('SERVER_PORT'), '80')
     1014        self.assertEqual(request.META.get('SERVER_PROTOCOL'), 'HTTP/1.1')
Back to Top