예제 #1
0
 async def test_not_found(self, dpy_guild: discord.Guild):
     category = MagicMock(spec=discord.CategoryChannel)
     client = mock_client()
     await safe_create_voice_channel(client,
                                     dpy_guild.id,
                                     "name",
                                     category=category)
     dpy_guild.create_voice_channel.assert_not_called()
예제 #2
0
 async def test_happy_path(self, dpy_guild: discord.Guild):
     category = MagicMock(spec=discord.CategoryChannel)
     client = mock_client(guilds=[dpy_guild])
     await safe_create_voice_channel(client,
                                     dpy_guild.id,
                                     "name",
                                     category=category)
     dpy_guild.create_voice_channel.assert_called_once_with(
         "name", category=category)
예제 #3
0
 async def test_uncached(
     self,
     dpy_channel: discord.TextChannel,
     monkeypatch: pytest.MonkeyPatch,
 ):
     client = mock_client(channels=[dpy_channel])
     monkeypatch.setattr(client, "get_channel",
                         MagicMock(return_value=None))
     assert await safe_fetch_text_channel(client, ANY,
                                          dpy_channel.id) is dpy_channel
예제 #4
0
 async def test_create_failure(self):
     guild = MagicMock(spec=discord.Guild)
     guild.id = 101
     guild.categories = []
     guild.create_category_channel = AsyncMock(
         side_effect=DiscordException())
     client = mock_client(guilds=[guild])
     result = await safe_ensure_voice_category(client, guild.id,
                                               "voice-channels")
     assert result is None
     guild.create_category_channel.assert_called_once_with("voice-channels")
예제 #5
0
 async def test_uncached(self, dpy_guild: discord.Guild,
                         monkeypatch: pytest.MonkeyPatch):
     category = MagicMock(spec=discord.CategoryChannel)
     client = mock_client(guilds=[dpy_guild])
     monkeypatch.setattr(client, "get_guild", MagicMock(return_value=None))
     await safe_create_voice_channel(client,
                                     dpy_guild.id,
                                     "name",
                                     category=category)
     dpy_guild.create_voice_channel.assert_called_once_with(
         "name", category=category)
예제 #6
0
 async def test_none_exists(self):
     new_category = MagicMock(spec=discord.CategoryChannel)
     guild = MagicMock(spec=discord.Guild)
     guild.id = 101
     guild.categories = []
     guild.create_category_channel = AsyncMock(return_value=new_category)
     client = mock_client(guilds=[guild])
     result = await safe_ensure_voice_category(client, guild.id,
                                               "voice-channels")
     assert result is new_category
     guild.create_category_channel.assert_called_once_with("voice-channels")
예제 #7
0
 async def test_available_exists(self):
     channel = MagicMock(spec=discord.VoiceChannel)
     category = MagicMock(spec=discord.CategoryChannel)
     category.name = "voice-channels"
     category.channels = [channel]
     guild = MagicMock(spec=discord.Guild)
     guild.id = 101
     guild.categories = [category]
     guild.create_category_channel = AsyncMock()
     client = mock_client(guilds=[guild], categories=[category])
     result = await safe_ensure_voice_category(client, guild.id,
                                               "voice-channels")
     assert result is category
     guild.create_category_channel.assert_not_called()
예제 #8
0
 async def test_available_has_bad_name(self):
     new_category = MagicMock(spec=discord.CategoryChannel)
     new_category.name = "voice-channels"
     channel = MagicMock(spec=discord.VoiceChannel)
     category = MagicMock(spec=discord.CategoryChannel)
     category.name = "voice-channels xyz"
     category.channels = [channel]
     guild = MagicMock(spec=discord.Guild)
     guild.id = 101
     guild.categories = [category]
     guild.create_category_channel = AsyncMock(return_value=new_category)
     client = mock_client(guilds=[guild], categories=[category])
     result = await safe_ensure_voice_category(client, guild.id,
                                               "voice-channels")
     assert result is new_category
     guild.create_category_channel.assert_called_once_with("voice-channels")
예제 #9
0
 async def test_missing_numbered_category(self):
     new_category = MagicMock(spec=discord.CategoryChannel)
     new_category.name = "voice-channels 2"
     channel1 = MagicMock(spec=discord.VoiceChannel)
     category1 = MagicMock(spec=discord.CategoryChannel)
     category1.name = "voice-channels 1"
     category1.channels = [channel1] * 50
     channel3 = MagicMock(spec=discord.VoiceChannel)
     category3 = MagicMock(spec=discord.CategoryChannel)
     category3.name = "voice-channels 3"
     category3.channels = [channel3]
     guild = MagicMock(spec=discord.Guild)
     guild.id = 101
     guild.categories = [category1, category3]
     guild.create_category_channel = AsyncMock(return_value=new_category)
     client = mock_client(guilds=[guild], categories=[category1, category3])
     result = await safe_ensure_voice_category(client, guild.id,
                                               "voice-channels")
     assert result is new_category
     guild.create_category_channel.assert_called_once_with(
         "voice-channels 2")
예제 #10
0
 async def test_uncached(self, dpy_guild: discord.Guild,
                         monkeypatch: pytest.MonkeyPatch):
     client = mock_client(guilds=[dpy_guild])
     monkeypatch.setattr(client, "get_guild", MagicMock(return_value=None))
     assert await safe_fetch_guild(client, dpy_guild.id) is dpy_guild
예제 #11
0
 async def test_no_guild(self):
     client = mock_client()
     result = await safe_ensure_voice_category(client, 404,
                                               "voice-channels")
     assert result is None
예제 #12
0
 async def test_cached(self, dpy_channel: discord.TextChannel):
     client = mock_client(channels=[dpy_channel])
     assert await safe_fetch_text_channel(client, ANY,
                                          dpy_channel.id) is dpy_channel
예제 #13
0
 async def test_cached(self, dpy_author: discord.User):
     client = mock_client(users=[dpy_author])
     assert await safe_fetch_user(client, dpy_author.id) is dpy_author
예제 #14
0
 async def test_uncached(self, dpy_author: discord.User,
                         monkeypatch: pytest.MonkeyPatch):
     client = mock_client(users=[dpy_author])
     monkeypatch.setattr(client, "get_user", MagicMock(return_value=None))
     assert await safe_fetch_user(client, dpy_author.id) is dpy_author
예제 #15
0
 async def test_not_found(self, dpy_guild: discord.Guild):
     client = mock_client()
     await safe_create_category_channel(client, dpy_guild.id, "name")
     dpy_guild.create_category_channel.assert_not_called()
예제 #16
0
 async def test_non_text(self):
     channel = MagicMock(spec=discord.DMChannel)
     client = mock_client(channels=[channel])
     assert await safe_fetch_text_channel(client, ANY, channel.id) is None
예제 #17
0
 async def test_cached(self, dpy_guild: discord.Guild):
     client = mock_client(guilds=[dpy_guild])
     assert await safe_fetch_guild(client, dpy_guild.id) is dpy_guild
예제 #18
0
 async def test_uncached_non_text(self, monkeypatch: pytest.MonkeyPatch):
     channel = MagicMock(spec=discord.DMChannel)
     client = mock_client(channels=[channel])
     monkeypatch.setattr(client, "get_channel",
                         MagicMock(return_value=None))
     assert await safe_fetch_text_channel(client, ANY, channel.id) is None
예제 #19
0
 async def test_happy_path(self, dpy_guild: discord.Guild):
     client = mock_client(guilds=[dpy_guild])
     await safe_create_category_channel(client, dpy_guild.id, "name")
     dpy_guild.create_category_channel.assert_called_once_with("name")