2017-06-18 05:15:40 -04:00
|
|
|
from unittest import TestCase
|
2017-07-18 00:01:54 -04:00
|
|
|
import zulip_botserver.server
|
2017-06-18 05:15:40 -04:00
|
|
|
import json
|
|
|
|
from typing import Any, List, Dict, Mapping
|
|
|
|
|
|
|
|
class BotServerTestCase(TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
# type: () -> None
|
2017-07-18 00:01:54 -04:00
|
|
|
zulip_botserver.server.app.testing = True
|
|
|
|
self.app = zulip_botserver.server.app.test_client()
|
2017-06-18 05:15:40 -04:00
|
|
|
|
|
|
|
def assert_bot_server_response(self,
|
|
|
|
available_bots=None,
|
|
|
|
bots_config=None,
|
|
|
|
bots_lib_module=None,
|
2017-11-07 06:57:47 -05:00
|
|
|
bot_handlers=None,
|
2017-11-07 07:17:32 -05:00
|
|
|
payload_url="/bots/helloworld",
|
2017-06-18 05:15:40 -04:00
|
|
|
message=dict(message={'key': "test message"}),
|
|
|
|
check_success=False,
|
|
|
|
):
|
2017-11-07 06:57:47 -05:00
|
|
|
# type: (List[str], Dict[str, Any], Dict[str, Any], Dict[str, Any], str, Dict[str, Dict[str, Any]], bool) -> None
|
2017-06-18 05:15:40 -04:00
|
|
|
if available_bots is not None:
|
2017-07-18 00:01:54 -04:00
|
|
|
zulip_botserver.server.available_bots = available_bots
|
|
|
|
zulip_botserver.server.bots_config = bots_config
|
2017-11-07 07:17:32 -05:00
|
|
|
zulip_botserver.server.load_lib_modules()
|
|
|
|
zulip_botserver.server.load_bot_handlers()
|
2017-11-07 06:57:47 -05:00
|
|
|
|
2017-06-18 05:15:40 -04:00
|
|
|
response = self.app.post(payload_url, data=json.dumps(message))
|
|
|
|
|
|
|
|
if check_success:
|
|
|
|
assert response.status_code >= 200 and response.status_code < 300
|
|
|
|
else:
|
|
|
|
assert response.status_code >= 400 and response.status_code < 500
|