mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 16:37:23 +00:00
Create back end for patching bots.
(imported from commit 189444d79bb7832b26f3e9c1b65da260122255bd)
This commit is contained in:
@@ -170,6 +170,8 @@ v1_api_and_json_patterns = patterns('zephyr.views',
|
||||
'PATCH': 'update_subscriptions_backend'}),
|
||||
url(r'^users/(?P<email>.*)$', 'rest_dispatch',
|
||||
{'DELETE': 'deactivate_user_backend'}),
|
||||
url(r'^bots/(?P<email>.*)$', 'rest_dispatch',
|
||||
{'PATCH': 'patch_bot_backend'}),
|
||||
url(r'^register$', 'rest_dispatch',
|
||||
{'POST': 'api_events_register'}),
|
||||
)
|
||||
|
||||
@@ -575,6 +575,42 @@ class BotTest(AuthedTestCase):
|
||||
self.login("hamlet@humbughq.com")
|
||||
self.assert_num_bots_equal(1)
|
||||
|
||||
def get_bot(self):
|
||||
result = self.client.post("/json/get_bots")
|
||||
bots = ujson.loads(result.content)['bots']
|
||||
return bots[0]
|
||||
|
||||
def test_patch_bot_full_name(self):
|
||||
self.login("hamlet@humbughq.com")
|
||||
bot_info = {
|
||||
'full_name': 'The Bot of Hamlet',
|
||||
'short_name': 'hambot',
|
||||
}
|
||||
result = self.client.post("/json/create_bot", bot_info)
|
||||
self.assert_json_success(result)
|
||||
bot_info = {
|
||||
'full_name': 'Fred',
|
||||
}
|
||||
result = self.client_patch("/json/bots/hambot-bot@humbughq.com", bot_info)
|
||||
self.assert_json_success(result)
|
||||
|
||||
full_name = ujson.loads(result.content)['full_name']
|
||||
self.assertEqual('Fred', full_name)
|
||||
|
||||
bot = self.get_bot()
|
||||
self.assertEqual('Fred', bot['full_name'])
|
||||
|
||||
def test_patch_bogus_bot(self):
|
||||
# Deleting a bogus bot will succeed silently.
|
||||
self.login("hamlet@humbughq.com")
|
||||
self.create_bot()
|
||||
bot_info = {
|
||||
'full_name': 'Fred',
|
||||
}
|
||||
result = self.client_patch("/json/bots/nonexistent-bot@humbughq.com", bot_info)
|
||||
self.assert_json_error(result, 'No such user')
|
||||
self.assert_num_bots_equal(1)
|
||||
|
||||
class PointerTest(AuthedTestCase):
|
||||
|
||||
def test_update_pointer(self):
|
||||
|
||||
@@ -1997,6 +1997,25 @@ def deactivate_user_backend(request, user_profile, email):
|
||||
do_deactivate(target)
|
||||
return json_success({})
|
||||
|
||||
@has_request_variables
|
||||
def patch_bot_backend(request, user_profile, email, full_name=REQ):
|
||||
# TODO:
|
||||
# 1) Validate data
|
||||
# 2) Support avatar changes
|
||||
# Note that API key changes will be done with a separate POST command:
|
||||
# POST /bots/[email]/api_key/regenerate
|
||||
try:
|
||||
bot = get_user_profile_by_email(email)
|
||||
except:
|
||||
return json_error('No such user')
|
||||
bot.full_name = full_name
|
||||
bot.save()
|
||||
|
||||
json_result = dict(
|
||||
full_name = full_name,
|
||||
)
|
||||
return json_success(json_result)
|
||||
|
||||
@authenticated_json_post_view
|
||||
@has_request_variables
|
||||
def json_create_bot(request, user_profile, full_name=REQ, short_name=REQ):
|
||||
|
||||
Reference in New Issue
Block a user