python-zulip-api/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py
neiljp (Neil Pilgrim) 0ea49c96ed bot tests: import patch in incrementor & monkeytestit as in other tests.
This makes the code more compact and consistent.
2018-06-11 08:16:43 -04:00

48 lines
1.8 KiB
Python

from unittest.mock import patch
from unittest import skipIf
from sys import version_info
from importlib import import_module
from zulip_bots.test_lib import BotTestCase, DefaultTests
@skipIf(version_info[:2] < (3, 5), "monkeytestit requires python3.5+")
class TestMonkeyTestitBot(BotTestCase, DefaultTests):
bot_name = "monkeytestit"
def setUp(self):
self.monkeytestit_class = import_module(
"zulip_bots.bots.monkeytestit.monkeytestit").MonkeyTestitBot
def test_bot_responds_to_empty_message(self):
message = dict(
content='',
type='stream',
)
with patch.object(self.monkeytestit_class, 'initialize', return_value=None):
with self.mock_config_info({'api_key': "magic"}):
res = self.get_response(message)
self.assertTrue("Unknown command" in res['content'])
def test_website_fail(self):
message = dict(
content='check https://website.com',
type='stream',
)
with patch.object(self.monkeytestit_class, 'initialize', return_value=None):
with self.mock_config_info({'api_key': "magic"}):
with self.mock_http_conversation('website_result_fail'):
res = self.get_response(message)
self.assertTrue("Status: tests_failed" in res['content'])
def test_website_success(self):
message = dict(
content='check https://website.com',
type='stream',
)
with patch.object(self.monkeytestit_class, 'initialize', return_value=None):
with self.mock_config_info({'api_key': "magic"}):
with self.mock_http_conversation('website_result_success'):
res = self.get_response(message)
self.assertTrue("success" in res['content'])