summaryrefslogtreecommitdiff
path: root/tests/sessions_tests
diff options
context:
space:
mode:
authorFrançois Freitag <mail@franek.fr>2020-05-18 22:11:46 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-12-28 09:30:16 +0100
commitb11ec9a69ef626bd7aa22879145e9d74ea38a814 (patch)
treec38bd15f3c332cff4f3955e5ca52725395853c2f /tests/sessions_tests
parent270072c4c231acd72a03534357a4aa59010e76ff (diff)
downloaddjango-b11ec9a69ef626bd7aa22879145e9d74ea38a814.tar.gz
Fixed #32301 -- Made clearsessions raise CommandError when clear_expired() is not implemented.
Diffstat (limited to 'tests/sessions_tests')
-rw-r--r--tests/sessions_tests/no_clear_expired.py6
-rw-r--r--tests/sessions_tests/tests.py11
2 files changed, 17 insertions, 0 deletions
diff --git a/tests/sessions_tests/no_clear_expired.py b/tests/sessions_tests/no_clear_expired.py
new file mode 100644
index 0000000000..0bdfcab6da
--- /dev/null
+++ b/tests/sessions_tests/no_clear_expired.py
@@ -0,0 +1,6 @@
+from django.contrib.sessions.backends.base import SessionBase
+
+
+class SessionStore(SessionBase):
+ """Session store without support for clearing expired sessions."""
+ pass
diff --git a/tests/sessions_tests/tests.py b/tests/sessions_tests/tests.py
index 2832fd8970..73d2a13a9f 100644
--- a/tests/sessions_tests/tests.py
+++ b/tests/sessions_tests/tests.py
@@ -910,3 +910,14 @@ class CookieSessionTests(SessionTestsMixin, SimpleTestCase):
@unittest.skip("CookieSession is stored in the client and there is no way to query it.")
def test_session_save_does_not_resurrect_session_logged_out_in_other_context(self):
pass
+
+
+class ClearSessionsCommandTests(SimpleTestCase):
+ def test_clearsessions_unsupported(self):
+ msg = (
+ "Session engine 'tests.sessions_tests.no_clear_expired' doesn't "
+ "support clearing expired sessions."
+ )
+ with self.settings(SESSION_ENGINE='tests.sessions_tests.no_clear_expired'):
+ with self.assertRaisesMessage(management.CommandError, msg):
+ management.call_command('clearsessions')