bots: Simplify test_github_details.py.
This commit is contained in:
parent
f421e90a64
commit
5f70e17259
|
@ -1,25 +1,29 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from zulip_bots.test_lib import (
|
||||||
from __future__ import print_function
|
StubBotHandler,
|
||||||
|
StubBotTestCase,
|
||||||
import json
|
get_bot_message_handler,
|
||||||
|
)
|
||||||
from zulip_bots.test_lib import BotTestCase
|
|
||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
class TestGithubDetailBot(BotTestCase):
|
class TestGithubDetailBot(StubBotTestCase):
|
||||||
bot_name = "github_detail"
|
bot_name = "github_detail"
|
||||||
mock_config = {'owner': 'zulip', 'repo': 'zulip'}
|
mock_config = {'owner': 'zulip', 'repo': 'zulip'}
|
||||||
|
|
||||||
# Overrides default test_bot_usage().
|
# Overrides default test_bot_usage().
|
||||||
def test_bot_usage(self: Any) -> None:
|
def test_bot_usage(self: Any) -> None:
|
||||||
|
bot = get_bot_message_handler(self.bot_name)
|
||||||
|
bot_handler = StubBotHandler()
|
||||||
|
|
||||||
with self.mock_config_info(self.mock_config):
|
with self.mock_config_info(self.mock_config):
|
||||||
self.initialize_bot()
|
bot.initialize(bot_handler)
|
||||||
self.assertNotEqual(self.message_handler.usage(), '')
|
|
||||||
|
self.assertIn('displays details on github issues', bot.usage())
|
||||||
|
|
||||||
def test_issue(self: Any) -> None:
|
def test_issue(self: Any) -> None:
|
||||||
|
request = 'zulip/zulip#5365'
|
||||||
bot_response = '**[zulip/zulip#5365](https://github.com/zulip/zulip/issues/5365)'\
|
bot_response = '**[zulip/zulip#5365](https://github.com/zulip/zulip/issues/5365)'\
|
||||||
' - frontend: Enable hot-reloading of CSS in development**\n'\
|
' - frontend: Enable hot-reloading of CSS in development**\n'\
|
||||||
'Created by **[timabbott](https://github.com/timabbott)**\n'\
|
'Created by **[timabbott](https://github.com/timabbott)**\n'\
|
||||||
|
@ -29,15 +33,13 @@ class TestGithubDetailBot(BotTestCase):
|
||||||
'able to use the hot-reloading feature of webpack for managing our CSS.\r\n\r\n'\
|
'able to use the hot-reloading feature of webpack for managing our CSS.\r\n\r\n'\
|
||||||
'In order to do this, step 1 is to move our CSS minification pipeline '\
|
'In order to do this, step 1 is to move our CSS minification pipeline '\
|
||||||
'from django-pipeline to Webpack. \n```'
|
'from django-pipeline to Webpack. \n```'
|
||||||
# This message calls the `send_reply` function of BotHandlerApi
|
|
||||||
with self.mock_http_conversation('test_issue'):
|
with self.mock_http_conversation('test_issue'):
|
||||||
self.assert_bot_response(
|
with self.mock_config_info(self.mock_config):
|
||||||
message = {'content': 'zulip/zulip#5365'},
|
self.verify_reply(request, bot_response)
|
||||||
response = {'content': bot_response},
|
|
||||||
expected_method='send_reply'
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_pull_request(self: Any) -> None:
|
def test_pull_request(self: Any) -> None:
|
||||||
|
request = 'zulip/zulip#5345'
|
||||||
bot_response = '**[zulip/zulip#5345](https://github.com/zulip/zulip/pull/5345)'\
|
bot_response = '**[zulip/zulip#5345](https://github.com/zulip/zulip/pull/5345)'\
|
||||||
' - [WIP] modal: Replace bootstrap modal with custom modal class**\n'\
|
' - [WIP] modal: Replace bootstrap modal with custom modal class**\n'\
|
||||||
'Created by **[jackrzhang](https://github.com/jackrzhang)**\n'\
|
'Created by **[jackrzhang](https://github.com/jackrzhang)**\n'\
|
||||||
|
@ -49,45 +51,30 @@ class TestGithubDetailBot(BotTestCase):
|
||||||
'using bootstrap for the account settings modal and all other modals,'\
|
'using bootstrap for the account settings modal and all other modals,'\
|
||||||
' replace with `Modal` class\r\n[] Add hotkey support for closing the'\
|
' replace with `Modal` class\r\n[] Add hotkey support for closing the'\
|
||||||
' top modal for `Esc`\r\n\r\nThis should also be a helpful step in removing dependencies from Bootstrap.\n```'
|
' top modal for `Esc`\r\n\r\nThis should also be a helpful step in removing dependencies from Bootstrap.\n```'
|
||||||
# This message calls the `send_reply` function of BotHandlerApi
|
|
||||||
with self.mock_http_conversation('test_pull'):
|
with self.mock_http_conversation('test_pull'):
|
||||||
self.assert_bot_response(
|
with self.mock_config_info(self.mock_config):
|
||||||
message = {'content': 'zulip/zulip#5345'},
|
self.verify_reply(request, bot_response)
|
||||||
response = {'content': bot_response},
|
|
||||||
expected_method='send_reply'
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_404(self: Any) -> None:
|
def test_404(self: Any) -> None:
|
||||||
|
request = 'zulip/zulip#0'
|
||||||
bot_response = 'Failed to find issue/pr: zulip/zulip#0'
|
bot_response = 'Failed to find issue/pr: zulip/zulip#0'
|
||||||
# This message calls the `send_reply` function of BotHandlerApi
|
|
||||||
with self.mock_http_conversation('test_404'):
|
with self.mock_http_conversation('test_404'):
|
||||||
self.assert_bot_response(
|
with self.mock_config_info(self.mock_config):
|
||||||
message = {'content': 'zulip/zulip#0'},
|
self.verify_reply(request, bot_response)
|
||||||
response = {'content': bot_response},
|
|
||||||
expected_method='send_reply'
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_random_text(self: Any) -> None:
|
def test_random_text(self: Any) -> None:
|
||||||
|
request = 'some random text'
|
||||||
bot_response = 'Failed to find any issue or PR.'
|
bot_response = 'Failed to find any issue or PR.'
|
||||||
# This message calls the `send_reply` function of BotHandlerApi
|
with self.mock_config_info(self.mock_config):
|
||||||
self.assert_bot_response(
|
self.verify_reply(request, bot_response)
|
||||||
message = {'content': 'some random text'},
|
|
||||||
response = {'content': bot_response},
|
|
||||||
expected_method='send_reply'
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_help_text(self: Any) -> None:
|
def test_help_text(self: Any) -> None:
|
||||||
|
request = 'help'
|
||||||
bot_response = 'This plugin displays details on github issues and pull requests. '\
|
bot_response = 'This plugin displays details on github issues and pull requests. '\
|
||||||
'To reference an issue or pull request usename mention the bot then '\
|
'To reference an issue or pull request usename mention the bot then '\
|
||||||
'anytime in the message type its id, for example:\n@**Github detail** '\
|
'anytime in the message type its id, for example:\n@**Github detail** '\
|
||||||
'#3212 zulip#3212 zulip/zulip#3212\nThe default owner is zulip and '\
|
'#3212 zulip#3212 zulip/zulip#3212\nThe default owner is zulip and '\
|
||||||
'the default repo is zulip.'
|
'the default repo is zulip.'
|
||||||
# This message calls the `send_reply` function of BotHandlerApi
|
|
||||||
|
|
||||||
with self.mock_config_info(self.mock_config):
|
with self.mock_config_info(self.mock_config):
|
||||||
self.initialize_bot()
|
self.verify_reply(request, bot_response)
|
||||||
self.assert_bot_response(
|
|
||||||
message = {'content': 'help'},
|
|
||||||
response = {'content': bot_response},
|
|
||||||
expected_method='send_reply'
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in a new issue