2018-05-23 05:40:28 +02:00
|
|
|
from zerver.lib.onboarding import create_if_missing_realm_internal_bots
|
2020-06-11 00:54:34 +02:00
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
|
|
|
from zerver.models import Realm, UserProfile
|
|
|
|
|
2018-05-23 05:40:28 +02:00
|
|
|
|
|
|
|
class TestRealmInternalBotCreation(ZulipTestCase):
|
|
|
|
def test_create_if_missing_realm_internal_bots(self) -> None:
|
2021-02-12 08:19:30 +01:00
|
|
|
realm_internal_bots_dict = [
|
2021-02-12 08:20:45 +01:00
|
|
|
{"var_name": "TEST_BOT", "email_template": "test-bot@%s", "name": "Test Bot"}
|
2021-02-12 08:19:30 +01:00
|
|
|
]
|
2018-05-23 05:40:28 +02:00
|
|
|
|
|
|
|
def check_test_bot_exists() -> bool:
|
|
|
|
all_realms_count = Realm.objects.count()
|
|
|
|
all_test_bot_count = UserProfile.objects.filter(
|
2021-02-12 08:20:45 +01:00
|
|
|
email="test-bot@zulip.com",
|
2018-05-23 05:40:28 +02:00
|
|
|
).count()
|
|
|
|
return all_realms_count == all_test_bot_count
|
|
|
|
|
|
|
|
self.assertFalse(check_test_bot_exists())
|
|
|
|
with self.settings(REALM_INTERNAL_BOTS=realm_internal_bots_dict):
|
|
|
|
create_if_missing_realm_internal_bots()
|
|
|
|
self.assertTrue(check_test_bot_exists())
|