cleanup: Fix indentation.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
parent
07c64673f7
commit
bd9bb0a4e8
|
@ -292,9 +292,9 @@ def get_rooms(zulipToJabber: ZulipToJabberBot) -> List[str]:
|
||||||
|
|
||||||
rooms = [] # type: List[str]
|
rooms = [] # type: List[str]
|
||||||
for stream_info in stream_infos:
|
for stream_info in stream_infos:
|
||||||
stream = stream_info['name']
|
stream = stream_info['name']
|
||||||
if stream.endswith("/xmpp"):
|
if stream.endswith("/xmpp"):
|
||||||
rooms.append(stream_to_room(stream))
|
rooms.append(stream_to_room(stream))
|
||||||
return rooms
|
return rooms
|
||||||
|
|
||||||
def config_error(msg: str) -> None:
|
def config_error(msg: str) -> None:
|
||||||
|
|
|
@ -23,12 +23,12 @@ following the syntax shown below :smile:.\n \
|
||||||
def test_bot_responds_to_empty_message(self) -> None:
|
def test_bot_responds_to_empty_message(self) -> None:
|
||||||
with self.mock_config_info(self.normal_config), \
|
with self.mock_config_info(self.normal_config), \
|
||||||
self.mock_http_conversation('test_valid_auth_token'):
|
self.mock_http_conversation('test_valid_auth_token'):
|
||||||
self.verify_reply('', self.help_message)
|
self.verify_reply('', self.help_message)
|
||||||
|
|
||||||
def test_help_message(self) -> None:
|
def test_help_message(self) -> None:
|
||||||
with self.mock_config_info(self.normal_config), \
|
with self.mock_config_info(self.normal_config), \
|
||||||
self.mock_http_conversation('test_valid_auth_token'):
|
self.mock_http_conversation('test_valid_auth_token'):
|
||||||
self.verify_reply('help', self.help_message)
|
self.verify_reply('help', self.help_message)
|
||||||
|
|
||||||
def test_message_with_daystamp_and_value(self) -> None:
|
def test_message_with_daystamp_and_value(self) -> None:
|
||||||
bot_response = '[Datapoint](https://www.beeminder.com/aaron/goal) created.'
|
bot_response = '[Datapoint](https://www.beeminder.com/aaron/goal) created.'
|
||||||
|
@ -54,9 +54,9 @@ following the syntax shown below :smile:.\n \
|
||||||
def test_syntax_error(self) -> None:
|
def test_syntax_error(self) -> None:
|
||||||
with self.mock_config_info(self.normal_config), \
|
with self.mock_config_info(self.normal_config), \
|
||||||
self.mock_http_conversation('test_valid_auth_token'):
|
self.mock_http_conversation('test_valid_auth_token'):
|
||||||
bot_response = "Make sure you follow the syntax.\n You can take a look \
|
bot_response = "Make sure you follow the syntax.\n You can take a look \
|
||||||
at syntax by: @mention-botname help"
|
at syntax by: @mention-botname help"
|
||||||
self.verify_reply("20180303, 50, comment, redundant comment", bot_response)
|
self.verify_reply("20180303, 50, comment, redundant comment", bot_response)
|
||||||
|
|
||||||
def test_connection_error_when_handle_message(self) -> None:
|
def test_connection_error_when_handle_message(self) -> None:
|
||||||
with self.mock_config_info(self.normal_config), \
|
with self.mock_config_info(self.normal_config), \
|
||||||
|
@ -84,7 +84,7 @@ right now.\nPlease try again later')
|
||||||
with self.mock_config_info(self.normal_config), \
|
with self.mock_config_info(self.normal_config), \
|
||||||
self.mock_http_conversation('test_valid_auth_token'), \
|
self.mock_http_conversation('test_valid_auth_token'), \
|
||||||
self.mock_http_conversation('test_error'):
|
self.mock_http_conversation('test_error'):
|
||||||
self.verify_reply(bot_request, bot_response)
|
self.verify_reply(bot_request, bot_response)
|
||||||
|
|
||||||
def test_invalid_when_initialize(self) -> None:
|
def test_invalid_when_initialize(self) -> None:
|
||||||
bot = get_bot_message_handler(self.bot_name)
|
bot = get_bot_message_handler(self.bot_name)
|
||||||
|
@ -95,7 +95,7 @@ right now.\nPlease try again later')
|
||||||
'goalname': 'goal'}), \
|
'goalname': 'goal'}), \
|
||||||
self.mock_http_conversation('test_invalid_when_initialize'), \
|
self.mock_http_conversation('test_invalid_when_initialize'), \
|
||||||
self.assertRaises(bot_handler.BotQuitException):
|
self.assertRaises(bot_handler.BotQuitException):
|
||||||
bot.initialize(bot_handler)
|
bot.initialize(bot_handler)
|
||||||
|
|
||||||
def test_connection_error_during_initialize(self) -> None:
|
def test_connection_error_during_initialize(self) -> None:
|
||||||
bot = get_bot_message_handler(self.bot_name)
|
bot = get_bot_message_handler(self.bot_name)
|
||||||
|
|
|
@ -183,33 +183,33 @@ def dbx_read(client: Any, fn: str) -> str:
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
def dbx_search(client: Any, query: str, folder: str, max_results: str) -> str:
|
def dbx_search(client: Any, query: str, folder: str, max_results: str) -> str:
|
||||||
if folder is None:
|
if folder is None:
|
||||||
folder = ''
|
folder = ''
|
||||||
else:
|
else:
|
||||||
folder = '/' + folder
|
folder = '/' + folder
|
||||||
if max_results is None:
|
if max_results is None:
|
||||||
max_results = '20'
|
max_results = '20'
|
||||||
try:
|
try:
|
||||||
result = client.files_search(folder, query, max_results=int(max_results))
|
result = client.files_search(folder, query, max_results=int(max_results))
|
||||||
msg_list = []
|
msg_list = []
|
||||||
count = 0
|
count = 0
|
||||||
for entry in result.matches:
|
for entry in result.matches:
|
||||||
file_info = entry.metadata
|
file_info = entry.metadata
|
||||||
count += 1
|
count += 1
|
||||||
msg_list += [" - " + URL.format(name=file_info.name, path=file_info.path_lower)]
|
msg_list += [" - " + URL.format(name=file_info.name, path=file_info.path_lower)]
|
||||||
msg = '\n'.join(msg_list)
|
msg = '\n'.join(msg_list)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
msg = "Usage: `search <foldername> query --mr 10 --fd <folderName>`\n"\
|
msg = "Usage: `search <foldername> query --mr 10 --fd <folderName>`\n"\
|
||||||
"Note:`--mr <int>` is optional and is used to specify maximun results.\n"\
|
"Note:`--mr <int>` is optional and is used to specify maximun results.\n"\
|
||||||
" `--fd <folderName>` to search in specific folder."
|
" `--fd <folderName>` to search in specific folder."
|
||||||
|
|
||||||
if msg == '':
|
if msg == '':
|
||||||
msg = "No files/folders found matching your query.\n"\
|
msg = "No files/folders found matching your query.\n"\
|
||||||
"For file name searching, the last token is used for prefix matching"\
|
"For file name searching, the last token is used for prefix matching"\
|
||||||
" (i.e. “bat c” matches “bat cave” but not “batman car”)."
|
" (i.e. “bat c” matches “bat cave” but not “batman car”)."
|
||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
def dbx_share(client: Any, fn: str):
|
def dbx_share(client: Any, fn: str):
|
||||||
fn = '/' + fn
|
fn = '/' + fn
|
||||||
|
|
|
@ -41,13 +41,13 @@ right now.\nPlease try again later")
|
||||||
bot_response = "No user found. Make sure you typed it correctly."
|
bot_response = "No user found. Make sure you typed it correctly."
|
||||||
with self.mock_config_info(self.normal_config), \
|
with self.mock_config_info(self.normal_config), \
|
||||||
self.mock_http_conversation('test_no_recipient_found'):
|
self.mock_http_conversation('test_no_recipient_found'):
|
||||||
self.verify_reply('david: hello', bot_response)
|
self.verify_reply('david: hello', bot_response)
|
||||||
|
|
||||||
def test_found_invalid_recipient(self) -> None:
|
def test_found_invalid_recipient(self) -> None:
|
||||||
bot_response = "Found user is invalid."
|
bot_response = "Found user is invalid."
|
||||||
with self.mock_config_info(self.normal_config), \
|
with self.mock_config_info(self.normal_config), \
|
||||||
self.mock_http_conversation('test_found_invalid_recipient'):
|
self.mock_http_conversation('test_found_invalid_recipient'):
|
||||||
self.verify_reply('david: hello', bot_response)
|
self.verify_reply('david: hello', bot_response)
|
||||||
|
|
||||||
@patch('zulip_bots.bots.flock.flock.get_recipient_id')
|
@patch('zulip_bots.bots.flock.flock.get_recipient_id')
|
||||||
def test_message_send_connection_error(self, get_recipient_id: str) -> None:
|
def test_message_send_connection_error(self, get_recipient_id: str) -> None:
|
||||||
|
@ -64,7 +64,7 @@ right now.\nPlease try again later")
|
||||||
get_recipient_id.return_value = ["u:userid", None]
|
get_recipient_id.return_value = ["u:userid", None]
|
||||||
with self.mock_config_info(self.normal_config), \
|
with self.mock_config_info(self.normal_config), \
|
||||||
self.mock_http_conversation('test_message_send_success'):
|
self.mock_http_conversation('test_message_send_success'):
|
||||||
self.verify_reply('Rishabh: hi there', bot_response)
|
self.verify_reply('Rishabh: hi there', bot_response)
|
||||||
|
|
||||||
@patch('zulip_bots.bots.flock.flock.get_recipient_id')
|
@patch('zulip_bots.bots.flock.flock.get_recipient_id')
|
||||||
def test_message_send_failed(self, get_recipient_id: str) -> None:
|
def test_message_send_failed(self, get_recipient_id: str) -> None:
|
||||||
|
@ -72,4 +72,4 @@ right now.\nPlease try again later")
|
||||||
get_recipient_id.return_value = ["u:invalid", None]
|
get_recipient_id.return_value = ["u:invalid", None]
|
||||||
with self.mock_config_info(self.normal_config), \
|
with self.mock_config_info(self.normal_config), \
|
||||||
self.mock_http_conversation('test_message_send_failed'):
|
self.mock_http_conversation('test_message_send_failed'):
|
||||||
self.verify_reply('Rishabh: hi there', bot_response)
|
self.verify_reply('Rishabh: hi there', bot_response)
|
||||||
|
|
|
@ -16,11 +16,11 @@ class TestGoogleTranslateBot(BotTestCase, DefaultTests):
|
||||||
def _test(self, message, response, http_config_fixture, http_fixture=None):
|
def _test(self, message, response, http_config_fixture, http_fixture=None):
|
||||||
with self.mock_config_info({'key': 'abcdefg'}), \
|
with self.mock_config_info({'key': 'abcdefg'}), \
|
||||||
self.mock_http_conversation(http_config_fixture):
|
self.mock_http_conversation(http_config_fixture):
|
||||||
if http_fixture:
|
if http_fixture:
|
||||||
with self.mock_http_conversation(http_fixture):
|
with self.mock_http_conversation(http_fixture):
|
||||||
self.verify_reply(message, response)
|
self.verify_reply(message, response)
|
||||||
else:
|
else:
|
||||||
self.verify_reply(message, response)
|
self.verify_reply(message, response)
|
||||||
|
|
||||||
def test_normal(self):
|
def test_normal(self):
|
||||||
self._test('"hello" de', 'Hallo (from Foo Test User)', 'test_languages', 'test_normal')
|
self._test('"hello" de', 'Hallo (from Foo Test User)', 'test_languages', 'test_normal')
|
||||||
|
@ -76,6 +76,6 @@ class TestGoogleTranslateBot(BotTestCase, DefaultTests):
|
||||||
def test_connection_error(self):
|
def test_connection_error(self):
|
||||||
with patch('requests.post', side_effect=ConnectionError()), \
|
with patch('requests.post', side_effect=ConnectionError()), \
|
||||||
patch('logging.warning'):
|
patch('logging.warning'):
|
||||||
self._test('"test" en',
|
self._test('"test" en',
|
||||||
'Could not connect to Google Translate. .',
|
'Could not connect to Google Translate. .',
|
||||||
'test_languages')
|
'test_languages')
|
||||||
|
|
|
@ -91,7 +91,7 @@ def beat(message, topic_name, merels_storage):
|
||||||
return unknown_command()
|
return unknown_command()
|
||||||
|
|
||||||
if mechanics.get_take_status(topic_name, merels_storage) == 1:
|
if mechanics.get_take_status(topic_name, merels_storage) == 1:
|
||||||
same_player_move = "Take is required to proceed.\n"
|
same_player_move = "Take is required to proceed.\n"
|
||||||
return responses, same_player_move
|
return responses, same_player_move
|
||||||
|
|
||||||
elif match.group(4) is not None and match.group(5) is not None:
|
elif match.group(4) is not None and match.group(5) is not None:
|
||||||
|
|
|
@ -23,7 +23,7 @@ class TestYoutubeBot(BotTestCase, DefaultTests):
|
||||||
def test_bot_responds_to_empty_message(self) -> None:
|
def test_bot_responds_to_empty_message(self) -> None:
|
||||||
with self.mock_config_info(self.normal_config), \
|
with self.mock_config_info(self.normal_config), \
|
||||||
self.mock_http_conversation('test_keyok'):
|
self.mock_http_conversation('test_keyok'):
|
||||||
self.verify_reply('', self.help_content)
|
self.verify_reply('', self.help_content)
|
||||||
|
|
||||||
def test_single(self) -> None:
|
def test_single(self) -> None:
|
||||||
bot_response = 'Here is what I found for `funny cats` : \n'\
|
bot_response = 'Here is what I found for `funny cats` : \n'\
|
||||||
|
@ -32,7 +32,7 @@ class TestYoutubeBot(BotTestCase, DefaultTests):
|
||||||
|
|
||||||
with self.mock_config_info(self.normal_config), \
|
with self.mock_config_info(self.normal_config), \
|
||||||
self.mock_http_conversation('test_single'):
|
self.mock_http_conversation('test_single'):
|
||||||
self.verify_reply('funny cats', bot_response)
|
self.verify_reply('funny cats', bot_response)
|
||||||
|
|
||||||
def test_invalid_key(self) -> None:
|
def test_invalid_key(self) -> None:
|
||||||
bot = get_bot_message_handler(self.bot_name)
|
bot = get_bot_message_handler(self.bot_name)
|
||||||
|
@ -41,7 +41,7 @@ class TestYoutubeBot(BotTestCase, DefaultTests):
|
||||||
with self.mock_config_info({'key': 'somethinginvalid', 'number_of_results': '5', 'video_region': 'US'}), \
|
with self.mock_config_info({'key': 'somethinginvalid', 'number_of_results': '5', 'video_region': 'US'}), \
|
||||||
self.mock_http_conversation('test_invalid_key'), \
|
self.mock_http_conversation('test_invalid_key'), \
|
||||||
self.assertRaises(bot_handler.BotQuitException):
|
self.assertRaises(bot_handler.BotQuitException):
|
||||||
bot.initialize(bot_handler)
|
bot.initialize(bot_handler)
|
||||||
|
|
||||||
def test_unknown_error(self) -> None:
|
def test_unknown_error(self) -> None:
|
||||||
bot = get_bot_message_handler(self.bot_name)
|
bot = get_bot_message_handler(self.bot_name)
|
||||||
|
@ -50,7 +50,7 @@ class TestYoutubeBot(BotTestCase, DefaultTests):
|
||||||
with self.mock_config_info(self.normal_config), \
|
with self.mock_config_info(self.normal_config), \
|
||||||
self.mock_http_conversation('test_unknown_error'), \
|
self.mock_http_conversation('test_unknown_error'), \
|
||||||
self.assertRaises(HTTPError):
|
self.assertRaises(HTTPError):
|
||||||
bot.initialize(bot_handler)
|
bot.initialize(bot_handler)
|
||||||
|
|
||||||
def test_multiple(self) -> None:
|
def test_multiple(self) -> None:
|
||||||
get_bot_message_handler(self.bot_name)
|
get_bot_message_handler(self.bot_name)
|
||||||
|
@ -65,7 +65,7 @@ class TestYoutubeBot(BotTestCase, DefaultTests):
|
||||||
|
|
||||||
with self.mock_config_info(self.normal_config), \
|
with self.mock_config_info(self.normal_config), \
|
||||||
self.mock_http_conversation('test_multiple'):
|
self.mock_http_conversation('test_multiple'):
|
||||||
self.verify_reply('list marvel', bot_response)
|
self.verify_reply('list marvel', bot_response)
|
||||||
|
|
||||||
def test_noresult(self) -> None:
|
def test_noresult(self) -> None:
|
||||||
bot_response = 'Oops ! Sorry I couldn\'t find any video for `somethingrandomwithnoresult` ' \
|
bot_response = 'Oops ! Sorry I couldn\'t find any video for `somethingrandomwithnoresult` ' \
|
||||||
|
@ -79,10 +79,10 @@ class TestYoutubeBot(BotTestCase, DefaultTests):
|
||||||
help_content = self.help_content
|
help_content = self.help_content
|
||||||
with self.mock_config_info(self.normal_config), \
|
with self.mock_config_info(self.normal_config), \
|
||||||
self.mock_http_conversation('test_keyok'):
|
self.mock_http_conversation('test_keyok'):
|
||||||
self.verify_reply('help', help_content)
|
self.verify_reply('help', help_content)
|
||||||
self.verify_reply('list', help_content)
|
self.verify_reply('list', help_content)
|
||||||
self.verify_reply('help list', help_content)
|
self.verify_reply('help list', help_content)
|
||||||
self.verify_reply('top', help_content)
|
self.verify_reply('top', help_content)
|
||||||
|
|
||||||
def test_connection_error(self) -> None:
|
def test_connection_error(self) -> None:
|
||||||
with self.mock_config_info(self.normal_config), \
|
with self.mock_config_info(self.normal_config), \
|
||||||
|
|
|
@ -73,9 +73,9 @@ class TestDefaultArguments(TestCase):
|
||||||
with patch('sys.argv', ['zulip-run-bot', 'bot.module.name', '--config-file', '/path/to/config']):
|
with patch('sys.argv', ['zulip-run-bot', 'bot.module.name', '--config-file', '/path/to/config']):
|
||||||
with patch('importlib.import_module', return_value=mock_bot_module) as mock_import_module:
|
with patch('importlib.import_module', return_value=mock_bot_module) as mock_import_module:
|
||||||
with patch('zulip_bots.run.run_message_handler_for_bot'):
|
with patch('zulip_bots.run.run_message_handler_for_bot'):
|
||||||
with patch('zulip_bots.run.exit_gracefully_if_zulip_config_is_missing'):
|
with patch('zulip_bots.run.exit_gracefully_if_zulip_config_is_missing'):
|
||||||
zulip_bots.run.main()
|
zulip_bots.run.main()
|
||||||
mock_import_module.assert_called_once_with(bot_module_name)
|
mock_import_module.assert_called_once_with(bot_module_name)
|
||||||
|
|
||||||
|
|
||||||
class TestBotLib(TestCase):
|
class TestBotLib(TestCase):
|
||||||
|
|
Loading…
Reference in a new issue