Ticket #15740: 15740.diff

File 15740.diff, 1.9 KB (added by Preston Timmons, 14 years ago)
  • django/test/client.py

    diff --git a/django/test/client.py b/django/test/client.py
    index dd0d811..f4b8d63 100644
    a b class Client(RequestFactory):  
    358358        """
    359359        if 'django.contrib.sessions' in settings.INSTALLED_APPS:
    360360            engine = import_module(settings.SESSION_ENGINE)
    361             cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None)
     361            cookie = self.cookies.get(settings.SESSION_COOKIE_NAME)
    362362            if cookie:
    363363                return engine.SessionStore(cookie.value)
     364            else:
     365                session_store = engine.SessionStore()
     366                session_store.save()
     367                self.cookies[settings.SESSION_COOKIE_NAME] = \
     368                    session_store.session_key
     369                return session_store
    364370        return {}
    365371    session = property(_session)
    366372
    367 
    368373    def request(self, **request):
    369374        """
    370375        The master request method. Composes the environment dictionary
  • 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 b24032d..9f415a4 100644
    a b class SessionTests(TestCase):  
    690690        self.assertEqual(response.status_code, 200)
    691691        self.assertEqual(response.content, 'YES')
    692692
     693    def test_session_manipulation(self):
     694        # Modify the session
     695        session = self.client.session
     696        session["session_var"] = "foo"
     697        session.save()
     698
     699        # Check that the session works in the client
     700        response = self.client.get('/test_client_regress/check_session/')
     701        self.assertEqual(response.status_code, 200)
     702        self.assertEqual(response.content, 'foo')
     703
    693704    def test_logout(self):
    694705        """Logout should work whether the user is logged in or not (#9978)."""
    695706        self.client.logout()
Back to Top