test_sessions: Extends tests to reach 100% coverage of sessions.py.

Fixes #3980.
This commit is contained in:
Tim Abbott 2017-05-10 10:04:57 -07:00
parent 53f1f75fcb
commit 232592cc9f
2 changed files with 14 additions and 4 deletions

View File

@ -63,6 +63,7 @@ target_fully_covered = {path for target in [
'zerver/lib/push_notifications.py',
'zerver/lib/request.py',
'zerver/lib/response.py',
'zerver/lib/sessions.py',
'zerver/lib/test_helpers.py',
'zerver/lib/test_classes.py',
'zerver/lib/upload.py',

View File

@ -60,18 +60,27 @@ class TestSessions(ZulipTestCase):
def test_delete_all_deactivated_user_sessions(self):
# type: () -> None
# Test that no exception is thrown with a logged-out session
self.login('hamlet@zulip.com')
self.assertIn('_auth_user_id', self.client.session)
user_profile_1 = get_user_profile_by_email('hamlet@zulip.com')
user_profile_1.is_active = False
self.client_post('/accounts/logout/')
delete_all_deactivated_user_sessions()
result = self.client_get("/")
self.assertEqual('/login', result.url)
# Test nothing happens to an active user's session
self.login('othello@zulip.com')
self.assertIn('_auth_user_id', self.client.session)
user_profile_2 = get_user_profile_by_email('othello@zulip.com')
user_profile_2.is_active = True
delete_all_deactivated_user_sessions()
self.assertIn('_auth_user_id', self.client.session)
# Test that a deactivated session gets logged out
self.login('cordelia@zulip.com')
self.assertIn('_auth_user_id', self.client.session)
user_profile_3 = get_user_profile_by_email('cordelia@zulip.com')
user_profile_3.is_active = False
user_profile_3.save()
delete_all_deactivated_user_sessions()
result = self.client_get("/")
self.assertEqual('/login', result.url)