backend: Add bot config data to initial state data.

This commit is contained in:
Robert Hönig
2018-01-30 19:19:52 +01:00
committed by Tim Abbott
parent fd4aa88046
commit ade077ff73
2 changed files with 18 additions and 6 deletions

View File

@@ -1929,11 +1929,23 @@ def get_bot_services(user_profile_id: str) -> List[Service]:
return list(Service.objects.filter(user_profile__id=user_profile_id))
def get_service_dicts_for_bots(user_profile_id: str) -> List[Dict[str, Any]]:
user_profile = get_user_profile_by_id(user_profile_id)
services = get_bot_services(user_profile_id)
service_dicts = [{'base_url': service.base_url,
'interface': service.interface,
}
for service in services]
service_dicts = [] # type: List[Dict[Text, Any]]
if user_profile.bot_type == UserProfile.OUTGOING_WEBHOOK_BOT:
service_dicts = [{'base_url': service.base_url,
'interface': service.interface,
}
for service in services]
elif user_profile.bot_type == UserProfile.EMBEDDED_BOT:
from zerver.lib.bot_config import get_bot_config, ConfigError
try:
service_dicts = [{'config_data': get_bot_config(user_profile),
'service_name': services[0].name
}]
# A ConfigError just means that there are no config entries for user_profile.
except ConfigError:
pass
return service_dicts
def get_service_profile(user_profile_id: str, service_name: str) -> Service:

View File

@@ -186,8 +186,8 @@ class HomeTest(ZulipTestCase):
with patch('zerver.lib.cache.cache_set') as cache_mock:
result = self._get_home_page(stream='Denmark')
self.assert_length(queries, 41)
self.assert_length(cache_mock.call_args_list, 7)
self.assert_length(queries, 42)
self.assert_length(cache_mock.call_args_list, 8)
html = result.content.decode('utf-8')