zulip_botserver: Remove unused imports and do some other cleanup.

This commit is contained in:
Guitar1st 2018-05-14 19:08:03 +00:00
parent 292a3bc067
commit 641665c338
3 changed files with 19 additions and 23 deletions

View file

@ -1,14 +1,15 @@
from unittest import TestCase
import zulip_botserver.server
import json import json
from typing import Any, List, Dict, Mapping, Optional
from typing import Any, List, Dict, Optional
from unittest import TestCase
from zulip_botserver import server
class BotServerTestCase(TestCase): class BotServerTestCase(TestCase):
def setUp(self): def setUp(self):
# type: () -> None # type: () -> None
zulip_botserver.server.app.testing = True server.app.testing = True
self.app = zulip_botserver.server.app.test_client() self.app = server.app.test_client()
def assert_bot_server_response(self, def assert_bot_server_response(self,
available_bots=None, available_bots=None,
@ -21,14 +22,14 @@ class BotServerTestCase(TestCase):
): ):
# type: (Optional[List[str]], Optional[Dict[str, Any]], Optional[Dict[str, Any]], Optional[Dict[str, Any]], str, Dict[str, Dict[str, Any]], bool) -> None # type: (Optional[List[str]], Optional[Dict[str, Any]], Optional[Dict[str, Any]], Optional[Dict[str, Any]], str, Dict[str, Dict[str, Any]], bool) -> None
if available_bots is not None: if available_bots is not None:
zulip_botserver.server.available_bots = available_bots server.available_bots = available_bots
zulip_botserver.server.bots_config = bots_config # type: ignore # monkey-patching server.bots_config = bots_config # type: ignore # monkey-patching
zulip_botserver.server.load_lib_modules() server.load_lib_modules()
zulip_botserver.server.load_bot_handlers() server.load_bot_handlers()
response = self.app.post(payload_url, data=json.dumps(message)) response = self.app.post(payload_url, data=json.dumps(message))
if check_success: if check_success:
assert response.status_code >= 200 and response.status_code < 300 assert 200 <= response.status_code < 300
else: else:
assert response.status_code >= 400 and response.status_code < 500 assert 400 <= response.status_code < 500

View file

@ -2,7 +2,6 @@ from __future__ import absolute_import
import mock import mock
import unittest import unittest
from typing import Any from typing import Any
from zulip_botserver import server
from .server_test_lib import BotServerTestCase from .server_test_lib import BotServerTestCase
import six import six

View file

@ -1,13 +1,11 @@
from __future__ import absolute_import
from __future__ import print_function
import os import os
import sys import sys
import json import json
import argparse import argparse
from flask import Flask, request from flask import Flask, request
from importlib import import_module from importlib import import_module
from typing import Any, Dict, Mapping, Union, List, Tuple from typing import Any, Dict, Mapping, Union, List
from werkzeug.exceptions import BadRequest from werkzeug.exceptions import BadRequest
from six.moves.configparser import SafeConfigParser from six.moves.configparser import SafeConfigParser
@ -122,19 +120,17 @@ def parse_args():
parser = argparse.ArgumentParser(usage=usage) parser = argparse.ArgumentParser(usage=usage)
parser.add_argument('--config-file', parser.add_argument('--config-file',
action='store', action='store',
help='(config file for the zulip bot server (flaskbotrc))') required=True,
help='Config file for the zulip bot server (flaskbotrc)')
parser.add_argument('--hostname', parser.add_argument('--hostname',
action='store', action='store',
default="127.0.0.1", default="127.0.0.1",
help='(address on which you want to run the server)') help='Address on which you want to run the server')
parser.add_argument('--port', parser.add_argument('--port',
action='store', action='store',
default=5002, default=5002,
help='(port on which you want to run the server)') help='Port on which you want to run the server')
options = parser.parse_args() return parser.parse_args()
if not options.config_file: # if flaskbotrc is not given
parser.error('Flaskbotrc not given')
return options
def main(): def main():