mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
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:
@@ -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__),
|
||||
|
||||
Reference in New Issue
Block a user