Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
bots: Pass realm to remaining get_system_bot calls in tests.
Mateusz Manderac34260426a6b
diff --git a/zerver/tests/test_event_system.py b/zerver/tests/test_event_system.pyindex 2192d99689f..206e91f5121 100644--- a/zerver/tests/test_event_system.py+++ b/zerver/tests/test_event_system.py@@ -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"])diff --git a/zerver/tests/test_message_send.py b/zerver/tests/test_message_send.pyindex 0951d948d73..120c2ad4308 100644--- a/zerver/tests/test_message_send.py+++ b/zerver/tests/test_message_send.py@@ -240,7 +240,7 @@ class MessagePOSTTest(ZulipTestCase):)# Cross realm bots should be allowed- notification_bot = get_system_bot("[email protected]")+ notification_bot = get_system_bot("[email protected]", 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("[email protected]")+ # System bots should be allowed+ notification_bot = get_system_bot("[email protected]", 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("[email protected]")+ # System bots should be allowed+ notification_bot = get_system_bot("[email protected]", 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("[email protected]", 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=["[email protected]", "[email protected]"]):@@ -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)diff --git a/zerver/tests/test_retention.py b/zerver/tests/test_retention.pyindex 8b6d1e6a6d1..32c039b81c7 100644--- a/zerver/tests/test_retention.py+++ b/zerver/tests/test_retention.py@@ -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 = "[email protected]"+ 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",)diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex 97cb1d639f0..063a5912128 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -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"diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.pyindex 36cd2dec05f..89ac65ef69a 100644--- a/zerver/tests/test_subs.py+++ b/zerver/tests/test_subs.py@@ -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()diff --git a/zerver/tests/test_tutorial.py b/zerver/tests/test_tutorial.pyindex 5399337998e..fe680506238 100644--- a/zerver/tests/test_tutorial.py+++ b/zerver/tests/test_tutorial.py@@ -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.pyuser = 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)diff --git a/zerver/tests/test_upload.py b/zerver/tests/test_upload.pyindex 6f95e6066ab..84be88fb3ec 100644--- a/zerver/tests/test_upload.py+++ b/zerver/tests/test_upload.py@@ -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_emailcordelia.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_USERcordelia.save()diff --git a/zerver/webhooks/helloworld/tests.py b/zerver/webhooks/helloworld/tests.pyindex 9e7cbeba5b8..cf237b00933 100644--- a/zerver/webhooks/helloworld/tests.py+++ b/zerver/webhooks/helloworld/tests.py@@ -1,7 +1,7 @@from django.conf import settingsfrom zerver.lib.test_classes import WebhookTestCase-from zerver.models import get_system_bot+from zerver.models import get_realm, get_system_botclass HelloWorldHookTests(WebhookTestCase):@@ -51,7 +51,8 @@ class HelloWorldHookTests(WebhookTestCase):# Note that this is really just a test for check_send_webhook_messageself.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 `[email protected]` 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",