tests: Extract and use assert_logged_in_user_id test helper.

This cleans up the pattern for how we check which user is logged in
during Zulip's backend unit tests to be much more readable (replacing
the arcane session code that does this check).
This commit is contained in:
Mayank Madan
2019-05-27 01:42:46 +05:30
committed by Tim Abbott
parent 90a9dfa7f5
commit 7fedcbd840
4 changed files with 51 additions and 46 deletions

View File

@@ -22,6 +22,7 @@ from two_factor.models import PhoneDevice
from zerver.lib.initial_password import initial_password
from zerver.lib.utils import is_remote_server
from zerver.lib.users import get_api_key
from zerver.lib.sessions import get_session_dict_user
from zerver.lib.actions import (
check_send_message, create_stream_if_needed, bulk_add_subscriptions,
@@ -559,6 +560,13 @@ class ZulipTestCase(TestCase):
for substring in substrings:
self.assertNotIn(substring, decoded)
def assert_logged_in_user_id(self, user_id: Optional[int]) -> None:
"""
Verifies the user currently logged in for the test client has the provided user_id.
Pass None to verify no user is logged in.
"""
self.assertEqual(get_session_dict_user(self.client.session), user_id)
def webhook_fixture_data(self, type: str, action: str, file_type: str='json') -> str:
fn = os.path.join(
os.path.dirname(__file__),