Compare commits
2 Commits
117e1aeda8
...
5beaf24bdc
Author | SHA1 | Date | |
---|---|---|---|
5beaf24bdc | |||
4bbcd387c6 |
@ -22,6 +22,7 @@
|
|||||||
"MePageUrl": "https://discord.com/channels/@me",
|
"MePageUrl": "https://discord.com/channels/@me",
|
||||||
"CmdURL": "https://discord.com/channels/910199451145076828/911578636899987526",
|
"CmdURL": "https://discord.com/channels/910199451145076828/911578636899987526",
|
||||||
"GuildId": 910199451145076828,
|
"GuildId": 910199451145076828,
|
||||||
"BotId": 998159802393964594
|
"BotId": 998159802393964594,
|
||||||
|
"TestUserId": 401941112010571777
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,8 +4,10 @@ from enum import Enum
|
|||||||
class CommandSelectorsEnum(Enum):
|
class CommandSelectorsEnum(Enum):
|
||||||
cmd_chat = '/html/body/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div/div[3]/div[2]/main/form/div/div[1]/div/div[3]/div/div[2]/div'
|
cmd_chat = '/html/body/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div/div[3]/div[2]/main/form/div/div[1]/div/div[3]/div/div[2]/div'
|
||||||
cmd_chat_input = '/html/body/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div/div[3]/div/main/form/div/div[2]/div/div[2]/div/div'
|
cmd_chat_input = '/html/body/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div/div[3]/div/main/form/div/div[2]/div/div[2]/div/div'
|
||||||
|
msg_input = '/html/body/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div/div[3]/div[2]/main/form/div/div[1]/div/div[3]/div/div/div'
|
||||||
|
|
||||||
ping = '//*[ contains (text(), ‘Krümmelmonster-test’ ) ]'
|
ping = '/html/body/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div/div[3]/div[2]/main/form/div/div[2]/div/div/div[5]/div'
|
||||||
info = '//*[ contains (text(), ‘Krümmelmonster-test’ ) ]'
|
info = '/html/body/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div/div[3]/div[2]/main/form/div/div[2]/div/div/div[5]/div'
|
||||||
help = '//*[ contains (text(), ‘Krümmelmonster-test’ ) ]'
|
help = '/html/body/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div/div[3]/div[2]/main/form/div/div[2]/div/div/div[5]/div'
|
||||||
afk = '//*[ contains (text(), ‘Krümmelmonster-test’ ) ]'
|
afk = '/html/body/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div/div[3]/div[2]/main/form/div/div[2]/div/div/div[2]/div'
|
||||||
|
purge = '/html/body/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div/div[3]/div[2]/main/form/div/div[2]/div/div/div[5]/div'
|
||||||
|
@ -16,7 +16,12 @@
|
|||||||
"LicenseName": "",
|
"LicenseName": "",
|
||||||
"LicenseDescription": "",
|
"LicenseDescription": "",
|
||||||
"Dependencies": [
|
"Dependencies": [
|
||||||
"cpl-core>=2022.10.0.post9"
|
"cpl-core>=2022.10.0.post9",
|
||||||
|
"PyNaCl==1.5.0",
|
||||||
|
"cffi==1.15.1",
|
||||||
|
"pycparser==2.21",
|
||||||
|
"selenium==4.6.1",
|
||||||
|
"webdriver-manager==3.8.5"
|
||||||
],
|
],
|
||||||
"DevDependencies": [
|
"DevDependencies": [
|
||||||
"cpl-cli>=2022.10.0"
|
"cpl-cli>=2022.10.0"
|
||||||
|
@ -28,9 +28,22 @@ class CommandTestCaseWithApp(TestCaseWithApp):
|
|||||||
cls._t = cls._services.get_service(TranslatePipe)
|
cls._t = cls._services.get_service(TranslatePipe)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def send_command(cls, cmd: str, selector: CommandSelectorsEnum):
|
def send_message(cls, msg: str):
|
||||||
UI.driver.get(cls._test_settings.cmd_url)
|
if UI.driver.current_url != cls._test_settings.cmd_url:
|
||||||
|
UI.driver.get(cls._test_settings.cmd_url)
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
cmd_element_ident = (By.XPATH, CommandSelectorsEnum.cmd_chat.value)
|
||||||
|
cmd_element = UI.driver.find_element(*cmd_element_ident)
|
||||||
|
cmd_element.send_keys(msg)
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
UI.driver.find_element(By.XPATH, CommandSelectorsEnum.msg_input.value).send_keys(Keys.ENTER)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def send_command(cls, cmd: str, selector: CommandSelectorsEnum):
|
||||||
|
if UI.driver.current_url != cls._test_settings.cmd_url:
|
||||||
|
UI.driver.get(cls._test_settings.cmd_url)
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
cmd_element_ident = (By.XPATH, CommandSelectorsEnum.cmd_chat.value)
|
cmd_element_ident = (By.XPATH, CommandSelectorsEnum.cmd_chat.value)
|
||||||
cmd_element = UI.driver.find_element(*cmd_element_ident)
|
cmd_element = UI.driver.find_element(*cmd_element_ident)
|
||||||
|
@ -14,6 +14,7 @@ class TestSettings(ConfigurationModelABC):
|
|||||||
self._cmd_url = ''
|
self._cmd_url = ''
|
||||||
self._guild_id = 0
|
self._guild_id = 0
|
||||||
self._bot_id = 0
|
self._bot_id = 0
|
||||||
|
self._test_user_id = 0
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def login_url(self) -> str:
|
def login_url(self) -> str:
|
||||||
@ -35,6 +36,10 @@ class TestSettings(ConfigurationModelABC):
|
|||||||
def bot_id(self) -> int:
|
def bot_id(self) -> int:
|
||||||
return self._bot_id
|
return self._bot_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def test_user_id(self) -> int:
|
||||||
|
return self._test_user_id
|
||||||
|
|
||||||
def from_dict(self, settings: dict):
|
def from_dict(self, settings: dict):
|
||||||
try:
|
try:
|
||||||
self._login_url = settings['LoginUrl']
|
self._login_url = settings['LoginUrl']
|
||||||
@ -42,6 +47,7 @@ class TestSettings(ConfigurationModelABC):
|
|||||||
self._cmd_url = settings['CmdURL']
|
self._cmd_url = settings['CmdURL']
|
||||||
self._guild_id = settings['GuildId']
|
self._guild_id = settings['GuildId']
|
||||||
self._bot_id = settings['BotId']
|
self._bot_id = settings['BotId']
|
||||||
|
self._test_user_id = settings['TestUserId']
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings')
|
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings')
|
||||||
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
||||||
|
@ -2,13 +2,14 @@ import asyncio
|
|||||||
|
|
||||||
|
|
||||||
class Async:
|
class Async:
|
||||||
|
_loop = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def test(cls, coro):
|
def async_func(cls, coro):
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
try:
|
if cls._loop is None:
|
||||||
return asyncio.run(coro(*args, **kwargs))
|
cls._loop = asyncio.get_event_loop()
|
||||||
except Exception as e:
|
|
||||||
return
|
return cls._loop.run_until_complete(coro(*args, **kwargs))
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
@ -12,7 +12,7 @@ from ui_tests_shared.ui import UI
|
|||||||
|
|
||||||
class AFKCommandTestCase(CommandTestCaseWithApp):
|
class AFKCommandTestCase(CommandTestCaseWithApp):
|
||||||
|
|
||||||
@Async.test
|
@Async.async_func
|
||||||
async def test_error_message(self):
|
async def test_error_message(self):
|
||||||
correct_response = self._t.transform('modules.base.afk_command_channel_missing_message')
|
correct_response = self._t.transform('modules.base.afk_command_channel_missing_message')
|
||||||
self.assertIsNotNone(correct_response)
|
self.assertIsNotNone(correct_response)
|
||||||
@ -21,22 +21,24 @@ class AFKCommandTestCase(CommandTestCaseWithApp):
|
|||||||
def check(m: discord.Message):
|
def check(m: discord.Message):
|
||||||
return m.content == correct_response and m.author.id == self._test_settings.bot_id
|
return m.content == correct_response and m.author.id == self._test_settings.bot_id
|
||||||
|
|
||||||
response = await self._bot.wait_for('message', check=check)
|
response = await self._bot.wait_for('message', check=check, timeout=10)
|
||||||
self.assertEqual(response.content, correct_response)
|
self.assertEqual(response.content, correct_response)
|
||||||
|
|
||||||
@Async.test
|
@Async.async_func
|
||||||
async def test_move(self):
|
async def test_move(self):
|
||||||
# correct_response = self._t.transform('modules.base.pong')
|
# correct_response = self._t.transform('modules.base.pong')
|
||||||
# self.assertIsNotNone(correct_response)
|
# self.assertIsNotNone(correct_response)
|
||||||
UI.driver.find_element(By.XPATH, '//*[@id="channels"]/ul/li[20]/div/div/div/a').click()
|
UI.driver.find_element(By.XPATH, '//*[@id="channels"]/ul/li[20]/div/div/div/a').click()
|
||||||
time.sleep(1)
|
def check1(member: discord.Member, before: discord.VoiceState, after: discord.VoiceState):
|
||||||
|
return member.id == self._test_settings.test_user_id and after is not None and after.channel.id == 911578760476762153
|
||||||
|
res = await self._bot.wait_for('voice_state_update', check=check1, timeout=10)
|
||||||
|
|
||||||
self.send_command('afk', CommandSelectorsEnum.afk)
|
self.send_command('afk', CommandSelectorsEnum.afk)
|
||||||
|
|
||||||
def check(member: discord.Member, before: discord.VoiceState, after: discord.VoiceState):
|
def check2(member: discord.Member, before: discord.VoiceState, after: discord.VoiceState):
|
||||||
return member.id == self._bot.user.id
|
return member.id == self._test_settings.test_user_id and after is not None and after.channel.id == 910199452915093594
|
||||||
|
member, before, after = await self._bot.wait_for('voice_state_update', check=check2, timeout=10)
|
||||||
response: VoiceState = await self._bot.wait_for('voice_state_update', check=check)
|
UI.driver.find_element(By.XPATH, '/html/body/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div/div[1]/section/div[1]/div/div[1]/div[2]/button').click()
|
||||||
self.assertIsNotNone(response.channel)
|
self.assertIsNotNone(after.channel)
|
||||||
self.assertEqual(response.channel.id, 910199452915093594)
|
self.assertEqual(after.channel.id, 910199452915093594)
|
||||||
# self.assertEqual(response.content, correct_response)
|
# self.assertEqual(response.content, correct_response)
|
||||||
|
@ -7,7 +7,7 @@ from ui_tests_shared.decorators import Async
|
|||||||
|
|
||||||
class HelpCommandTestCase(CommandTestCaseWithApp):
|
class HelpCommandTestCase(CommandTestCaseWithApp):
|
||||||
|
|
||||||
@Async.test
|
@Async.async_func
|
||||||
async def test_help(self):
|
async def test_help(self):
|
||||||
correct_response = 'https://git.sh-edraft.de/sh-edraft.de/kd_discord_bot/wiki/Befehle'
|
correct_response = 'https://git.sh-edraft.de/sh-edraft.de/kd_discord_bot/wiki/Befehle'
|
||||||
self.send_command('help', CommandSelectorsEnum.help)
|
self.send_command('help', CommandSelectorsEnum.help)
|
||||||
|
@ -34,7 +34,7 @@ class InfoCommandTestCase(CommandTestCaseWithApp):
|
|||||||
embed.add_field(name=self._t.transform('modules.base.info.fields.modules'), value='\n'.join(modules), inline=False)
|
embed.add_field(name=self._t.transform('modules.base.info.fields.modules'), value='\n'.join(modules), inline=False)
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
@Async.test
|
@Async.async_func
|
||||||
async def test_info(self):
|
async def test_info(self):
|
||||||
correct_response = self.get_embed()
|
correct_response = self.get_embed()
|
||||||
self.send_command('info', CommandSelectorsEnum.info)
|
self.send_command('info', CommandSelectorsEnum.info)
|
||||||
|
@ -7,7 +7,7 @@ from ui_tests_shared.decorators import Async
|
|||||||
|
|
||||||
class PingCommandTestCase(CommandTestCaseWithApp):
|
class PingCommandTestCase(CommandTestCaseWithApp):
|
||||||
|
|
||||||
@Async.test
|
@Async.async_func
|
||||||
async def test_ping(self):
|
async def test_ping(self):
|
||||||
correct_response = self._t.transform('modules.base.pong')
|
correct_response = self._t.transform('modules.base.pong')
|
||||||
self.assertIsNotNone(correct_response)
|
self.assertIsNotNone(correct_response)
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
import asyncio
|
||||||
|
import time
|
||||||
|
|
||||||
|
import discord
|
||||||
|
|
||||||
|
from ui_tests.src.ui_tests_shared.command_selectors_enum import CommandSelectorsEnum
|
||||||
|
from ui_tests_shared.command_test_case_with_app import CommandTestCaseWithApp
|
||||||
|
from ui_tests_shared.decorators import Async
|
||||||
|
|
||||||
|
|
||||||
|
class PurgeCommandTestCase(CommandTestCaseWithApp):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.send_message('test nachricht 1')
|
||||||
|
self.send_message('test nachricht 2')
|
||||||
|
self.send_message('test nachricht 3')
|
||||||
|
self.send_message('test nachricht 4')
|
||||||
|
|
||||||
|
def test_purge(self):
|
||||||
|
correct_response = self._t.transform('modules.moderator.purge_message')
|
||||||
|
self.assertIsNotNone(correct_response)
|
||||||
|
self.send_command('purge', CommandSelectorsEnum.purge)
|
||||||
|
|
||||||
|
def check(m: discord.Message):
|
||||||
|
return m.content == correct_response and m.author.id == self._test_settings.bot_id
|
||||||
|
|
||||||
|
response = asyncio.run(self._bot.wait_for('message', check=check))
|
||||||
|
self.assertEqual(response.content, correct_response)
|
||||||
|
time.sleep(20)
|
||||||
|
channel = self._bot.get_channel(911578680998895687)
|
||||||
|
self.assertEqual(channel.message_count, 0)
|
Loading…
Reference in New Issue
Block a user