mirror of https://github.com/zulip/zulip.git
bots: Pass realm to remaining get_system_bot calls in tests.
This commit is contained in:
parent
ce4eb6f203
commit
c34260426a
|
@ -1110,15 +1110,16 @@ class TestEventsRegisterNarrowDefaults(ZulipTestCase):
|
|||
|
||||
class TestGetRawUserDataSystemBotRealm(ZulipTestCase):
|
||||
def test_get_raw_user_data_on_system_bot_realm(self) -> None:
|
||||
realm = get_realm(settings.SYSTEM_BOT_REALM)
|
||||
result = get_raw_user_data(
|
||||
get_realm("zulipinternal"),
|
||||
realm,
|
||||
self.example_user("hamlet"),
|
||||
client_gravatar=True,
|
||||
user_avatar_url_field_optional=True,
|
||||
)
|
||||
|
||||
for bot_email in settings.CROSS_REALM_BOT_EMAILS:
|
||||
bot_profile = get_system_bot(bot_email)
|
||||
bot_profile = get_system_bot(bot_email, realm.id)
|
||||
self.assertTrue(bot_profile.id in result)
|
||||
self.assertTrue(result[bot_profile.id]["is_system_bot"])
|
||||
|
||||
|
|
|
@ -240,7 +240,7 @@ class MessagePOSTTest(ZulipTestCase):
|
|||
)
|
||||
|
||||
# Cross realm bots should be allowed
|
||||
notification_bot = get_system_bot("notification-bot@zulip.com")
|
||||
notification_bot = get_system_bot("notification-bot@zulip.com", stream.realm_id)
|
||||
internal_send_stream_message(
|
||||
notification_bot, stream, "Test topic", "Test message by notification bot"
|
||||
)
|
||||
|
@ -319,8 +319,8 @@ class MessagePOSTTest(ZulipTestCase):
|
|||
"Only organization administrators and moderators can send to this stream.",
|
||||
)
|
||||
|
||||
# Cross realm bots should be allowed
|
||||
notification_bot = get_system_bot("notification-bot@zulip.com")
|
||||
# System bots should be allowed
|
||||
notification_bot = get_system_bot("notification-bot@zulip.com", stream.realm_id)
|
||||
internal_send_stream_message(
|
||||
notification_bot, stream, "Test topic", "Test message by notification bot"
|
||||
)
|
||||
|
@ -425,8 +425,8 @@ class MessagePOSTTest(ZulipTestCase):
|
|||
moderator_owned_bot.save()
|
||||
self._send_and_verify_message(moderator_owned_bot, stream_name)
|
||||
|
||||
# Cross realm bots should be allowed
|
||||
notification_bot = get_system_bot("notification-bot@zulip.com")
|
||||
# System bots should be allowed
|
||||
notification_bot = get_system_bot("notification-bot@zulip.com", stream.realm_id)
|
||||
internal_send_stream_message(
|
||||
notification_bot, stream, "Test topic", "Test message by notification bot"
|
||||
)
|
||||
|
@ -2058,7 +2058,8 @@ class PersonalMessageSendTest(ZulipTestCase):
|
|||
self.send_personal_message(user_profile, self.example_user("cordelia"))
|
||||
|
||||
bot_profile = self.create_test_bot("testbot", user_profile)
|
||||
self.send_personal_message(user_profile, get_system_bot(settings.NOTIFICATION_BOT))
|
||||
notification_bot = get_system_bot("notification-bot@zulip.com", user_profile.realm_id)
|
||||
self.send_personal_message(user_profile, notification_bot)
|
||||
self.send_personal_message(user_profile, bot_profile)
|
||||
self.send_personal_message(bot_profile, user_profile)
|
||||
|
||||
|
@ -2342,7 +2343,9 @@ class TestCrossRealmPMs(ZulipTestCase):
|
|||
user1a = self.create_user(user1a_email)
|
||||
user2 = self.create_user(user2_email)
|
||||
user3 = self.create_user(user3_email)
|
||||
notification_bot = get_system_bot(notification_bot_email)
|
||||
|
||||
internal_realm = get_realm(settings.SYSTEM_BOT_REALM)
|
||||
notification_bot = get_system_bot(notification_bot_email, internal_realm.id)
|
||||
with self.settings(
|
||||
CROSS_REALM_BOT_EMAILS=["notification-bot@zulip.com", "welcome-bot@zulip.com"]
|
||||
):
|
||||
|
@ -2362,7 +2365,7 @@ class TestCrossRealmPMs(ZulipTestCase):
|
|||
# Cross-realm bots in the zulip.com realm can PM any realm
|
||||
# (They need lower level APIs to do this.)
|
||||
internal_send_private_message(
|
||||
sender=get_system_bot(notification_bot_email),
|
||||
sender=notification_bot,
|
||||
recipient_user=get_user(user2_email, r2),
|
||||
content="bla",
|
||||
)
|
||||
|
@ -2375,7 +2378,7 @@ class TestCrossRealmPMs(ZulipTestCase):
|
|||
# be used.
|
||||
internal_send_private_message(
|
||||
sender=user2,
|
||||
recipient_user=get_system_bot(notification_bot_email),
|
||||
recipient_user=notification_bot,
|
||||
content="blabla",
|
||||
)
|
||||
assert_message_received(notification_bot, user2)
|
||||
|
|
|
@ -139,9 +139,10 @@ class ArchiveMessagesTestingBase(RetentionTestingBase):
|
|||
def _send_cross_realm_personal_message(self) -> int:
|
||||
# Send message from bot to users from different realm.
|
||||
bot_email = "notification-bot@zulip.com"
|
||||
internal_realm = get_realm(settings.SYSTEM_BOT_REALM)
|
||||
zulip_user = self.example_user("hamlet")
|
||||
msg_id = internal_send_private_message(
|
||||
sender=get_system_bot(bot_email),
|
||||
sender=get_system_bot(bot_email, internal_realm.id),
|
||||
recipient_user=zulip_user,
|
||||
content="test message",
|
||||
)
|
||||
|
|
|
@ -2834,7 +2834,8 @@ class EmailUnsubscribeTests(ZulipTestCase):
|
|||
class RealmCreationTest(ZulipTestCase):
|
||||
@override_settings(OPEN_REALM_CREATION=True)
|
||||
def check_able_to_create_realm(self, email: str, password: str = "test") -> None:
|
||||
notification_bot = get_system_bot(settings.NOTIFICATION_BOT)
|
||||
internal_realm = get_realm(settings.SYSTEM_BOT_REALM)
|
||||
notification_bot = get_system_bot(settings.NOTIFICATION_BOT, internal_realm.id)
|
||||
signups_stream, _ = create_stream_if_needed(notification_bot.realm, "signups")
|
||||
|
||||
string_id = "zuliptest"
|
||||
|
|
|
@ -83,6 +83,7 @@ from zerver.models import (
|
|||
get_default_stream_groups,
|
||||
get_realm,
|
||||
get_stream,
|
||||
get_system_bot,
|
||||
get_user,
|
||||
get_user_profile_by_id_in_realm,
|
||||
)
|
||||
|
@ -278,7 +279,7 @@ class TestCreateStreams(ZulipTestCase):
|
|||
self.subscribe(iago, announce_stream.name)
|
||||
self.subscribe(hamlet, announce_stream.name)
|
||||
|
||||
notification_bot = UserProfile.objects.get(full_name="Notification Bot")
|
||||
notification_bot = get_system_bot(settings.NOTIFICATION_BOT, realm.id)
|
||||
self.login_user(iago)
|
||||
|
||||
initial_message_count = Message.objects.count()
|
||||
|
|
|
@ -13,7 +13,7 @@ class TutorialTests(ZulipTestCase):
|
|||
# This is only a quick fix - ideally, we would have this message sent by the initialization
|
||||
# code in populate_db.py
|
||||
user = self.example_user("hamlet")
|
||||
welcome_bot = get_system_bot(settings.WELCOME_BOT)
|
||||
welcome_bot = get_system_bot(settings.WELCOME_BOT, user.realm_id)
|
||||
content = "Shortened welcome message."
|
||||
internal_send_private_message(welcome_bot, user, content)
|
||||
|
||||
|
@ -34,7 +34,7 @@ class TutorialTests(ZulipTestCase):
|
|||
|
||||
def test_single_response_to_pm(self) -> None:
|
||||
user = self.example_user("hamlet")
|
||||
bot = get_system_bot(settings.WELCOME_BOT)
|
||||
bot = get_system_bot(settings.WELCOME_BOT, user.realm_id)
|
||||
content = "whatever"
|
||||
self.login_user(user)
|
||||
self.send_personal_message(user, bot, content)
|
||||
|
@ -52,7 +52,7 @@ class TutorialTests(ZulipTestCase):
|
|||
def test_no_response_to_group_pm(self) -> None:
|
||||
user1 = self.example_user("hamlet")
|
||||
user2 = self.example_user("cordelia")
|
||||
bot = get_system_bot(settings.WELCOME_BOT)
|
||||
bot = get_system_bot(settings.WELCOME_BOT, user1.realm_id)
|
||||
content = "whatever"
|
||||
self.login_user(user1)
|
||||
self.send_huddle_message(user1, [bot, user2], content)
|
||||
|
|
|
@ -588,7 +588,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
|
|||
body = f"First message ...[zulip.txt](http://{host}/user_uploads/" + fp_path_id + ")"
|
||||
with self.settings(CROSS_REALM_BOT_EMAILS={user_2.email, user_3.email}):
|
||||
internal_send_private_message(
|
||||
sender=get_system_bot(user_2.email),
|
||||
sender=get_system_bot(user_2.email, user_2.realm_id),
|
||||
recipient_user=user_1,
|
||||
content=body,
|
||||
)
|
||||
|
@ -1017,7 +1017,8 @@ class AvatarTest(UploadSerializeMixin, ZulipTestCase):
|
|||
cordelia.email = cordelia.delivery_email
|
||||
cordelia.save()
|
||||
|
||||
cross_realm_bot = get_system_bot(settings.WELCOME_BOT)
|
||||
internal_realm = get_realm(settings.SYSTEM_BOT_REALM)
|
||||
cross_realm_bot = get_system_bot(settings.WELCOME_BOT, internal_realm.id)
|
||||
|
||||
cordelia.avatar_source = UserProfile.AVATAR_FROM_USER
|
||||
cordelia.save()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from django.conf import settings
|
||||
|
||||
from zerver.lib.test_classes import WebhookTestCase
|
||||
from zerver.models import get_system_bot
|
||||
from zerver.models import get_realm, get_system_bot
|
||||
|
||||
|
||||
class HelloWorldHookTests(WebhookTestCase):
|
||||
|
@ -51,7 +51,8 @@ class HelloWorldHookTests(WebhookTestCase):
|
|||
# Note that this is really just a test for check_send_webhook_message
|
||||
self.STREAM_NAME = "nonexistent"
|
||||
self.url = self.build_webhook_url()
|
||||
notification_bot = get_system_bot(settings.NOTIFICATION_BOT)
|
||||
realm = get_realm("zulip")
|
||||
notification_bot = get_system_bot(settings.NOTIFICATION_BOT, realm.id)
|
||||
expected_message = "Your bot `webhook-bot@zulip.com` tried to send a message to stream #**nonexistent**, but that stream does not exist. Click [here](#streams/new) to create it."
|
||||
self.send_and_test_private_message(
|
||||
"goodbye",
|
||||
|
|
Loading…
Reference in New Issue