From 641665c3381f2799193812447e042fef3510c4d6 Mon Sep 17 00:00:00 2001 From: Guitar1st Date: Mon, 14 May 2018 19:08:03 +0000 Subject: [PATCH] zulip_botserver: Remove unused imports and do some other cleanup. --- zulip_botserver/tests/server_test_lib.py | 23 ++++++++++++----------- zulip_botserver/tests/test_server.py | 1 - zulip_botserver/zulip_botserver/server.py | 18 +++++++----------- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/zulip_botserver/tests/server_test_lib.py b/zulip_botserver/tests/server_test_lib.py index 18364c5..70ecaff 100644 --- a/zulip_botserver/tests/server_test_lib.py +++ b/zulip_botserver/tests/server_test_lib.py @@ -1,14 +1,15 @@ -from unittest import TestCase -import zulip_botserver.server 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): def setUp(self): # type: () -> None - zulip_botserver.server.app.testing = True - self.app = zulip_botserver.server.app.test_client() + server.app.testing = True + self.app = server.app.test_client() def assert_bot_server_response(self, 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 if available_bots is not None: - zulip_botserver.server.available_bots = available_bots - zulip_botserver.server.bots_config = bots_config # type: ignore # monkey-patching - zulip_botserver.server.load_lib_modules() - zulip_botserver.server.load_bot_handlers() + server.available_bots = available_bots + server.bots_config = bots_config # type: ignore # monkey-patching + server.load_lib_modules() + 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 + assert 200 <= response.status_code < 300 else: - assert response.status_code >= 400 and response.status_code < 500 + assert 400 <= response.status_code < 500 diff --git a/zulip_botserver/tests/test_server.py b/zulip_botserver/tests/test_server.py index b870679..a295ff6 100644 --- a/zulip_botserver/tests/test_server.py +++ b/zulip_botserver/tests/test_server.py @@ -2,7 +2,6 @@ from __future__ import absolute_import import mock import unittest from typing import Any -from zulip_botserver import server from .server_test_lib import BotServerTestCase import six diff --git a/zulip_botserver/zulip_botserver/server.py b/zulip_botserver/zulip_botserver/server.py index 45d6680..cab082c 100644 --- a/zulip_botserver/zulip_botserver/server.py +++ b/zulip_botserver/zulip_botserver/server.py @@ -1,13 +1,11 @@ -from __future__ import absolute_import -from __future__ import print_function - import os import sys import json import argparse + from flask import Flask, request 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 six.moves.configparser import SafeConfigParser @@ -122,19 +120,17 @@ def parse_args(): parser = argparse.ArgumentParser(usage=usage) parser.add_argument('--config-file', 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', action='store', 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', action='store', default=5002, - help='(port on which you want to run the server)') - options = parser.parse_args() - if not options.config_file: # if flaskbotrc is not given - parser.error('Flaskbotrc not given') - return options + help='Port on which you want to run the server') + return parser.parse_args() def main():