diff options
| author | Sergey Kolosov <m17.admin@gmail.com> | 2016-04-02 16:11:47 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-04-04 07:48:48 -0400 |
| commit | 21dd98a38660747c781802afca7ca02407964383 (patch) | |
| tree | b045713969b238a5ea80ceba819e5402b1bb104d /django | |
| parent | 5faf745999caa3d2588979ae1262cc28652c21a5 (diff) | |
Fixed #25699 -- Allowed using the test client if 'django.contrib.sessions' isn't in INSTALLED_APPS.
Diffstat (limited to 'django')
| -rw-r--r-- | django/test/client.py | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/django/test/client.py b/django/test/client.py index 42b325bd14..8349a902fa 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -9,7 +9,6 @@ from copy import copy from importlib import import_module from io import BytesIO -from django.apps import apps from django.conf import settings from django.core.handlers.base import BaseHandler from django.core.handlers.wsgi import ISO_8859_1, UTF_8, WSGIRequest @@ -419,17 +418,15 @@ class Client(RequestFactory): """ Obtains the current session variables. """ - if apps.is_installed('django.contrib.sessions'): - engine = import_module(settings.SESSION_ENGINE) - cookie = self.cookies.get(settings.SESSION_COOKIE_NAME) - if cookie: - return engine.SessionStore(cookie.value) - else: - s = engine.SessionStore() - s.save() - self.cookies[settings.SESSION_COOKIE_NAME] = s.session_key - return s - return {} + engine = import_module(settings.SESSION_ENGINE) + cookie = self.cookies.get(settings.SESSION_COOKIE_NAME) + if cookie: + return engine.SessionStore(cookie.value) + + session = engine.SessionStore() + session.save() + self.cookies[settings.SESSION_COOKIE_NAME] = session.session_key + return session session = property(_session) def request(self, **request): @@ -594,12 +591,11 @@ class Client(RequestFactory): Sets the Factory to appear as if it has successfully logged into a site. Returns True if login is possible; False if the provided credentials - are incorrect, or the user is inactive, or if the sessions framework is - not available. + are incorrect. """ from django.contrib.auth import authenticate user = authenticate(**credentials) - if user and apps.is_installed('django.contrib.sessions'): + if user: self._login(user) return True else: |
