@@ -0,0 +1,2996 @@
+from __future__ import absolute_import%0Afrom typing import Any, Callable%0A%0Afrom zerver.lib.sessions import (%0A    user_sessions,%0A    delete_session,%0A    delete_user_sessions,%0A    delete_realm_user_sessions,%0A    delete_all_user_sessions,%0A    delete_all_deactivated_user_sessions,%0A)%0A%0Afrom zerver.models import (%0A    UserProfile, get_user_profile_by_id,%0A    get_user_profile_by_email, get_realm%0A)%0A%0Afrom zerver.lib.test_classes import ZulipTestCase%0A%0A%0Aclass TestSessions(ZulipTestCase):%0A%0A    def do_test_session(self, user, action, expected_result):%0A        # type: (str, Callable%5B%5B%5D, Any%5D, bool) -%3E None%0A        self.login(user)%0A        self.assertIn('_auth_user_id', self.client.session)%0A        action()%0A        if expected_result:%0A            result = self.client_get('/')%0A            self.assertEqual('/login', result.url)%0A        else:%0A            self.assertIn('_auth_user_id', self.client.session)%0A%0A    def test_delete_session(self):%0A        # type: () -%3E None%0A        self.login('hamlet@zulip.com')%0A        self.assertIn('_auth_user_id', self.client.session)%0A        user_profile = get_user_profile_by_email('hamlet@zulip.com')%0A        for session in user_sessions(user_profile):%0A            delete_session(session)%0A        result = self.client_get(%22/%22)%0A        self.assertEqual('/login', result.url)%0A%0A    def test_delete_user_sessions(self):%0A        # type: () -%3E None%0A        user_profile = get_user_profile_by_email('hamlet@zulip.com')%0A        self.do_test_session('hamlet@zulip.com', lambda: delete_user_sessions(user_profile), True)%0A        self.do_test_session('othello@zulip.com', lambda: delete_user_sessions(user_profile), False)%0A%0A    def test_delete_realm_user_sessions(self):%0A        # type: () -%3E None%0A        realm = get_realm('zulip')%0A        self.do_test_session('hamlet@zulip.com', lambda: delete_realm_user_sessions(realm), True)%0A        self.do_test_session('sipbtest@mit.edu', lambda: delete_realm_user_sessions(realm), False)%0A%0A    def test_delete_all_user_sessions(self):%0A        # type: () -%3E None%0A        self.do_test_session('hamlet@zulip.com', lambda: delete_all_user_sessions(), True)%0A        self.do_test_session('sipbtest@mit.edu', lambda: delete_all_user_sessions(), True)%0A%0A    def test_delete_all_deactivated_user_sessions(self):%0A        # type: () -%3E None%0A        self.login('hamlet@zulip.com')%0A        self.assertIn('_auth_user_id', self.client.session)%0A        user_profile_1 = get_user_profile_by_email('hamlet@zulip.com')%0A        user_profile_1.is_active = False%0A        self.client_post('/accounts/logout/')%0A        delete_all_deactivated_user_sessions()%0A        result = self.client_get(%22/%22)%0A        self.assertEqual('/login', result.url)%0A%0A        self.login('othello@zulip.com')%0A        self.assertIn('_auth_user_id', self.client.session)%0A        user_profile_2 = get_user_profile_by_email('othello@zulip.com')%0A        user_profile_2.is_active = True%0A        delete_all_deactivated_user_sessions()%0A        self.assertIn('_auth_user_id', self.client.session)%0A

Add tests for zerver/lib/sessions.py.