Loading tests/cog/test_actions.py +23 −13 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ from cogdb.schema import (DiscordUser, FortSystem, FortDrop, FortUser, AdminPerm, RolePerm, ChannelPerm, Global, TrackSystem, TrackSystemCached, TrackByID) from tests.conftest import fake_msg_gears, fake_msg_newuser from tests.conftest import fake_msg_gears, fake_msg_newuser, Interaction import tests.conftest as tc from tests.cog.test_inara import INARA_TEST Loading @@ -46,6 +46,9 @@ def patch_scanners(): async def update_cells_(): return True def find_dupe_(_): return None, None mock_cls = aiomock.Mock() mock_cls.update_sheet_user_dict.return_value = [ {'range': 'A20:B20', 'values': [['test cry', 'test name']]}, Loading @@ -53,6 +56,7 @@ def patch_scanners(): scanner.__class__ = mock_cls scanner.send_batch = send_batch_ scanner.get_batch = get_batch_ scanner.find_dupe = find_dupe_ scanner.update_cells = update_cells_ cog.actions.SCANNERS = { 'hudson_carriers': scanner, Loading Loading @@ -1736,35 +1740,41 @@ async def test_cmd_vote_display(f_bot, f_admins, f_dusers, f_global_testbed, f_v @INARA_TEST @pytest.mark.asyncio async def test_cmd_whois_canceled(f_bot, f_asheet_kos, f_kos): emoji_no = "\u274C" async def test_cmd_whois_cancelled(f_bot, f_asheet_kos, f_kos): msg = fake_msg_gears("!whois Prozer") f_bot.wait_for.async_return_value = emoji_no, None f_bot.wait_for.async_side_effect = ( Interaction('cmd_who_friendly', message=msg, user=msg.author, comp_label=cog.inara.BUT_CANCEL), Interaction('cmd_who_friendly', message=msg, user=msg.author, comp_label=cog.inara.BUT_DENY), ) await action_map(msg, f_bot).execute() f_bot.send_message.assert_called_with(msg.channel, 'Command ignored.') assert "Should the CMDR Prozer be added as friendly or hostile?" in str(f_bot.send_message.call_args).replace("\\n", "\n") @INARA_TEST @pytest.mark.asyncio async def test_cmd_whois_friendly(f_bot, f_asheet_kos, f_kos): emoji_friendly = "\u1F7E2" f_bot.wait_for.async_return_value = emoji_friendly, None msg = fake_msg_gears("!whois Prozer") msg = fake_msg_gears('!whois Prozer') f_bot.wait_for.async_side_effect = ( Interaction('cmd_who_friendly', message=msg, user=msg.author, comp_label=cog.inara.BUT_FRIENDLY), Interaction('cmd_who_friendly', message=msg, user=msg.author, comp_label=cog.inara.BUT_DENY), ) await action_map(msg, f_bot).execute() f_bot.send_message.assert_called_with(msg.channel, 'CMDR has been reported to Leadership.') assert "Should the CMDR Prozer be added as friendly or hostile?" in str(f_bot.send_message.call_args).replace("\\n", "\n") @INARA_TEST @pytest.mark.asyncio async def test_cmd_whois_hostile(f_bot, f_asheet_kos, f_kos): emoji_hostile = "\u1F534" f_bot.wait_for.async_return_value = emoji_hostile, None async def test_cmd_whois_hostile(f_bot, f_asheet_kos, f_kos, patch_scanners): msg = fake_msg_gears("!whois Prozer") f_bot.wait_for.async_side_effect = ( Interaction('cmd_who_friendly', message=msg, user=msg.author, comp_label=cog.inara.BUT_FRIENDLY), Interaction('cmd_who_friendly', message=msg, user=msg.author, comp_label=cog.inara.BUT_APPROVE), ) await action_map(msg, f_bot).execute() f_bot.send_message.assert_called_with(msg.channel, 'CMDR has been reported to Leadership.') assert "Should the CMDR Prozer be added as friendly or hostile?" in str(f_bot.send_message.call_args).replace("\\n", "\n") def test_process_system_args(): Loading tests/cog/test_inara.py +13 −5 Original line number Diff line number Diff line Loading @@ -79,7 +79,11 @@ async def test_search_with_api(f_bot): @pytest.mark.asyncio async def test_reply_with_api_result(f_bot): api = cog.inara.InaraApi() f_bot.wait_for.async_return_value = (fake_msg_gears('stop'), None) msg = fake_msg_gears('stop') comp = aiomock.Mock() comp.label = cog.inara.BUT_CANCEL f_bot.wait_for.async_return_value = Interaction('reply_api', message=msg, user=msg.author, component=comp) f_bot.send_message.async_return_value = fake_msg_gears("A message to send.") cog.util.BOT = f_bot f_msg = fake_msg_gears('!whois gearsandcogs') Loading @@ -87,7 +91,7 @@ async def test_reply_with_api_result(f_bot): await api.reply_with_api_result(cmdr["req_id"], cmdr["event_data"], f_msg) # TODO: Very lazy check :/ assert "CMDR has been reported to Leadership." in str(f_bot.send_message.call_args) assert 'Should the CMDR GearsandCogs be added as friendly or hostile?' in str(f_bot.send_message.call_args) @pytest.mark.asyncio Loading Loading @@ -139,8 +143,11 @@ async def test_friendly_detector_hostile_with_squad(f_bot): @pytest.mark.asyncio async def test_select_from_multiple_exact(f_bot): api = cog.inara.InaraApi() # 7 is not guaranteed, based on external inara cmdr names order in results f_bot.wait_for.async_return_value = fake_msg_gears('cmdr 9') msg = fake_msg_gears('stop') f_bot.wait_for.async_side_effect = [ Interaction('reply_api', message=msg, user=msg.author, comp_label='GearsandCogs'), Interaction('reply_api', message=msg, user=msg.author, comp_label=cog.inara.BUT_DENY), ] cog.util.BOT = f_bot cmdr = await api.search_with_api('gears', fake_msg_gears('!whois gears')) assert cmdr["name"] == "GearsandCogs" Loading @@ -152,7 +159,8 @@ async def test_select_from_multiple_exact(f_bot): @pytest.mark.asyncio async def test_select_from_multiple_stop(f_bot): api = cog.inara.InaraApi() f_bot.wait_for.async_return_value = fake_msg_gears('stop') msg = fake_msg_gears(cog.inara.BUT_CANCEL) f_bot.wait_for.async_return_value = Interaction('multiple_stop', message=msg, user=msg.author, comp_label=cog.inara.BUT_CANCEL) cog.util.BOT = f_bot with pytest.raises(cog.exc.CmdAborted): await api.search_with_api('gears', fake_msg_gears('!whois gears')) Loading tests/cogdb/test_scanners.py +1 −1 Original line number Diff line number Diff line Loading @@ -366,7 +366,7 @@ async def test_kosscanner_find_dupe(f_asheet_kos): await fscan.update_cells() cnt, row = fscan.find_dupe('Silas Kruge') assert cnt == 1467 assert cnt == 1468 assert not fscan.find_dupe('NotThere')[0] Loading tests/conftest.py +17 −2 Original line number Diff line number Diff line Loading @@ -464,7 +464,7 @@ class Channel(FakeObject): msg.is_deleted = True self.all_delete_messages += messages async def send(self, embed): async def send(self, embed, **kwargs): return Message(embed, None, self.guild, None) Loading Loading @@ -526,10 +526,25 @@ class Message(FakeObject): class Interaction(FakeObject): def __init__(self, name, *, id=None, user=None, message=None): """ Fake interaction object for discord components. """ def __init__(self, name, *, id=None, user=None, message=None, component=None, values=None, comp_label=None): super().__init__(name, id) self.message = message self.user = user self.sent = [] if comp_label: component = aiomock.Mock() print('label', comp_label) component.label = comp_label self.component = component self.values = [component.label] if component and not values else values async def send(self, *args, **kwargs): self.sent += args def fake_servers(): Loading Loading
tests/cog/test_actions.py +23 −13 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ from cogdb.schema import (DiscordUser, FortSystem, FortDrop, FortUser, AdminPerm, RolePerm, ChannelPerm, Global, TrackSystem, TrackSystemCached, TrackByID) from tests.conftest import fake_msg_gears, fake_msg_newuser from tests.conftest import fake_msg_gears, fake_msg_newuser, Interaction import tests.conftest as tc from tests.cog.test_inara import INARA_TEST Loading @@ -46,6 +46,9 @@ def patch_scanners(): async def update_cells_(): return True def find_dupe_(_): return None, None mock_cls = aiomock.Mock() mock_cls.update_sheet_user_dict.return_value = [ {'range': 'A20:B20', 'values': [['test cry', 'test name']]}, Loading @@ -53,6 +56,7 @@ def patch_scanners(): scanner.__class__ = mock_cls scanner.send_batch = send_batch_ scanner.get_batch = get_batch_ scanner.find_dupe = find_dupe_ scanner.update_cells = update_cells_ cog.actions.SCANNERS = { 'hudson_carriers': scanner, Loading Loading @@ -1736,35 +1740,41 @@ async def test_cmd_vote_display(f_bot, f_admins, f_dusers, f_global_testbed, f_v @INARA_TEST @pytest.mark.asyncio async def test_cmd_whois_canceled(f_bot, f_asheet_kos, f_kos): emoji_no = "\u274C" async def test_cmd_whois_cancelled(f_bot, f_asheet_kos, f_kos): msg = fake_msg_gears("!whois Prozer") f_bot.wait_for.async_return_value = emoji_no, None f_bot.wait_for.async_side_effect = ( Interaction('cmd_who_friendly', message=msg, user=msg.author, comp_label=cog.inara.BUT_CANCEL), Interaction('cmd_who_friendly', message=msg, user=msg.author, comp_label=cog.inara.BUT_DENY), ) await action_map(msg, f_bot).execute() f_bot.send_message.assert_called_with(msg.channel, 'Command ignored.') assert "Should the CMDR Prozer be added as friendly or hostile?" in str(f_bot.send_message.call_args).replace("\\n", "\n") @INARA_TEST @pytest.mark.asyncio async def test_cmd_whois_friendly(f_bot, f_asheet_kos, f_kos): emoji_friendly = "\u1F7E2" f_bot.wait_for.async_return_value = emoji_friendly, None msg = fake_msg_gears("!whois Prozer") msg = fake_msg_gears('!whois Prozer') f_bot.wait_for.async_side_effect = ( Interaction('cmd_who_friendly', message=msg, user=msg.author, comp_label=cog.inara.BUT_FRIENDLY), Interaction('cmd_who_friendly', message=msg, user=msg.author, comp_label=cog.inara.BUT_DENY), ) await action_map(msg, f_bot).execute() f_bot.send_message.assert_called_with(msg.channel, 'CMDR has been reported to Leadership.') assert "Should the CMDR Prozer be added as friendly or hostile?" in str(f_bot.send_message.call_args).replace("\\n", "\n") @INARA_TEST @pytest.mark.asyncio async def test_cmd_whois_hostile(f_bot, f_asheet_kos, f_kos): emoji_hostile = "\u1F534" f_bot.wait_for.async_return_value = emoji_hostile, None async def test_cmd_whois_hostile(f_bot, f_asheet_kos, f_kos, patch_scanners): msg = fake_msg_gears("!whois Prozer") f_bot.wait_for.async_side_effect = ( Interaction('cmd_who_friendly', message=msg, user=msg.author, comp_label=cog.inara.BUT_FRIENDLY), Interaction('cmd_who_friendly', message=msg, user=msg.author, comp_label=cog.inara.BUT_APPROVE), ) await action_map(msg, f_bot).execute() f_bot.send_message.assert_called_with(msg.channel, 'CMDR has been reported to Leadership.') assert "Should the CMDR Prozer be added as friendly or hostile?" in str(f_bot.send_message.call_args).replace("\\n", "\n") def test_process_system_args(): Loading
tests/cog/test_inara.py +13 −5 Original line number Diff line number Diff line Loading @@ -79,7 +79,11 @@ async def test_search_with_api(f_bot): @pytest.mark.asyncio async def test_reply_with_api_result(f_bot): api = cog.inara.InaraApi() f_bot.wait_for.async_return_value = (fake_msg_gears('stop'), None) msg = fake_msg_gears('stop') comp = aiomock.Mock() comp.label = cog.inara.BUT_CANCEL f_bot.wait_for.async_return_value = Interaction('reply_api', message=msg, user=msg.author, component=comp) f_bot.send_message.async_return_value = fake_msg_gears("A message to send.") cog.util.BOT = f_bot f_msg = fake_msg_gears('!whois gearsandcogs') Loading @@ -87,7 +91,7 @@ async def test_reply_with_api_result(f_bot): await api.reply_with_api_result(cmdr["req_id"], cmdr["event_data"], f_msg) # TODO: Very lazy check :/ assert "CMDR has been reported to Leadership." in str(f_bot.send_message.call_args) assert 'Should the CMDR GearsandCogs be added as friendly or hostile?' in str(f_bot.send_message.call_args) @pytest.mark.asyncio Loading Loading @@ -139,8 +143,11 @@ async def test_friendly_detector_hostile_with_squad(f_bot): @pytest.mark.asyncio async def test_select_from_multiple_exact(f_bot): api = cog.inara.InaraApi() # 7 is not guaranteed, based on external inara cmdr names order in results f_bot.wait_for.async_return_value = fake_msg_gears('cmdr 9') msg = fake_msg_gears('stop') f_bot.wait_for.async_side_effect = [ Interaction('reply_api', message=msg, user=msg.author, comp_label='GearsandCogs'), Interaction('reply_api', message=msg, user=msg.author, comp_label=cog.inara.BUT_DENY), ] cog.util.BOT = f_bot cmdr = await api.search_with_api('gears', fake_msg_gears('!whois gears')) assert cmdr["name"] == "GearsandCogs" Loading @@ -152,7 +159,8 @@ async def test_select_from_multiple_exact(f_bot): @pytest.mark.asyncio async def test_select_from_multiple_stop(f_bot): api = cog.inara.InaraApi() f_bot.wait_for.async_return_value = fake_msg_gears('stop') msg = fake_msg_gears(cog.inara.BUT_CANCEL) f_bot.wait_for.async_return_value = Interaction('multiple_stop', message=msg, user=msg.author, comp_label=cog.inara.BUT_CANCEL) cog.util.BOT = f_bot with pytest.raises(cog.exc.CmdAborted): await api.search_with_api('gears', fake_msg_gears('!whois gears')) Loading
tests/cogdb/test_scanners.py +1 −1 Original line number Diff line number Diff line Loading @@ -366,7 +366,7 @@ async def test_kosscanner_find_dupe(f_asheet_kos): await fscan.update_cells() cnt, row = fscan.find_dupe('Silas Kruge') assert cnt == 1467 assert cnt == 1468 assert not fscan.find_dupe('NotThere')[0] Loading
tests/conftest.py +17 −2 Original line number Diff line number Diff line Loading @@ -464,7 +464,7 @@ class Channel(FakeObject): msg.is_deleted = True self.all_delete_messages += messages async def send(self, embed): async def send(self, embed, **kwargs): return Message(embed, None, self.guild, None) Loading Loading @@ -526,10 +526,25 @@ class Message(FakeObject): class Interaction(FakeObject): def __init__(self, name, *, id=None, user=None, message=None): """ Fake interaction object for discord components. """ def __init__(self, name, *, id=None, user=None, message=None, component=None, values=None, comp_label=None): super().__init__(name, id) self.message = message self.user = user self.sent = [] if comp_label: component = aiomock.Mock() print('label', comp_label) component.label = comp_label self.component = component self.values = [component.label] if component and not values else values async def send(self, *args, **kwargs): self.sent += args def fake_servers(): Loading