zulip_botserver: Change style of type annotations to python3

This commit is contained in:
Guitar1st 2018-05-14 19:45:54 +00:00
parent 641665c338
commit 2ba6f75fb3
3 changed files with 24 additions and 38 deletions

View file

@ -6,21 +6,19 @@ from zulip_botserver import server
class BotServerTestCase(TestCase):
def setUp(self):
# type: () -> None
def setUp(self) -> None:
server.app.testing = True
self.app = 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: (Optional[List[str]], Optional[Dict[str, Any]], Optional[Dict[str, Any]], Optional[Dict[str, Any]], str, Dict[str, Dict[str, Any]], bool) -> None
available_bots: Optional[List[str]]=None,
bots_config: Optional[Dict[str, Any]]=None,
bots_lib_module: Optional[Dict[str, Any]]=None,
bot_handlers: Optional[Dict[str, Any]]=None,
payload_url: str="/bots/helloworld",
message: Optional[Dict[str, Any]]=dict(message={'key': "test message"}),
check_success: bool=False,
) -> None:
if available_bots is not None:
server.available_bots = available_bots
server.bots_config = bots_config # type: ignore # monkey-patching

View file

@ -1,24 +1,20 @@
from __future__ import absolute_import
import mock
from typing import Any, Dict
import unittest
from typing import Any
from .server_test_lib import BotServerTestCase
import six
class BotServerTests(BotServerTestCase):
class MockMessageHandler(object):
def handle_message(self, message, bot_handler):
# type: (Any, Any, Any) -> None
def handle_message(self, message: Dict[str, str], bot_handler: Any) -> None:
assert message == {'key': "test message"}
class MockLibModule(object):
def handler_class(self):
# type: () -> Any
def handler_class(self) -> Any:
return BotServerTests.MockMessageHandler()
@mock.patch('zulip_botserver.server.ExternalBotHandler')
def test_successful_request(self, mock_ExternalBotHandler):
# type: (mock.Mock) -> None
def test_successful_request(self, mock_ExternalBotHandler: mock.Mock) -> None:
available_bots = ['helloworld']
bots_config = {
'helloworld': {
@ -31,16 +27,14 @@ class BotServerTests(BotServerTestCase):
bots_config=bots_config,
check_success=True)
def test_bot_module_not_exists(self):
# type: () -> None
def test_bot_module_not_exists(self) -> None:
self.assert_bot_server_response(available_bots=[],
payload_url="/bots/not_supported_bot",
check_success=False)
@mock.patch('logging.error')
@mock.patch('zulip_bots.lib.StateHandler')
def test_wrong_bot_credentials(self, mock_StateHandler, mock_LoggingError):
# type: (mock.Mock, mock.Mock) -> None
def test_wrong_bot_credentials(self, mock_StateHandler: mock.Mock, mock_LoggingError: mock.Mock) -> None:
available_bots = ['nonexistent-bot']
bots_config = {
'nonexistent-bot': {