mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 09:27:43 +00:00
Change bot domains to string_id.EXTERNAL_HOST.
Change applies to both subdomains and non-subdomains case, though we use just the EXTERNAL_HOST in the non-subdomains case if there is only 1 realm. Fixes #3903.
This commit is contained in:
@@ -115,12 +115,19 @@ casper.then(function create_bot() {
|
||||
bot_default_events_register_stream: 'Rome',
|
||||
});
|
||||
|
||||
casper.test.info('Submiting the create bot form');
|
||||
casper.test.info('Submitting the create bot form');
|
||||
casper.click('#create_bot_button');
|
||||
});
|
||||
|
||||
var bot_email;
|
||||
if (REALMS_HAVE_SUBDOMAINS) {
|
||||
bot_email = '1-bot@zulip.zulipdev.com';
|
||||
} else {
|
||||
bot_email = '1-bot@zulip.localhost';
|
||||
}
|
||||
|
||||
casper.then(function () {
|
||||
var button_sel = '.download_bot_zuliprc[data-email="1-bot@zulip.com"]';
|
||||
var button_sel = '.download_bot_zuliprc[data-email="' + bot_email + '"]';
|
||||
|
||||
casper.waitUntilVisible(button_sel, function () {
|
||||
casper.click(button_sel);
|
||||
@@ -135,15 +142,15 @@ casper.then(function () {
|
||||
});
|
||||
|
||||
casper.then(function () {
|
||||
casper.waitUntilVisible('.open_edit_bot_form[data-email="1-bot@zulip.com"]', function open_edit_bot_form() {
|
||||
casper.waitUntilVisible('.open_edit_bot_form[data-email="' + bot_email + '"]', function open_edit_bot_form() {
|
||||
casper.test.info('Opening edit bot form');
|
||||
casper.click('.open_edit_bot_form[data-email="1-bot@zulip.com"]');
|
||||
casper.click('.open_edit_bot_form[data-email="' + bot_email + '"]');
|
||||
});
|
||||
});
|
||||
|
||||
casper.then(function () {
|
||||
casper.waitUntilVisible('.edit_bot_form[data-email="1-bot@zulip.com"]', function test_edit_bot_form_values() {
|
||||
var form_sel = '.edit_bot_form[data-email="1-bot@zulip.com"]';
|
||||
casper.waitUntilVisible('.edit_bot_form[data-email="' + bot_email + '"]', function test_edit_bot_form_values() {
|
||||
var form_sel = '.edit_bot_form[data-email="' + bot_email + '"]';
|
||||
casper.test.info('Testing edit bot form values');
|
||||
|
||||
// casper.test.assertEqual(
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<label for="bot_short_name">{{t "Username" }}</label>
|
||||
<input type="text" name="bot_short_name" id="create_bot_short_name" class="required bot_local_part"
|
||||
placeholder="bot_user_name" value="" />
|
||||
-{{t "bot" }}@{{ page_params.domain }}
|
||||
-bot@{{ page_params.realm_bot_domain }}
|
||||
<div>
|
||||
<label for="create_bot_short_name" generated="true" class="text-error"></label>
|
||||
</div>
|
||||
|
||||
@@ -52,7 +52,8 @@ def server_is_up(server, log_file):
|
||||
return False
|
||||
|
||||
@contextmanager
|
||||
def test_server_running(force=False, external_host='testserver', log_file=None, dots=False, use_db=True):
|
||||
def test_server_running(force=False, external_host='testserver',
|
||||
log_file=None, dots=False, use_db=True):
|
||||
# type: (bool, str, str, bool, bool) -> Iterator[None]
|
||||
if log_file:
|
||||
if os.path.exists(log_file) and os.path.getsize(log_file) < 100000:
|
||||
|
||||
@@ -107,6 +107,7 @@ def fetch_initial_state_data(user_profile, event_types, queue_id,
|
||||
state['realm_icon_source'] = user_profile.realm.icon_source
|
||||
state['realm_email_changes_disabled'] = user_profile.realm.email_changes_disabled
|
||||
state['max_icon_file_size'] = settings.MAX_ICON_FILE_SIZE
|
||||
state['realm_bot_domain'] = user_profile.realm.get_bot_domain()
|
||||
|
||||
if want('realm_domain'):
|
||||
state['realm_domain'] = user_profile.realm.domain
|
||||
|
||||
@@ -191,6 +191,16 @@ class Realm(ModelReprMixin, models.Model):
|
||||
# TODO: Change return type to QuerySet[UserProfile]
|
||||
return UserProfile.objects.filter(realm=self, is_active=True).select_related()
|
||||
|
||||
def get_bot_domain(self):
|
||||
# type: () -> str
|
||||
# Remove the port. Mainly needed for development environment.
|
||||
external_host = settings.EXTERNAL_HOST.split(':')[0]
|
||||
if settings.REALMS_HAVE_SUBDOMAINS or \
|
||||
Realm.objects.filter(deactivated=False) \
|
||||
.exclude(string_id__in=settings.SYSTEM_ONLY_REALMS).count() > 1:
|
||||
return "%s.%s" % (self.string_id, external_host)
|
||||
return external_host
|
||||
|
||||
@property
|
||||
def subdomain(self):
|
||||
# type: () -> Optional[Text]
|
||||
|
||||
@@ -1091,7 +1091,8 @@ class TestZulipRemoteUserBackend(ZulipTestCase):
|
||||
with self.settings(REALMS_HAVE_SUBDOMAINS=True,
|
||||
AUTHENTICATION_BACKENDS=('zproject.backends.ZulipRemoteUserBackend',)):
|
||||
with mock.patch('zerver.views.auth.get_subdomain', return_value='acme'):
|
||||
result = self.client_post('http://testserver:9080/accounts/login/sso/', REMOTE_USER=email)
|
||||
result = self.client_post('http://testserver:9080/accounts/login/sso/',
|
||||
REMOTE_USER=email)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assertIs(get_session_dict_user(self.client.session), None)
|
||||
self.assertIn(b"Let's get started", result.content)
|
||||
@@ -1102,7 +1103,8 @@ class TestZulipRemoteUserBackend(ZulipTestCase):
|
||||
with self.settings(REALMS_HAVE_SUBDOMAINS=True,
|
||||
AUTHENTICATION_BACKENDS=('zproject.backends.ZulipRemoteUserBackend',)):
|
||||
with mock.patch('zerver.views.auth.get_subdomain', return_value=''):
|
||||
result = self.client_post('http://testserver:9080/accounts/login/sso/', REMOTE_USER=email)
|
||||
result = self.client_post('http://testserver:9080/accounts/login/sso/',
|
||||
REMOTE_USER=email)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assertIs(get_session_dict_user(self.client.session), None)
|
||||
self.assertIn(b"Let's get started", result.content)
|
||||
|
||||
@@ -38,9 +38,23 @@ class BotTest(ZulipTestCase):
|
||||
self.assert_json_success(result)
|
||||
return ujson.loads(result.content)
|
||||
|
||||
def test_bot_domain(self):
|
||||
# type: () -> None
|
||||
self.login("hamlet@zulip.com")
|
||||
self.create_bot()
|
||||
self.assertTrue(UserProfile.objects.filter(email='hambot-bot@zulip.testserver').exists())
|
||||
# The other cases are hard to test directly, since we don't allow creating bots from
|
||||
# the wrong subdomain, and because 'testserver.example.com' is not a valid domain for the bot's email.
|
||||
# So we just test the Raelm.get_bot_domain function.
|
||||
realm = get_realm('zulip')
|
||||
with self.settings(REALMS_HAVE_SUBDOMAINS=True):
|
||||
self.assertEqual(realm.get_bot_domain(), 'zulip.testserver')
|
||||
Realm.objects.exclude(string_id='zulip').update(deactivated=True)
|
||||
self.assertEqual(realm.get_bot_domain(), 'testserver')
|
||||
|
||||
def deactivate_bot(self):
|
||||
# type: () -> None
|
||||
result = self.client_delete("/json/bots/hambot-bot@zulip.com")
|
||||
result = self.client_delete("/json/bots/hambot-bot@zulip.testserver")
|
||||
self.assert_json_success(result)
|
||||
|
||||
def test_add_bot_with_bad_username(self):
|
||||
@@ -64,14 +78,14 @@ class BotTest(ZulipTestCase):
|
||||
result = self.create_bot()
|
||||
self.assert_num_bots_equal(1)
|
||||
|
||||
bot = get_user_profile_by_email('hambot-bot@zulip.com')
|
||||
bot = get_user_profile_by_email('hambot-bot@zulip.testserver')
|
||||
|
||||
event = [e for e in events if e['event']['type'] == 'realm_bot'][0]
|
||||
self.assertEqual(
|
||||
dict(
|
||||
type='realm_bot',
|
||||
op='add',
|
||||
bot=dict(email='hambot-bot@zulip.com',
|
||||
bot=dict(email='hambot-bot@zulip.testserver',
|
||||
user_id=bot.id,
|
||||
full_name='The Bot of Hamlet',
|
||||
is_active=True,
|
||||
@@ -87,11 +101,11 @@ class BotTest(ZulipTestCase):
|
||||
|
||||
users_result = self.client_get('/json/users')
|
||||
members = ujson.loads(users_result.content)['members']
|
||||
bots = [m for m in members if m['email'] == 'hambot-bot@zulip.com']
|
||||
bots = [m for m in members if m['email'] == 'hambot-bot@zulip.testserver']
|
||||
self.assertEqual(len(bots), 1)
|
||||
bot = bots[0]
|
||||
self.assertEqual(bot['bot_owner'], 'hamlet@zulip.com')
|
||||
self.assertEqual(bot['user_id'], get_user_profile_by_email('hambot-bot@zulip.com').id)
|
||||
self.assertEqual(bot['user_id'], get_user_profile_by_email('hambot-bot@zulip.testserver').id)
|
||||
|
||||
def test_add_bot_with_username_in_use(self):
|
||||
# type: () -> None
|
||||
@@ -113,7 +127,7 @@ class BotTest(ZulipTestCase):
|
||||
self.assert_num_bots_equal(0)
|
||||
with get_test_image_file('img.png') as fp:
|
||||
self.create_bot(file=fp)
|
||||
profile = get_user_profile_by_email('hambot-bot@zulip.com')
|
||||
profile = get_user_profile_by_email('hambot-bot@zulip.testserver')
|
||||
# Make sure that avatar image that we've uploaded is same with avatar image in the server
|
||||
self.assertTrue(filecmp.cmp(fp.name,
|
||||
os.path.splitext(avatar_disk_path(profile))[0] +
|
||||
@@ -147,7 +161,7 @@ class BotTest(ZulipTestCase):
|
||||
self.assert_num_bots_equal(1)
|
||||
self.assertEqual(result['default_sending_stream'], 'Denmark')
|
||||
|
||||
profile = get_user_profile_by_email('hambot-bot@zulip.com')
|
||||
profile = get_user_profile_by_email('hambot-bot@zulip.testserver')
|
||||
self.assertEqual(profile.default_sending_stream.name, 'Denmark')
|
||||
|
||||
def test_add_bot_with_default_sending_stream_not_subscribed(self):
|
||||
@@ -158,7 +172,7 @@ class BotTest(ZulipTestCase):
|
||||
self.assert_num_bots_equal(1)
|
||||
self.assertEqual(result['default_sending_stream'], 'Rome')
|
||||
|
||||
profile = get_user_profile_by_email('hambot-bot@zulip.com')
|
||||
profile = get_user_profile_by_email('hambot-bot@zulip.testserver')
|
||||
self.assertEqual(profile.default_sending_stream.name, 'Rome')
|
||||
|
||||
def test_bot_add_subscription(self):
|
||||
@@ -192,7 +206,7 @@ class BotTest(ZulipTestCase):
|
||||
|
||||
# A bot
|
||||
bot_request_data = {
|
||||
'principals': '["hambot-bot@zulip.com"]'
|
||||
'principals': '["hambot-bot@zulip.testserver"]'
|
||||
}
|
||||
events_bot = [] # type: List[Dict[str, Any]]
|
||||
with tornado_redirected_to_list(events_bot):
|
||||
@@ -222,7 +236,7 @@ class BotTest(ZulipTestCase):
|
||||
self.assert_num_bots_equal(1)
|
||||
self.assertEqual(result['default_sending_stream'], 'Denmark')
|
||||
|
||||
profile = get_user_profile_by_email('hambot-bot@zulip.com')
|
||||
profile = get_user_profile_by_email('hambot-bot@zulip.testserver')
|
||||
self.assertEqual(profile.default_sending_stream.name, 'Denmark')
|
||||
|
||||
event = [e for e in events if e['event']['type'] == 'realm_bot'][0]
|
||||
@@ -230,7 +244,7 @@ class BotTest(ZulipTestCase):
|
||||
dict(
|
||||
type='realm_bot',
|
||||
op='add',
|
||||
bot=dict(email='hambot-bot@zulip.com',
|
||||
bot=dict(email='hambot-bot@zulip.testserver',
|
||||
user_id=profile.id,
|
||||
full_name='The Bot of Hamlet',
|
||||
is_active=True,
|
||||
@@ -269,7 +283,7 @@ class BotTest(ZulipTestCase):
|
||||
self.assert_num_bots_equal(1)
|
||||
self.assertEqual(result['default_events_register_stream'], 'Denmark')
|
||||
|
||||
profile = get_user_profile_by_email('hambot-bot@zulip.com')
|
||||
profile = get_user_profile_by_email('hambot-bot@zulip.testserver')
|
||||
self.assertEqual(profile.default_events_register_stream.name, 'Denmark')
|
||||
|
||||
def test_add_bot_with_default_events_register_stream_private_allowed(self):
|
||||
@@ -286,7 +300,7 @@ class BotTest(ZulipTestCase):
|
||||
self.assert_num_bots_equal(1)
|
||||
self.assertEqual(result['default_events_register_stream'], 'Denmark')
|
||||
|
||||
bot_profile = get_user_profile_by_email('hambot-bot@zulip.com')
|
||||
bot_profile = get_user_profile_by_email('hambot-bot@zulip.testserver')
|
||||
self.assertEqual(bot_profile.default_events_register_stream.name, 'Denmark')
|
||||
|
||||
event = [e for e in events if e['event']['type'] == 'realm_bot'][0]
|
||||
@@ -294,7 +308,7 @@ class BotTest(ZulipTestCase):
|
||||
dict(
|
||||
type='realm_bot',
|
||||
op='add',
|
||||
bot=dict(email='hambot-bot@zulip.com',
|
||||
bot=dict(email='hambot-bot@zulip.testserver',
|
||||
full_name='The Bot of Hamlet',
|
||||
user_id=bot_profile.id,
|
||||
is_active=True,
|
||||
@@ -334,7 +348,7 @@ class BotTest(ZulipTestCase):
|
||||
self.assert_num_bots_equal(1)
|
||||
self.assertTrue(result['default_all_public_streams'])
|
||||
|
||||
profile = get_user_profile_by_email('hambot-bot@zulip.com')
|
||||
profile = get_user_profile_by_email('hambot-bot@zulip.testserver')
|
||||
self.assertEqual(profile.default_all_public_streams, True)
|
||||
|
||||
def test_deactivate_bot(self):
|
||||
@@ -375,7 +389,7 @@ class BotTest(ZulipTestCase):
|
||||
result = self.client_delete("/json/bots/hamlet@zulip.com")
|
||||
self.assert_json_error(result, 'No such bot')
|
||||
|
||||
result = self.client_delete("/json/bots/hambot-bot@zulip.com")
|
||||
result = self.client_delete("/json/bots/hambot-bot@zulip.testserver")
|
||||
self.assert_json_error(result, 'Insufficient permission')
|
||||
|
||||
# But we don't actually deactivate the other person's bot.
|
||||
@@ -383,7 +397,7 @@ class BotTest(ZulipTestCase):
|
||||
self.assert_num_bots_equal(1)
|
||||
|
||||
# Can not deactivate a bot as a user
|
||||
result = self.client_delete("/json/users/hambot-bot@zulip.com")
|
||||
result = self.client_delete("/json/users/hambot-bot@zulip.testserver")
|
||||
self.assert_json_error(result, 'No such user')
|
||||
self.assert_num_bots_equal(1)
|
||||
|
||||
@@ -397,13 +411,13 @@ class BotTest(ZulipTestCase):
|
||||
# Have Othello try to mess with Hamlet's bots.
|
||||
self.login("othello@zulip.com")
|
||||
|
||||
result = self.client_post("/json/bots/hambot-bot@zulip.com/api_key/regenerate")
|
||||
result = self.client_post("/json/bots/hambot-bot@zulip.testserver/api_key/regenerate")
|
||||
self.assert_json_error(result, 'Insufficient permission')
|
||||
|
||||
bot_info = {
|
||||
'full_name': 'Fred',
|
||||
}
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.com", bot_info)
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.testserver", bot_info)
|
||||
self.assert_json_error(result, 'Insufficient permission')
|
||||
|
||||
def get_bot(self):
|
||||
@@ -418,7 +432,7 @@ class BotTest(ZulipTestCase):
|
||||
self.create_bot()
|
||||
bot = self.get_bot()
|
||||
old_api_key = bot['api_key']
|
||||
result = self.client_post('/json/bots/hambot-bot@zulip.com/api_key/regenerate')
|
||||
result = self.client_post('/json/bots/hambot-bot@zulip.testserver/api_key/regenerate')
|
||||
self.assert_json_success(result)
|
||||
new_api_key = ujson.loads(result.content)['api_key']
|
||||
self.assertNotEqual(old_api_key, new_api_key)
|
||||
@@ -443,7 +457,7 @@ class BotTest(ZulipTestCase):
|
||||
bot_info = {
|
||||
'full_name': 'Fred',
|
||||
}
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.com", bot_info)
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.testserver", bot_info)
|
||||
self.assert_json_success(result)
|
||||
|
||||
full_name = ujson.loads(result.content)['full_name']
|
||||
@@ -464,7 +478,7 @@ class BotTest(ZulipTestCase):
|
||||
bot_info = {
|
||||
'bot_owner': 'othello@zulip.com',
|
||||
}
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.com", bot_info)
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.testserver", bot_info)
|
||||
self.assert_json_success(result)
|
||||
|
||||
# Test bot's owner has been changed successfully.
|
||||
@@ -486,26 +500,26 @@ class BotTest(ZulipTestCase):
|
||||
result = self.client_post("/json/bots", bot_info)
|
||||
self.assert_json_success(result)
|
||||
|
||||
profile = get_user_profile_by_email('hambot-bot@zulip.com')
|
||||
profile = get_user_profile_by_email('hambot-bot@zulip.testserver')
|
||||
self.assertEqual(profile.avatar_source, UserProfile.AVATAR_FROM_GRAVATAR)
|
||||
|
||||
# Try error case first (too many files):
|
||||
with get_test_image_file('img.png') as fp1, \
|
||||
get_test_image_file('img.gif') as fp2:
|
||||
result = self.client_patch_multipart(
|
||||
'/json/bots/hambot-bot@zulip.com',
|
||||
'/json/bots/hambot-bot@zulip.testserver',
|
||||
dict(file1=fp1, file2=fp2))
|
||||
self.assert_json_error(result, 'You may only upload one file at a time')
|
||||
|
||||
profile = get_user_profile_by_email("hambot-bot@zulip.com")
|
||||
profile = get_user_profile_by_email("hambot-bot@zulip.testserver")
|
||||
self.assertEqual(profile.avatar_version, 1)
|
||||
|
||||
# HAPPY PATH
|
||||
with get_test_image_file('img.png') as fp:
|
||||
result = self.client_patch_multipart(
|
||||
'/json/bots/hambot-bot@zulip.com',
|
||||
'/json/bots/hambot-bot@zulip.testserver',
|
||||
dict(file=fp))
|
||||
profile = get_user_profile_by_email('hambot-bot@zulip.com')
|
||||
profile = get_user_profile_by_email('hambot-bot@zulip.testserver')
|
||||
self.assertEqual(profile.avatar_version, 2)
|
||||
# Make sure that avatar image that we've uploaded is same with avatar image in the server
|
||||
self.assertTrue(filecmp.cmp(fp.name,
|
||||
@@ -528,7 +542,7 @@ class BotTest(ZulipTestCase):
|
||||
bot_info = {
|
||||
'default_sending_stream': 'Denmark',
|
||||
}
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.com", bot_info)
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.testserver", bot_info)
|
||||
self.assert_json_success(result)
|
||||
|
||||
default_sending_stream = ujson.loads(result.content)['default_sending_stream']
|
||||
@@ -549,7 +563,7 @@ class BotTest(ZulipTestCase):
|
||||
bot_info = {
|
||||
'default_sending_stream': 'Rome',
|
||||
}
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.com", bot_info)
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.testserver", bot_info)
|
||||
self.assert_json_success(result)
|
||||
|
||||
default_sending_stream = ujson.loads(result.content)['default_sending_stream']
|
||||
@@ -570,11 +584,11 @@ class BotTest(ZulipTestCase):
|
||||
bot_info = {
|
||||
'default_sending_stream': '',
|
||||
}
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.com", bot_info)
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.testserver", bot_info)
|
||||
self.assert_json_success(result)
|
||||
|
||||
default_sending_stream = get_user_profile_by_email(
|
||||
"hambot-bot@zulip.com").default_sending_stream
|
||||
"hambot-bot@zulip.testserver").default_sending_stream
|
||||
self.assertEqual(None, default_sending_stream)
|
||||
|
||||
bot = self.get_bot()
|
||||
@@ -597,7 +611,7 @@ class BotTest(ZulipTestCase):
|
||||
bot_info = {
|
||||
'default_sending_stream': 'Denmark',
|
||||
}
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.com", bot_info)
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.testserver", bot_info)
|
||||
self.assert_json_success(result)
|
||||
|
||||
default_sending_stream = ujson.loads(result.content)['default_sending_stream']
|
||||
@@ -624,7 +638,7 @@ class BotTest(ZulipTestCase):
|
||||
bot_info = {
|
||||
'default_sending_stream': 'Denmark',
|
||||
}
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.com", bot_info)
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.testserver", bot_info)
|
||||
self.assert_json_error(result, "Invalid stream name 'Denmark'")
|
||||
|
||||
def test_patch_bot_to_stream_not_found(self):
|
||||
@@ -639,7 +653,7 @@ class BotTest(ZulipTestCase):
|
||||
bot_info = {
|
||||
'default_sending_stream': 'missing',
|
||||
}
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.com", bot_info)
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.testserver", bot_info)
|
||||
self.assert_json_error(result, "Invalid stream name 'missing'")
|
||||
|
||||
def test_patch_bot_events_register_stream(self):
|
||||
@@ -654,7 +668,7 @@ class BotTest(ZulipTestCase):
|
||||
bot_info = {
|
||||
'default_events_register_stream': 'Denmark',
|
||||
}
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.com", bot_info)
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.testserver", bot_info)
|
||||
self.assert_json_success(result)
|
||||
|
||||
default_events_register_stream = ujson.loads(result.content)['default_events_register_stream']
|
||||
@@ -679,7 +693,7 @@ class BotTest(ZulipTestCase):
|
||||
bot_info = {
|
||||
'default_events_register_stream': 'Denmark',
|
||||
}
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.com", bot_info)
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.testserver", bot_info)
|
||||
self.assert_json_success(result)
|
||||
|
||||
default_events_register_stream = ujson.loads(result.content)['default_events_register_stream']
|
||||
@@ -705,7 +719,7 @@ class BotTest(ZulipTestCase):
|
||||
bot_info = {
|
||||
'default_events_register_stream': 'Denmark',
|
||||
}
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.com", bot_info)
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.testserver", bot_info)
|
||||
self.assert_json_error(result, "Invalid stream name 'Denmark'")
|
||||
|
||||
def test_patch_bot_events_register_stream_none(self):
|
||||
@@ -720,11 +734,11 @@ class BotTest(ZulipTestCase):
|
||||
bot_info = {
|
||||
'default_events_register_stream': '',
|
||||
}
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.com", bot_info)
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.testserver", bot_info)
|
||||
self.assert_json_success(result)
|
||||
|
||||
default_events_register_stream = get_user_profile_by_email(
|
||||
"hambot-bot@zulip.com").default_events_register_stream
|
||||
"hambot-bot@zulip.testserver").default_events_register_stream
|
||||
self.assertEqual(None, default_events_register_stream)
|
||||
|
||||
bot = self.get_bot()
|
||||
@@ -742,7 +756,7 @@ class BotTest(ZulipTestCase):
|
||||
bot_info = {
|
||||
'default_events_register_stream': 'missing',
|
||||
}
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.com", bot_info)
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.testserver", bot_info)
|
||||
self.assert_json_error(result, "Invalid stream name 'missing'")
|
||||
|
||||
def test_patch_bot_default_all_public_streams_true(self):
|
||||
@@ -757,7 +771,7 @@ class BotTest(ZulipTestCase):
|
||||
bot_info = {
|
||||
'default_all_public_streams': ujson.dumps(True),
|
||||
}
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.com", bot_info)
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.testserver", bot_info)
|
||||
self.assert_json_success(result)
|
||||
|
||||
default_events_register_stream = ujson.loads(result.content)['default_all_public_streams']
|
||||
@@ -778,7 +792,7 @@ class BotTest(ZulipTestCase):
|
||||
bot_info = {
|
||||
'default_all_public_streams': ujson.dumps(False),
|
||||
}
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.com", bot_info)
|
||||
result = self.client_patch("/json/bots/hambot-bot@zulip.testserver", bot_info)
|
||||
self.assert_json_success(result)
|
||||
|
||||
default_events_register_stream = ujson.loads(result.content)['default_all_public_streams']
|
||||
@@ -800,7 +814,7 @@ class BotTest(ZulipTestCase):
|
||||
'full_name': 'Fred',
|
||||
'method': 'PATCH'
|
||||
}
|
||||
result = self.client_post("/json/bots/hambot-bot@zulip.com", bot_info)
|
||||
result = self.client_post("/json/bots/hambot-bot@zulip.testserver", bot_info)
|
||||
self.assert_json_success(result)
|
||||
|
||||
full_name = ujson.loads(result.content)['full_name']
|
||||
|
||||
@@ -97,6 +97,7 @@ class HomeTest(ZulipTestCase):
|
||||
"realm_add_emoji_by_admins_only",
|
||||
"realm_allow_message_editing",
|
||||
"realm_authentication_methods",
|
||||
"realm_bot_domain",
|
||||
"realm_create_stream_by_admins_only",
|
||||
"realm_default_language",
|
||||
"realm_default_streams",
|
||||
|
||||
@@ -1025,12 +1025,12 @@ class MessagePOSTTest(ZulipTestCase):
|
||||
result = self.client_post("/json/bots", bot_info)
|
||||
self.assert_json_success(result)
|
||||
|
||||
email = "irc-bot@zulip.com"
|
||||
email = "irc-bot@zulip.testserver"
|
||||
user = get_user_profile_by_email(email)
|
||||
user.is_api_super_user = True
|
||||
user.save()
|
||||
user = get_user_profile_by_email(email)
|
||||
self.subscribe_to_stream(email, "#IRCland")
|
||||
self.subscribe_to_stream(email, "#IRCland", realm=user.realm)
|
||||
result = self.client_post("/api/v1/messages",
|
||||
{"type": "stream",
|
||||
"forged": "true",
|
||||
|
||||
@@ -291,6 +291,7 @@ def home_real(request):
|
||||
'realm_add_emoji_by_admins_only',
|
||||
'realm_allow_message_editing',
|
||||
'realm_authentication_methods',
|
||||
'realm_bot_domain',
|
||||
'realm_create_stream_by_admins_only',
|
||||
'realm_default_language',
|
||||
'realm_default_streams',
|
||||
|
||||
@@ -238,7 +238,7 @@ def add_bot_backend(request, user_profile, full_name_raw=REQ("full_name"), short
|
||||
# type: (HttpRequest, UserProfile, Text, Text, Optional[Text], Optional[Text], Optional[bool]) -> HttpResponse
|
||||
short_name += "-bot"
|
||||
full_name = check_full_name(full_name_raw)
|
||||
email = short_name + "@" + user_profile.realm.domain
|
||||
email = '%s@%s' % (short_name, user_profile.realm.get_bot_domain())
|
||||
form = CreateUserForm({'full_name': full_name, 'email': email})
|
||||
if not form.is_valid():
|
||||
# We validate client-side as well
|
||||
|
||||
Reference in New Issue
Block a user