tests: Simplify how we get active streams.

There's no need for the complexity and extra round
trips to call get_display_recipient in a testing
context.

We also eliminate the unnecessary call to check_string.

This function is poorly named, but that's a sweep
for another day.
This commit is contained in:
Steve Howell 2023-07-16 13:27:39 +00:00 committed by Tim Abbott
parent a54760da0e
commit 8295b0d46e
1 changed files with 7 additions and 6 deletions

View File

@ -58,7 +58,7 @@ from zerver.lib.notification_data import UserMessageNotificationsData
from zerver.lib.rate_limiter import bounce_redis_key_prefix_for_testing from zerver.lib.rate_limiter import bounce_redis_key_prefix_for_testing
from zerver.lib.sessions import get_session_dict_user from zerver.lib.sessions import get_session_dict_user
from zerver.lib.soft_deactivation import do_soft_deactivate_users from zerver.lib.soft_deactivation import do_soft_deactivate_users
from zerver.lib.stream_subscription import get_stream_subscriptions_for_user from zerver.lib.stream_subscription import get_subscribed_stream_ids_for_user
from zerver.lib.streams import ( from zerver.lib.streams import (
create_stream_if_needed, create_stream_if_needed,
get_default_value_for_history_public_to_subscribers, get_default_value_for_history_public_to_subscribers,
@ -74,7 +74,6 @@ from zerver.lib.test_helpers import find_key_by_email, instrument_url, queries_c
from zerver.lib.topic import RESOLVED_TOPIC_PREFIX, filter_by_topic_name_via_message from zerver.lib.topic import RESOLVED_TOPIC_PREFIX, filter_by_topic_name_via_message
from zerver.lib.user_groups import get_system_user_group_for_user from zerver.lib.user_groups import get_system_user_group_for_user
from zerver.lib.users import get_api_key from zerver.lib.users import get_api_key
from zerver.lib.validator import check_string
from zerver.lib.webhooks.common import ( from zerver.lib.webhooks.common import (
check_send_webhook_message, check_send_webhook_message,
get_fixture_http_headers, get_fixture_http_headers,
@ -1040,12 +1039,14 @@ Output:
def get_streams(self, user_profile: UserProfile) -> List[str]: def get_streams(self, user_profile: UserProfile) -> List[str]:
""" """
Helper function to get the stream names for a user Helper function to get the active stream names for a user
""" """
subs = get_stream_subscriptions_for_user(user_profile).filter(
active=True, return list(
Stream.objects.filter(
id__in=get_subscribed_stream_ids_for_user(user_profile)
).values_list("name", flat=True)
) )
return [check_string("recipient", get_display_recipient(sub.recipient)) for sub in subs]
def send_personal_message( def send_personal_message(
self, self,