diff --git a/kdb-bot/test/ui_tests/config/appsettings.json b/kdb-bot/test/ui_tests/config/appsettings.json index 13e1fd89..0a7afabb 100644 --- a/kdb-bot/test/ui_tests/config/appsettings.json +++ b/kdb-bot/test/ui_tests/config/appsettings.json @@ -20,6 +20,8 @@ "TestSettings": { "LoginUrl": "https://discord.com/login", "MePageUrl": "https://discord.com/channels/@me", - "CmdURL": "https://discord.com/channels/910199451145076828/911578636899987526" + "CmdURL": "https://discord.com/channels/910199451145076828/911578636899987526", + "GuildId": 910199451145076828, + "BotId": 998159802393964594 } } \ No newline at end of file diff --git a/kdb-bot/test/ui_tests_shared/configuration/test_settings.py b/kdb-bot/test/ui_tests_shared/configuration/test_settings.py index 71cfac9a..fc7fa439 100644 --- a/kdb-bot/test/ui_tests_shared/configuration/test_settings.py +++ b/kdb-bot/test/ui_tests_shared/configuration/test_settings.py @@ -12,6 +12,8 @@ class TestSettings(ConfigurationModelABC): self._login_url = '' self._me_page_url = '' self._cmd_url = '' + self._guild_id = 0 + self._bot_id = 0 @property def login_url(self) -> str: @@ -25,11 +27,21 @@ class TestSettings(ConfigurationModelABC): def cmd_url(self) -> str: return self._cmd_url + @property + def guild_id(self) -> int: + return self._guild_id + + @property + def bot_id(self) -> int: + return self._bot_id + def from_dict(self, settings: dict): try: self._login_url = settings['LoginUrl'] self._me_page_url = settings['MePageUrl'] self._cmd_url = settings['CmdURL'] + self._guild_id = settings['GuildId'] + self._bot_id = settings['BotId'] except Exception as e: Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings') Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}') diff --git a/kdb-bot/test/ui_tests_tests/cases/__init__.py b/kdb-bot/test/ui_tests_tests/commands/__init__.py similarity index 100% rename from kdb-bot/test/ui_tests_tests/cases/__init__.py rename to kdb-bot/test/ui_tests_tests/commands/__init__.py diff --git a/kdb-bot/test/ui_tests_tests/commands/common/__init__.py b/kdb-bot/test/ui_tests_tests/commands/common/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/kdb-bot/test/ui_tests_tests/cases/help_test_case.py b/kdb-bot/test/ui_tests_tests/commands/common/help_command_test_case.py similarity index 87% rename from kdb-bot/test/ui_tests_tests/cases/help_test_case.py rename to kdb-bot/test/ui_tests_tests/commands/common/help_command_test_case.py index 9a6f302b..e6f7b6b4 100644 --- a/kdb-bot/test/ui_tests_tests/cases/help_test_case.py +++ b/kdb-bot/test/ui_tests_tests/commands/common/help_command_test_case.py @@ -4,7 +4,7 @@ from ui_tests_shared.command_test_case_with_app import CommandTestCaseWithApp from ui_tests_shared.decorators import Async -class HelpTestCase(CommandTestCaseWithApp): +class HelpCommandTestCase(CommandTestCaseWithApp): @Async.test async def test_help(self): @@ -12,7 +12,7 @@ class HelpTestCase(CommandTestCaseWithApp): self.send_command('help') def check(m: discord.Message): - return m.content == correct_response and m.author.id == 998159802393964594 + return m.content == correct_response and m.author.id == self._test_settings.bot_id response = await self._bot.wait_for('message', check=check) self.assertEqual(response.content, correct_response) diff --git a/kdb-bot/test/ui_tests_tests/commands/common/info_command_test_case.py b/kdb-bot/test/ui_tests_tests/commands/common/info_command_test_case.py new file mode 100644 index 00000000..08499404 --- /dev/null +++ b/kdb-bot/test/ui_tests_tests/commands/common/info_command_test_case.py @@ -0,0 +1,48 @@ +from datetime import datetime +import discord + +import bot +from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC +from ui_tests_shared.command_test_case_with_app import CommandTestCaseWithApp +from ui_tests_shared.decorators import Async + + +class HelpCommandTestCase(CommandTestCaseWithApp): + + def get_embed(self) -> discord.Embed: + client_utils: ClientUtilsServiceABC = self._services.get_service(ClientUtilsServiceABC) + client = client_utils.get_client(self._bot.user.id, self._test_settings.guild_id) + embed = discord.Embed( + title=self._t.transform('modules.base.info.title'), + description=self._t.transform('modules.base.info.description'), + color=int('ef9d0d', 16) + ) + + embed.add_field(name=self._t.transform('modules.base.info.fields.version'), value=bot.__version__) + start_time = self._config.get_configuration('Bot_StartTime') + ontime = round((datetime.now() - datetime.strptime(start_time, '%Y-%m-%d %H:%M:%S.%f')).total_seconds() / 3600, 2) + embed.add_field(name=self._t.transform('modules.base.info.fields.ontime'), value=f'{ontime}h') + embed.add_field(name=self._t.transform('modules.base.info.fields.sent_message_count'), value=client.sent_message_count, inline=False) + embed.add_field(name=self._t.transform('modules.base.info.fields.received_message_count'), value=client.received_message_count) + embed.add_field(name=self._t.transform('modules.base.info.fields.deleted_message_count'), value=client.deleted_message_count, inline=False) + embed.add_field(name=self._t.transform('modules.base.info.fields.received_command_count'), value=client.received_command_count) + embed.add_field(name=self._t.transform('modules.base.info.fields.moved_users_count'), value=client.moved_users_count) + from bot.module_list import ModuleList + modules = ModuleList.get_modules() + modules = modules.select(lambda x: x.__name__.replace('Module', '')) + embed.add_field(name=self._t.transform('modules.base.info.fields.modules'), value='\n'.join(modules), inline=False) + return embed + + @Async.test + async def test_info(self): + correct_response = self.get_embed() + self.send_command('info') + + def check(m: discord.Message): + return m.content == correct_response and m.author.id == self._test_settings.bot_id + + response: discord.Message = await self._bot.wait_for('message', check=check) + self.assertEqual(len(response.embeds), 1) + + self.assertEqual(response.embeds[0], correct_response) + await self._bot.close() diff --git a/kdb-bot/test/ui_tests_tests/cases/ping_test_case.py b/kdb-bot/test/ui_tests_tests/commands/common/ping_command_test_case.py similarity index 87% rename from kdb-bot/test/ui_tests_tests/cases/ping_test_case.py rename to kdb-bot/test/ui_tests_tests/commands/common/ping_command_test_case.py index 72575253..05dae8a4 100644 --- a/kdb-bot/test/ui_tests_tests/cases/ping_test_case.py +++ b/kdb-bot/test/ui_tests_tests/commands/common/ping_command_test_case.py @@ -4,7 +4,7 @@ from ui_tests_shared.command_test_case_with_app import CommandTestCaseWithApp from ui_tests_shared.decorators import Async -class PingTestCase(CommandTestCaseWithApp): +class PingCommandTestCase(CommandTestCaseWithApp): @Async.test async def test_ping(self): @@ -13,7 +13,7 @@ class PingTestCase(CommandTestCaseWithApp): self.send_command('ping') def check(m: discord.Message): - return m.content == correct_response and m.author.id == 998159802393964594 + return m.content == correct_response and m.author.id == self._test_settings.bot_id response = await self._bot.wait_for('message', check=check) self.assertEqual(response.content, correct_response)