python-zulip-api/zulip_botserver/tests/server_test_lib.py
derAnfaenger fb116259d0 zulip_botserver: Make tests more realistic.
Specifically, this invokes server.load_lib_modules()
and server.load_bot_handlers() to generate the modules
and handlers, instead of hardcoding them.
2017-11-10 18:36:20 -08:00

35 lines
1.4 KiB
Python

from unittest import TestCase
import zulip_botserver.server
import json
from typing import Any, List, Dict, Mapping
class BotServerTestCase(TestCase):
def setUp(self):
# type: () -> None
zulip_botserver.server.app.testing = True
self.app = zulip_botserver.server.app.test_client()
def assert_bot_server_response(self,
available_bots=None,
bots_config=None,
bots_lib_module=None,
bot_handlers=None,
payload_url="/bots/helloworld",
message=dict(message={'key': "test message"}),
check_success=False,
):
# type: (List[str], Dict[str, Any], Dict[str, Any], Dict[str, Any], str, Dict[str, Dict[str, Any]], bool) -> None
if available_bots is not None:
zulip_botserver.server.available_bots = available_bots
zulip_botserver.server.bots_config = bots_config
zulip_botserver.server.load_lib_modules()
zulip_botserver.server.load_bot_handlers()
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