mirror of https://github.com/zulip/zulip.git
mute_topic: Update tests to not use lib functions directly.
The "add_topic_mute" and "remove_topic_mute" library functions shouldn't be called directly from tests. They should instead call "do_mute_topic" and "do_unmute_topic" The reason being: Library functions are meant to be internal interfaces for just changing the database, and shouldn't generally be called elsewhere.
This commit is contained in:
parent
e161b36b21
commit
9ecc610681
|
@ -48,7 +48,6 @@ from zerver.lib.test_helpers import (
|
|||
use_s3_backend,
|
||||
)
|
||||
from zerver.lib.upload import claim_attachment, upload_avatar_image, upload_message_attachment
|
||||
from zerver.lib.user_topics import add_topic_mute
|
||||
from zerver.lib.utils import assert_is_not_none
|
||||
from zerver.models import (
|
||||
AlertWord,
|
||||
|
@ -773,13 +772,10 @@ class RealmImportExportTest(ExportFile):
|
|||
|
||||
# data to test import of muted topic
|
||||
stream = get_stream("Verona", original_realm)
|
||||
recipient = stream.recipient
|
||||
assert recipient is not None
|
||||
add_topic_mute(
|
||||
user_profile=sample_user,
|
||||
stream_id=stream.id,
|
||||
recipient_id=recipient.id,
|
||||
topic_name="Verona2",
|
||||
do_mute_topic(
|
||||
sample_user,
|
||||
stream,
|
||||
"Verona2",
|
||||
)
|
||||
|
||||
# data to test import of muted users
|
||||
|
|
|
@ -6,6 +6,7 @@ from django.db import connection, transaction
|
|||
|
||||
from zerver.actions.message_flags import do_update_message_flags
|
||||
from zerver.actions.streams import do_change_stream_permission
|
||||
from zerver.actions.user_topics import do_mute_topic
|
||||
from zerver.lib.fix_unreads import fix, fix_unsubscribed
|
||||
from zerver.lib.message import (
|
||||
MessageDetailsDict,
|
||||
|
@ -23,7 +24,6 @@ from zerver.lib.message import (
|
|||
from zerver.lib.test_classes import ZulipTestCase
|
||||
from zerver.lib.test_helpers import get_subscription, timeout_mock
|
||||
from zerver.lib.timeout import TimeoutExpiredError
|
||||
from zerver.lib.user_topics import add_topic_mute
|
||||
from zerver.models import (
|
||||
Message,
|
||||
Recipient,
|
||||
|
@ -470,14 +470,11 @@ class FixUnreadTests(ZulipTestCase):
|
|||
|
||||
def mute_topic(stream_name: str, topic_name: str) -> None:
|
||||
stream = get_stream(stream_name, realm)
|
||||
recipient = stream.recipient
|
||||
assert recipient is not None
|
||||
|
||||
add_topic_mute(
|
||||
user_profile=user,
|
||||
stream_id=stream.id,
|
||||
recipient_id=recipient.id,
|
||||
topic_name=topic_name,
|
||||
do_mute_topic(
|
||||
user,
|
||||
stream,
|
||||
topic_name,
|
||||
)
|
||||
|
||||
def force_unsubscribe(stream_name: str) -> None:
|
||||
|
@ -711,14 +708,11 @@ class GetUnreadMsgsTest(ZulipTestCase):
|
|||
def mute_topic(self, user_profile: UserProfile, stream_name: str, topic_name: str) -> None:
|
||||
realm = user_profile.realm
|
||||
stream = get_stream(stream_name, realm)
|
||||
recipient = stream.recipient
|
||||
assert recipient is not None
|
||||
|
||||
add_topic_mute(
|
||||
user_profile=user_profile,
|
||||
stream_id=stream.id,
|
||||
recipient_id=recipient.id,
|
||||
topic_name=topic_name,
|
||||
do_mute_topic(
|
||||
user_profile,
|
||||
stream,
|
||||
topic_name,
|
||||
)
|
||||
|
||||
def test_raw_unread_stream(self) -> None:
|
||||
|
|
|
@ -4,12 +4,11 @@ from unittest import mock
|
|||
|
||||
from django.utils.timezone import now as timezone_now
|
||||
|
||||
from zerver.actions.user_topics import do_mute_topic, do_unmute_topic
|
||||
from zerver.lib.stream_topic import StreamTopicTarget
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
from zerver.lib.user_topics import (
|
||||
add_topic_mute,
|
||||
get_topic_mutes,
|
||||
remove_topic_mute,
|
||||
topic_is_muted,
|
||||
)
|
||||
from zerver.models import UserProfile, UserTopic, get_stream
|
||||
|
@ -21,16 +20,13 @@ class MutedTopicsTests(ZulipTestCase):
|
|||
self.login_user(user)
|
||||
|
||||
stream = get_stream("Verona", user.realm)
|
||||
recipient = stream.recipient
|
||||
|
||||
mock_date_muted = datetime(2020, 1, 1, tzinfo=timezone.utc).timestamp()
|
||||
|
||||
assert recipient is not None
|
||||
add_topic_mute(
|
||||
user_profile=user,
|
||||
stream_id=stream.id,
|
||||
recipient_id=recipient.id,
|
||||
topic_name="Verona3",
|
||||
do_mute_topic(
|
||||
user,
|
||||
stream,
|
||||
"Verona3",
|
||||
date_muted=datetime(2020, 1, 1, tzinfo=timezone.utc),
|
||||
)
|
||||
|
||||
|
@ -45,7 +41,6 @@ class MutedTopicsTests(ZulipTestCase):
|
|||
cordelia = self.example_user("cordelia")
|
||||
realm = hamlet.realm
|
||||
stream = get_stream("Verona", realm)
|
||||
recipient = stream.recipient
|
||||
topic_name = "teST topic"
|
||||
|
||||
stream_topic_target = StreamTopicTarget(
|
||||
|
@ -57,12 +52,10 @@ class MutedTopicsTests(ZulipTestCase):
|
|||
self.assertEqual(user_ids, set())
|
||||
|
||||
def mute_topic_for_user(user: UserProfile) -> None:
|
||||
assert recipient is not None
|
||||
add_topic_mute(
|
||||
user_profile=user,
|
||||
stream_id=stream.id,
|
||||
recipient_id=recipient.id,
|
||||
topic_name="test TOPIC",
|
||||
do_mute_topic(
|
||||
user,
|
||||
stream,
|
||||
"test TOPIC",
|
||||
date_muted=timezone_now(),
|
||||
)
|
||||
|
||||
|
@ -107,10 +100,10 @@ class MutedTopicsTests(ZulipTestCase):
|
|||
self.assertIn((stream.name, "Verona3", mock_date_muted), get_topic_mutes(user))
|
||||
self.assertTrue(topic_is_muted(user, stream.id, "verona3"))
|
||||
|
||||
remove_topic_mute(
|
||||
user_profile=user,
|
||||
stream_id=stream.id,
|
||||
topic_name="Verona3",
|
||||
do_unmute_topic(
|
||||
user,
|
||||
stream,
|
||||
"Verona3",
|
||||
)
|
||||
|
||||
assert stream.recipient is not None
|
||||
|
@ -128,7 +121,6 @@ class MutedTopicsTests(ZulipTestCase):
|
|||
self.login_user(user)
|
||||
|
||||
stream = get_stream("Verona", realm)
|
||||
recipient = stream.recipient
|
||||
|
||||
url = "/api/v1/users/me/subscriptions/muted_topics"
|
||||
payloads: List[Dict[str, object]] = [
|
||||
|
@ -137,13 +129,11 @@ class MutedTopicsTests(ZulipTestCase):
|
|||
]
|
||||
mock_date_muted = datetime(2020, 1, 1, tzinfo=timezone.utc).timestamp()
|
||||
|
||||
assert recipient is not None
|
||||
for data in payloads:
|
||||
add_topic_mute(
|
||||
user_profile=user,
|
||||
stream_id=stream.id,
|
||||
recipient_id=recipient.id,
|
||||
topic_name="Verona3",
|
||||
do_mute_topic(
|
||||
user,
|
||||
stream,
|
||||
"Verona3",
|
||||
date_muted=datetime(2020, 1, 1, tzinfo=timezone.utc),
|
||||
)
|
||||
self.assertIn((stream.name, "Verona3", mock_date_muted), get_topic_mutes(user))
|
||||
|
@ -160,15 +150,7 @@ class MutedTopicsTests(ZulipTestCase):
|
|||
self.login_user(user)
|
||||
|
||||
stream = get_stream("Verona", realm)
|
||||
recipient = stream.recipient
|
||||
assert recipient is not None
|
||||
add_topic_mute(
|
||||
user_profile=user,
|
||||
stream_id=stream.id,
|
||||
recipient_id=recipient.id,
|
||||
topic_name="Verona3",
|
||||
date_muted=timezone_now(),
|
||||
)
|
||||
do_mute_topic(user, stream, "Verona3", date_muted=timezone_now())
|
||||
|
||||
url = "/api/v1/users/me/subscriptions/muted_topics"
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ from zerver.actions.message_send import RecipientInfoResult, get_recipient_info
|
|||
from zerver.actions.muted_users import do_mute_user
|
||||
from zerver.actions.realm_settings import do_set_realm_property
|
||||
from zerver.actions.user_settings import bulk_regenerate_api_keys, do_change_user_setting
|
||||
from zerver.actions.user_topics import do_mute_topic
|
||||
from zerver.actions.users import (
|
||||
change_user_is_active,
|
||||
do_change_can_create_users,
|
||||
|
@ -46,7 +47,6 @@ from zerver.lib.test_helpers import (
|
|||
)
|
||||
from zerver.lib.upload import upload_avatar_image
|
||||
from zerver.lib.user_groups import get_system_user_group_for_user
|
||||
from zerver.lib.user_topics import add_topic_mute
|
||||
from zerver.lib.users import Accounts, access_user_by_id, get_accounts_for_email, user_ids_to_users
|
||||
from zerver.lib.utils import assert_is_not_none
|
||||
from zerver.models import (
|
||||
|
@ -1841,11 +1841,10 @@ class RecipientInfoTest(ZulipTestCase):
|
|||
self.assertEqual(info.stream_push_user_ids, {hamlet.id})
|
||||
|
||||
# Now have Hamlet mute the topic to omit him from stream_push_user_ids.
|
||||
add_topic_mute(
|
||||
user_profile=hamlet,
|
||||
stream_id=stream.id,
|
||||
recipient_id=recipient.id,
|
||||
topic_name=topic_name,
|
||||
do_mute_topic(
|
||||
hamlet,
|
||||
stream,
|
||||
topic_name,
|
||||
)
|
||||
|
||||
info = get_recipient_info(
|
||||
|
|
Loading…
Reference in New Issue