XKCD: Split single test into multiple tests.
MODIFY
zulip_bots/zulip_bots/bots/xkcd/test_xkcd.py
zulip_bots/zulip_bots/bots/xkcd/test_xkcd.py
@@ -10,18 +10,7 @@ from zulip_bots.test_lib import BotTestCase
class TestXkcdBot(BotTestCase):
bot_name = "xkcd"
- @mock.patch('logging.exception')
- def test_bot(self, mock_logging_exception):
- help_txt = "xkcd bot supports these commands:"
- err_txt = "xkcd bot only supports these commands, not `{}`:"
- commands = '''
-* `@xkcd help` to show this help message.
-* `@xkcd latest` to fetch the latest comic strip from xkcd.
-* `@xkcd random` to fetch a random comic strip from xkcd.
-* `@xkcd <comic id>` to fetch a comic strip based on `<comic id>` e.g `@xkcd 1234`.'''
- invalid_id_txt = "Sorry, there is likely no xkcd comic strip with id: #"
-
- # 'latest' query
+ def test_latest_command(self):
bot_response = ("#1866: **Russell's Teapot**\n"
"[Unfortunately, NASA regulations state that Bertrand Russell-related "
"payloads can only be launched within launch vehicles which do not launch "
@@ -33,7 +22,7 @@ class TestXkcdBot(BotTestCase):
expected_method='send_reply'
)
- # 'random' query
+ def test_random_command(self):
bot_response = ("#1800: **Chess Notation**\n"
"[I've decided to score all my conversations using chess win-loss "
"notation. (??)](https://imgs.xkcd.com/comics/chess_notation.png)")
@@ -50,7 +39,7 @@ class TestXkcdBot(BotTestCase):
expected_method='send_reply'
)
- # specific comic ID query
+ def test_numeric_comic_id_command(self):
bot_response = ("#1: **Barrel - Part 1**\n[Don't we all.]"
"(https://imgs.xkcd.com/comics/barrel_cropped_(1).jpg)")
with self.mock_http_conversation('test_specific_id'):
@@ -60,7 +49,10 @@ class TestXkcdBot(BotTestCase):
expected_method='send_reply'
)
- # Comic ID doesn't exist.
+ @mock.patch('logging.exception')
+ def test_invalid_comic_ids(self, mock_logging_exception):
+ invalid_id_txt = "Sorry, there is likely no xkcd comic strip with id: #"
+
bot_response = invalid_id_txt + "999999999"
with self.mock_http_conversation('test_not_existing_id'):
self.assert_bot_response(
@@ -77,6 +69,14 @@ class TestXkcdBot(BotTestCase):
expected_method='send_reply'
)
+ def test_help_responses(self):
+ help_txt = "xkcd bot supports these commands:"
+ err_txt = "xkcd bot only supports these commands, not `{}`:"
+ commands = '''
+* `@xkcd help` to show this help message.
+* `@xkcd latest` to fetch the latest comic strip from xkcd.
+* `@xkcd random` to fetch a random comic strip from xkcd.
+* `@xkcd <comic id>` to fetch a comic strip based on `<comic id>` e.g `@xkcd 1234`.'''
# Empty query, no request made to the Internet.
bot_response = err_txt.format('')+commands
self.assert_bot_response(

XKCD: Split single test into multiple tests.