diff options
author | 2020-01-29 18:47:58 -0800 | |
---|---|---|
committer | 2020-02-12 10:07:55 -0800 | |
commit | 607e4480badd58d5de36d5be3306498afcb4348c (patch) | |
tree | b5765b8f0b176bd74e1923c516b3477cda4a12a9 /tests | |
parent | Sync tests: fix Syncer mocks not having async methods (diff) |
Sync tests: test sync_guild
Roles and users should be synced only if a guild is successfully
retrieved.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bot/cogs/sync/test_cog.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/bot/cogs/sync/test_cog.py b/tests/bot/cogs/sync/test_cog.py index ec66c795d..09ce0ae16 100644 --- a/tests/bot/cogs/sync/test_cog.py +++ b/tests/bot/cogs/sync/test_cog.py @@ -1,6 +1,8 @@ +import asyncio import unittest from unittest import mock +from bot import constants from bot.cogs import sync from bot.cogs.sync.syncers import Syncer from tests import helpers @@ -71,3 +73,25 @@ class SyncCogTests(unittest.TestCase): self.UserSyncer.assert_called_once_with(self.bot) sync_guild.assert_called_once_with() self.bot.loop.create_task.assert_called_once_with(mock_sync_guild_coro) + + def test_sync_cog_sync_guild(self): + """Roles and users should be synced only if a guild is successfully retrieved.""" + for guild in (helpers.MockGuild(), None): + with self.subTest(guild=guild): + self.bot.reset_mock() + self.cog.role_syncer.reset_mock() + self.cog.user_syncer.reset_mock() + + self.bot.get_guild = mock.MagicMock(return_value=guild) + + asyncio.run(self.cog.sync_guild()) + + self.bot.wait_until_guild_available.assert_called_once() + self.bot.get_guild.assert_called_once_with(constants.Guild.id) + + if guild is None: + self.cog.role_syncer.sync.assert_not_called() + self.cog.user_syncer.sync.assert_not_called() + else: + self.cog.role_syncer.sync.assert_called_once_with(guild) + self.cog.user_syncer.sync.assert_called_once_with(guild) |