Loading tests/cog/test_actions.py +6 −6 Original line number Diff line number Diff line Loading @@ -1865,8 +1865,8 @@ async def test_cmd_vote_display(f_bot, f_admins, f_dusers, f_global_testbed, f_v async def test_cmd_whois_cancelled(f_bot, f_asheet_kos, f_kos): 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_CANCEL), Interaction('cmd_who_friendly', message=msg, user=msg.author, comp_label=cog.inara.BUT_DENY), Interaction('cmd_who_cancelled', message=msg, user=msg.author, button=cog.inara.BUT_CANCEL), Interaction('cmd_who_deny', message=msg, user=msg.author, button=cog.inara.BUT_DENY), ) await action_map(msg, f_bot).execute() Loading @@ -1878,8 +1878,8 @@ async def test_cmd_whois_cancelled(f_bot, f_asheet_kos, f_kos): async def test_cmd_whois_friendly(f_bot, f_asheet_kos, f_kos): 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), Interaction('cmd_who_friendly', message=msg, user=msg.author, button=cog.inara.BUT_FRIENDLY), Interaction('cmd_who_deny', message=msg, user=msg.author, button=cog.inara.BUT_DENY), ) await action_map(msg, f_bot).execute() Loading @@ -1891,8 +1891,8 @@ async def test_cmd_whois_friendly(f_bot, f_asheet_kos, f_kos): 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), Interaction('cmd_who_hostile', message=msg, user=msg.author, button=cog.inara.BUT_HOSTILE), Interaction('cmd_who_approve', message=msg, user=msg.author, button=cog.inara.BUT_APPROVE), ) await action_map(msg, f_bot).execute() Loading tests/cog/test_inara.py +14 −21 Original line number Diff line number Diff line Loading @@ -23,18 +23,6 @@ REASON_INARA = 'Prevent temp inara ban due flooding. To enable, ensure os.enviro INARA_TEST = pytest.mark.skipif(not os.environ.get('ALL_TESTS'), reason=REASON_INARA) def mock_inter(values): inter = aiomock.AIOMock(values=values, sent=[]) inter.component.label = inter.values[0] inter.sent = [] async def send_(resp): inter.sent += [resp] inter.send = send_ return inter def test_inara_api_input(): api_input = cog.inara.InaraApiInput() api_input.add_event("fakeEvent", {"fakeKey": "fakeData"}) Loading Loading @@ -119,9 +107,11 @@ async def test_inara_api_key_unset(f_bot): async def test_search_inara_and_kos_match_exact(f_bot): api = cog.inara.InaraApi() cog.util.BOT = f_bot f_bot.wait_for.async_side_effect = [mock_inter([cog.inara.BUT_CANCEL])] msg = fake_msg_gears('!whois gearsandcogs') f_bot.wait_for.async_side_effect = [ Interaction('kos_cancel', message=msg, user=msg.author, button=cog.inara.BUT_CANCEL), ] result = await api.search_inara_and_kos('gearsandcogs', msg) expect = { Loading @@ -139,9 +129,12 @@ async def test_search_inara_and_kos_match_exact(f_bot): async def test_search_inara_and_kos_match_select(f_bot): api = cog.inara.InaraApi() cog.util.BOT = f_bot f_bot.wait_for.async_side_effect = [mock_inter(['Gearsprud']), mock_inter([cog.inara.BUT_FRIENDLY])] msg = fake_msg_gears('!whois gearsandcogs') f_bot.wait_for.async_side_effect = [ Interaction('kos_select', message=msg, user=msg.author, select='Gearsprud'), Interaction('kos_friendly', message=msg, user=msg.author, button=cog.inara.BUT_FRIENDLY), ] result = await api.search_inara_and_kos('gears', msg) expect = { Loading @@ -159,9 +152,11 @@ async def test_search_inara_and_kos_match_select(f_bot): async def test_search_inara_and_kos_no_match(f_bot): api = cog.inara.InaraApi() cog.util.BOT = f_bot f_bot.wait_for.async_side_effect = [mock_inter([cog.inara.BUT_HOSTILE])] msg = fake_msg_gears('!whois gearsandcogs') f_bot.wait_for.async_side_effect = [ Interaction('kos_hostile', message=msg, user=msg.author, button=cog.inara.BUT_HOSTILE), ] result = await api.search_inara_and_kos('notInInaraForSure', msg) expect = { Loading Loading @@ -192,9 +187,7 @@ async def test_search_with_api(f_bot): async def test_reply_with_api_result(f_bot): api = cog.inara.InaraApi() 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.wait_for.async_return_value = Interaction('reply_api', message=msg, user=msg.author, button=cog.inara.BUT_CANCEL) f_bot.send_message.async_return_value = fake_msg_gears("A message to send.") cog.util.BOT = f_bot Loading @@ -212,8 +205,8 @@ async def test_select_from_multiple_exact(f_bot): api = cog.inara.InaraApi() 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), Interaction('reply_api', message=msg, user=msg.author, select='GearsandCogs'), Interaction('reply_api', message=msg, user=msg.author, select=cog.inara.BUT_DENY), ] cog.util.BOT = f_bot cmdr = await api.search_with_api('gears', fake_msg_gears('!whois gears')) Loading @@ -227,7 +220,7 @@ async def test_select_from_multiple_exact(f_bot): async def test_select_from_multiple_stop(f_bot): api = cog.inara.InaraApi() 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) f_bot.wait_for.async_return_value = Interaction('multiple_stop', message=msg, user=msg.author, select=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/conftest.py +14 −5 Original line number Diff line number Diff line Loading @@ -544,22 +544,31 @@ class Interaction(FakeObject): """ Fake interaction object for discord components. """ def __init__(self, name, *, id=None, user=None, message=None, component=None, values=None, comp_label=None): def __init__(self, name, *, id=None, user=None, message=None, component=None, button=None, select=None): super().__init__(name, id) self.message = message self.user = user self.sent = [] if comp_label: if button or select: component = aiomock.Mock() component.label = comp_label component.label = button if button else select self.component = component self.values = [component.label] if component and not values else values if button: self.data = {'custom_id': button} if select: self.data = {'values': [select]} self.response = aiomock.Mock() self.response.send_message = self.send async def send(self, *args, **kwargs): self.sent += args async def send_message(self, *args, **kwargs): self.sent += args def fake_servers(): """ Generate fake discord servers for testing. """ Loading Loading
tests/cog/test_actions.py +6 −6 Original line number Diff line number Diff line Loading @@ -1865,8 +1865,8 @@ async def test_cmd_vote_display(f_bot, f_admins, f_dusers, f_global_testbed, f_v async def test_cmd_whois_cancelled(f_bot, f_asheet_kos, f_kos): 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_CANCEL), Interaction('cmd_who_friendly', message=msg, user=msg.author, comp_label=cog.inara.BUT_DENY), Interaction('cmd_who_cancelled', message=msg, user=msg.author, button=cog.inara.BUT_CANCEL), Interaction('cmd_who_deny', message=msg, user=msg.author, button=cog.inara.BUT_DENY), ) await action_map(msg, f_bot).execute() Loading @@ -1878,8 +1878,8 @@ async def test_cmd_whois_cancelled(f_bot, f_asheet_kos, f_kos): async def test_cmd_whois_friendly(f_bot, f_asheet_kos, f_kos): 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), Interaction('cmd_who_friendly', message=msg, user=msg.author, button=cog.inara.BUT_FRIENDLY), Interaction('cmd_who_deny', message=msg, user=msg.author, button=cog.inara.BUT_DENY), ) await action_map(msg, f_bot).execute() Loading @@ -1891,8 +1891,8 @@ async def test_cmd_whois_friendly(f_bot, f_asheet_kos, f_kos): 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), Interaction('cmd_who_hostile', message=msg, user=msg.author, button=cog.inara.BUT_HOSTILE), Interaction('cmd_who_approve', message=msg, user=msg.author, button=cog.inara.BUT_APPROVE), ) await action_map(msg, f_bot).execute() Loading
tests/cog/test_inara.py +14 −21 Original line number Diff line number Diff line Loading @@ -23,18 +23,6 @@ REASON_INARA = 'Prevent temp inara ban due flooding. To enable, ensure os.enviro INARA_TEST = pytest.mark.skipif(not os.environ.get('ALL_TESTS'), reason=REASON_INARA) def mock_inter(values): inter = aiomock.AIOMock(values=values, sent=[]) inter.component.label = inter.values[0] inter.sent = [] async def send_(resp): inter.sent += [resp] inter.send = send_ return inter def test_inara_api_input(): api_input = cog.inara.InaraApiInput() api_input.add_event("fakeEvent", {"fakeKey": "fakeData"}) Loading Loading @@ -119,9 +107,11 @@ async def test_inara_api_key_unset(f_bot): async def test_search_inara_and_kos_match_exact(f_bot): api = cog.inara.InaraApi() cog.util.BOT = f_bot f_bot.wait_for.async_side_effect = [mock_inter([cog.inara.BUT_CANCEL])] msg = fake_msg_gears('!whois gearsandcogs') f_bot.wait_for.async_side_effect = [ Interaction('kos_cancel', message=msg, user=msg.author, button=cog.inara.BUT_CANCEL), ] result = await api.search_inara_and_kos('gearsandcogs', msg) expect = { Loading @@ -139,9 +129,12 @@ async def test_search_inara_and_kos_match_exact(f_bot): async def test_search_inara_and_kos_match_select(f_bot): api = cog.inara.InaraApi() cog.util.BOT = f_bot f_bot.wait_for.async_side_effect = [mock_inter(['Gearsprud']), mock_inter([cog.inara.BUT_FRIENDLY])] msg = fake_msg_gears('!whois gearsandcogs') f_bot.wait_for.async_side_effect = [ Interaction('kos_select', message=msg, user=msg.author, select='Gearsprud'), Interaction('kos_friendly', message=msg, user=msg.author, button=cog.inara.BUT_FRIENDLY), ] result = await api.search_inara_and_kos('gears', msg) expect = { Loading @@ -159,9 +152,11 @@ async def test_search_inara_and_kos_match_select(f_bot): async def test_search_inara_and_kos_no_match(f_bot): api = cog.inara.InaraApi() cog.util.BOT = f_bot f_bot.wait_for.async_side_effect = [mock_inter([cog.inara.BUT_HOSTILE])] msg = fake_msg_gears('!whois gearsandcogs') f_bot.wait_for.async_side_effect = [ Interaction('kos_hostile', message=msg, user=msg.author, button=cog.inara.BUT_HOSTILE), ] result = await api.search_inara_and_kos('notInInaraForSure', msg) expect = { Loading Loading @@ -192,9 +187,7 @@ async def test_search_with_api(f_bot): async def test_reply_with_api_result(f_bot): api = cog.inara.InaraApi() 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.wait_for.async_return_value = Interaction('reply_api', message=msg, user=msg.author, button=cog.inara.BUT_CANCEL) f_bot.send_message.async_return_value = fake_msg_gears("A message to send.") cog.util.BOT = f_bot Loading @@ -212,8 +205,8 @@ async def test_select_from_multiple_exact(f_bot): api = cog.inara.InaraApi() 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), Interaction('reply_api', message=msg, user=msg.author, select='GearsandCogs'), Interaction('reply_api', message=msg, user=msg.author, select=cog.inara.BUT_DENY), ] cog.util.BOT = f_bot cmdr = await api.search_with_api('gears', fake_msg_gears('!whois gears')) Loading @@ -227,7 +220,7 @@ async def test_select_from_multiple_exact(f_bot): async def test_select_from_multiple_stop(f_bot): api = cog.inara.InaraApi() 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) f_bot.wait_for.async_return_value = Interaction('multiple_stop', message=msg, user=msg.author, select=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/conftest.py +14 −5 Original line number Diff line number Diff line Loading @@ -544,22 +544,31 @@ class Interaction(FakeObject): """ Fake interaction object for discord components. """ def __init__(self, name, *, id=None, user=None, message=None, component=None, values=None, comp_label=None): def __init__(self, name, *, id=None, user=None, message=None, component=None, button=None, select=None): super().__init__(name, id) self.message = message self.user = user self.sent = [] if comp_label: if button or select: component = aiomock.Mock() component.label = comp_label component.label = button if button else select self.component = component self.values = [component.label] if component and not values else values if button: self.data = {'custom_id': button} if select: self.data = {'values': [select]} self.response = aiomock.Mock() self.response.send_message = self.send async def send(self, *args, **kwargs): self.sent += args async def send_message(self, *args, **kwargs): self.sent += args def fake_servers(): """ Generate fake discord servers for testing. """ Loading