From b11ec9a69ef626bd7aa22879145e9d74ea38a814 Mon Sep 17 00:00:00 2001 From: François Freitag Date: Mon, 18 May 2020 22:11:46 +0200 Subject: Fixed #32301 -- Made clearsessions raise CommandError when clear_expired() is not implemented. --- tests/sessions_tests/no_clear_expired.py | 6 ++++++ tests/sessions_tests/tests.py | 11 +++++++++++ 2 files changed, 17 insertions(+) create mode 100644 tests/sessions_tests/no_clear_expired.py (limited to 'tests') 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') -- cgit v1.3