diff options
| author | 2020-01-07 10:46:16 -0800 | |
|---|---|---|
| committer | 2020-02-12 10:07:52 -0800 | |
| commit | 1cef637f4d53ba1a093403f4e237e6004330cc1d (patch) | |
| tree | a7cf6a2a90d0d7e706deb1f8bef25392d4eeb327 /tests | |
| parent | Sync tests: rename channel fixtures (diff) | |
Sync tests: use channel fixtures with subtests
* Merge test_send_prompt_fetches_channel_if_cache_miss into
test_send_prompt_gets_channel_from_cache
* Rename test_send_prompt_gets_channel_from_cache
* Test test_send_prompt_sends_new_message_if_not_given with
fetch_channel too
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/bot/cogs/sync/test_base.py | 42 |
1 files changed, 17 insertions, 25 deletions
diff --git a/tests/bot/cogs/sync/test_base.py b/tests/bot/cogs/sync/test_base.py index 1d61f8cb2..d46965738 100644 --- a/tests/bot/cogs/sync/test_base.py +++ b/tests/bot/cogs/sync/test_base.py @@ -62,26 +62,19 @@ class SyncerBaseTests(unittest.TestCase): msg.edit.assert_called_once() self.assertIn("content", msg.edit.call_args[1]) - def test_send_prompt_gets_channel_from_cache(self): - """The dev-core channel should be retrieved from cache if an extant message isn't given.""" - mock_channel = helpers.MockTextChannel() - mock_channel.send.return_value = helpers.MockMessage() - self.bot.get_channel.return_value = mock_channel - - asyncio.run(self.syncer._send_prompt()) + def test_send_prompt_gets_dev_core_channel(self): + """The dev-core channel should be retrieved if an extant message isn't given.""" + subtests = ( + (self.bot.get_channel, self.mock_get_channel), + (self.bot.fetch_channel, self.mock_fetch_channel), + ) - self.bot.get_channel.assert_called_once_with(constants.Channels.devcore) + for method, mock_ in subtests: + with self.subTest(method=method, msg=mock_.__name__): + mock_() + asyncio.run(self.syncer._send_prompt()) - def test_send_prompt_fetches_channel_if_cache_miss(self): - """The dev-core channel should be fetched with an API call if it's not in the cache.""" - self.bot.get_channel.return_value = None - mock_channel = helpers.MockTextChannel() - mock_channel.send.return_value = helpers.MockMessage() - self.bot.fetch_channel.return_value = mock_channel - - asyncio.run(self.syncer._send_prompt()) - - self.bot.fetch_channel.assert_called_once_with(constants.Channels.devcore) + method.assert_called_once_with(constants.Channels.devcore) def test_send_prompt_returns_None_if_channel_fetch_fails(self): """None should be returned if there's an HTTPException when fetching the channel.""" @@ -94,14 +87,13 @@ class SyncerBaseTests(unittest.TestCase): def test_send_prompt_sends_new_message_if_not_given(self): """A new message that mentions core devs should be sent if an extant message isn't given.""" - mock_channel = helpers.MockTextChannel() - mock_channel.send.return_value = helpers.MockMessage() - self.bot.get_channel.return_value = mock_channel - - asyncio.run(self.syncer._send_prompt()) + for mock_ in (self.mock_get_channel, self.mock_fetch_channel): + with self.subTest(msg=mock_.__name__): + mock_channel, _ = mock_() + asyncio.run(self.syncer._send_prompt()) - mock_channel.send.assert_called_once() - self.assertIn(self.syncer._CORE_DEV_MENTION, mock_channel.send.call_args[0][0]) + mock_channel.send.assert_called_once() + self.assertIn(self.syncer._CORE_DEV_MENTION, mock_channel.send.call_args[0][0]) def test_send_prompt_adds_reactions(self): """The message should have reactions for confirmation added.""" |