Compare commits
6 Commits
77d723b9da
...
#139
Author | SHA1 | Date | |
---|---|---|---|
069c701a05 | |||
5efcddf983 | |||
5beaf24bdc | |||
4bbcd387c6 | |||
117e1aeda8 | |||
7260ed0164 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -144,3 +144,4 @@ deploy/
|
|||||||
|
|
||||||
# idea
|
# idea
|
||||||
.idea/
|
.idea/
|
||||||
|
selenium-data/
|
@@ -11,6 +11,32 @@
|
|||||||
"ConsoleLogLevel": "ERROR",
|
"ConsoleLogLevel": "ERROR",
|
||||||
"FileLogLevel": "WARN"
|
"FileLogLevel": "WARN"
|
||||||
},
|
},
|
||||||
|
"BotLoggingSettings": {
|
||||||
|
"Api": {
|
||||||
|
"Path": "logs/$date_now/",
|
||||||
|
"Filename": "api.log",
|
||||||
|
"ConsoleLogLevel": "INFO",
|
||||||
|
"FileLogLevel": "DEBUG"
|
||||||
|
},
|
||||||
|
"Command": {
|
||||||
|
"Path": "logs/$date_now/",
|
||||||
|
"Filename": "commands.log",
|
||||||
|
"ConsoleLogLevel": "INFO",
|
||||||
|
"FileLogLevel": "DEBUG"
|
||||||
|
},
|
||||||
|
"Database": {
|
||||||
|
"Path": "logs/$date_now/",
|
||||||
|
"Filename": "database.log",
|
||||||
|
"ConsoleLogLevel": "INFO",
|
||||||
|
"FileLogLevel": "DEBUG"
|
||||||
|
},
|
||||||
|
"Message": {
|
||||||
|
"Path": "logs/$date_now/",
|
||||||
|
"Filename": "message.log",
|
||||||
|
"ConsoleLogLevel": "INFO",
|
||||||
|
"FileLogLevel": "DEBUG"
|
||||||
|
}
|
||||||
|
},
|
||||||
"Translation": {
|
"Translation": {
|
||||||
"DefaultLanguage": "de",
|
"DefaultLanguage": "de",
|
||||||
"Languages": [
|
"Languages": [
|
||||||
@@ -20,6 +46,9 @@
|
|||||||
"TestSettings": {
|
"TestSettings": {
|
||||||
"LoginUrl": "https://discord.com/login",
|
"LoginUrl": "https://discord.com/login",
|
||||||
"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,
|
||||||
|
"BotId": 998159802393964594,
|
||||||
|
"TestUserId": 401941112010571777
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -4,13 +4,46 @@ from typing import Optional
|
|||||||
from cpl_core.application import StartupABC
|
from cpl_core.application import StartupABC
|
||||||
from cpl_core.configuration import ConfigurationABC
|
from cpl_core.configuration import ConfigurationABC
|
||||||
from cpl_core.database import DatabaseSettings
|
from cpl_core.database import DatabaseSettings
|
||||||
from cpl_core.database.context import DatabaseContext
|
from cpl_core.dependency_injection import ServiceCollectionABC
|
||||||
from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC
|
from cpl_core.dependency_injection import ServiceProviderABC
|
||||||
from cpl_core.environment import ApplicationEnvironment
|
from cpl_core.environment import ApplicationEnvironment
|
||||||
from cpl_discord import get_discord_collection
|
from cpl_discord import get_discord_collection
|
||||||
from cpl_discord.discord_event_types_enum import DiscordEventTypesEnum
|
from cpl_discord.discord_event_types_enum import DiscordEventTypesEnum
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
from bot.startup_settings_extension import StartupSettingsExtension
|
||||||
|
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
|
||||||
|
from bot_core.abc.custom_file_logger_abc import CustomFileLoggerABC
|
||||||
|
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||||
|
from bot_core.configuration.bot_logging_settings import BotLoggingSettings
|
||||||
|
from bot_core.logging.command_logger import CommandLogger
|
||||||
|
from bot_core.logging.database_logger import DatabaseLogger
|
||||||
|
from bot_core.logging.message_logger import MessageLogger
|
||||||
|
from bot_core.pipes.date_time_offset_pipe import DateTimeOffsetPipe
|
||||||
|
from bot_core.service.client_utils_service import ClientUtilsService
|
||||||
|
from bot_core.service.message_service import MessageService
|
||||||
|
from bot_data.abc.auth_user_repository_abc import AuthUserRepositoryABC
|
||||||
|
from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC
|
||||||
|
from bot_data.abc.client_repository_abc import ClientRepositoryABC
|
||||||
|
from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC
|
||||||
|
from bot_data.abc.level_repository_abc import LevelRepositoryABC
|
||||||
|
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||||
|
from bot_data.abc.statistic_repository_abc import StatisticRepositoryABC
|
||||||
|
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
|
||||||
|
from bot_data.abc.user_joined_voice_channel_abc import UserJoinedVoiceChannelRepositoryABC
|
||||||
|
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||||
|
from bot_data.db_context import DBContext
|
||||||
|
from bot_data.service.auth_user_repository_service import AuthUserRepositoryService
|
||||||
|
from bot_data.service.auto_role_repository_service import AutoRoleRepositoryService
|
||||||
|
from bot_data.service.client_repository_service import ClientRepositoryService
|
||||||
|
from bot_data.service.known_user_repository_service import KnownUserRepositoryService
|
||||||
|
from bot_data.service.level_repository_service import LevelRepositoryService
|
||||||
|
from bot_data.service.seeder_service import SeederService
|
||||||
|
from bot_data.service.server_repository_service import ServerRepositoryService
|
||||||
|
from bot_data.service.statistic_repository_service import StatisticRepositoryService
|
||||||
|
from bot_data.service.user_joined_server_repository_service import UserJoinedServerRepositoryService
|
||||||
|
from bot_data.service.user_joined_voice_channel_service import UserJoinedVoiceChannelRepositoryService
|
||||||
|
from bot_data.service.user_repository_service import UserRepositoryService
|
||||||
from ui_tests.test_on_ready_event import TestOnReadyEvent
|
from ui_tests.test_on_ready_event import TestOnReadyEvent
|
||||||
|
|
||||||
|
|
||||||
@@ -30,11 +63,17 @@ class Startup(StartupABC):
|
|||||||
configuration.add_json_file(f'{cwd}/config/appsettings.json', optional=False)
|
configuration.add_json_file(f'{cwd}/config/appsettings.json', optional=False)
|
||||||
configuration.add_json_file(f'{cwd}/config/appsettings.{environment.host_name}.json', optional=True)
|
configuration.add_json_file(f'{cwd}/config/appsettings.{environment.host_name}.json', optional=True)
|
||||||
|
|
||||||
|
StartupSettingsExtension._configure_settings_with_sub_settings(configuration, BotLoggingSettings, lambda x: x.files, lambda x: x.key)
|
||||||
|
|
||||||
self._config = configuration
|
self._config = configuration
|
||||||
return configuration
|
return configuration
|
||||||
|
|
||||||
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
|
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
|
||||||
services.add_logging()
|
services.add_logging()
|
||||||
|
services.add_singleton(CustomFileLoggerABC, CommandLogger)
|
||||||
|
services.add_singleton(CustomFileLoggerABC, DatabaseLogger)
|
||||||
|
services.add_singleton(CustomFileLoggerABC, MessageLogger)
|
||||||
|
|
||||||
services.add_translation()
|
services.add_translation()
|
||||||
db_settings: DatabaseSettings = self._config.get_configuration(DatabaseSettings)
|
db_settings: DatabaseSettings = self._config.get_configuration(DatabaseSettings)
|
||||||
db_settings_with_pw = DatabaseSettings()
|
db_settings_with_pw = DatabaseSettings()
|
||||||
@@ -49,10 +88,31 @@ class Startup(StartupABC):
|
|||||||
"Buffered": db_settings.buffered,
|
"Buffered": db_settings.buffered,
|
||||||
"AuthPlugin": db_settings.auth_plugin
|
"AuthPlugin": db_settings.auth_plugin
|
||||||
})
|
})
|
||||||
services.add_db_context(DatabaseContext, db_settings_with_pw)
|
services.add_db_context(DBContext, db_settings_with_pw)
|
||||||
|
|
||||||
services.add_discord()
|
services.add_discord()
|
||||||
dc = get_discord_collection(services)
|
dc = get_discord_collection(services)
|
||||||
dc.add_event(DiscordEventTypesEnum.on_ready.value, TestOnReadyEvent)
|
dc.add_event(DiscordEventTypesEnum.on_ready.value, TestOnReadyEvent)
|
||||||
|
|
||||||
|
# bot_core stuff
|
||||||
|
services.add_transient(MessageServiceABC, MessageService)
|
||||||
|
services.add_transient(ClientUtilsServiceABC, ClientUtilsService)
|
||||||
|
|
||||||
|
# pipes
|
||||||
|
services.add_transient(DateTimeOffsetPipe)
|
||||||
|
|
||||||
|
# data stuff
|
||||||
|
services.add_transient(AuthUserRepositoryABC, AuthUserRepositoryService)
|
||||||
|
services.add_transient(ServerRepositoryABC, ServerRepositoryService)
|
||||||
|
services.add_transient(UserRepositoryABC, UserRepositoryService)
|
||||||
|
services.add_transient(ClientRepositoryABC, ClientRepositoryService)
|
||||||
|
services.add_transient(KnownUserRepositoryABC, KnownUserRepositoryService)
|
||||||
|
services.add_transient(UserJoinedServerRepositoryABC, UserJoinedServerRepositoryService)
|
||||||
|
services.add_transient(UserJoinedVoiceChannelRepositoryABC, UserJoinedVoiceChannelRepositoryService)
|
||||||
|
services.add_transient(AutoRoleRepositoryABC, AutoRoleRepositoryService)
|
||||||
|
services.add_transient(LevelRepositoryABC, LevelRepositoryService)
|
||||||
|
services.add_transient(StatisticRepositoryABC, StatisticRepositoryService)
|
||||||
|
|
||||||
|
services.add_transient(SeederService)
|
||||||
|
|
||||||
return services.build_service_provider()
|
return services.build_service_provider()
|
||||||
|
@@ -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"
|
||||||
|
15
kdb-bot/test/ui_tests_shared/command_selectors_enum.py
Normal file
15
kdb-bot/test/ui_tests_shared/command_selectors_enum.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
from enum import 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_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'
|
||||||
|
|
||||||
|
kdb_test = "//*[contains (text(), 'Krümmelmonster-test')]"
|
||||||
|
|
||||||
|
ping = kdb_test
|
||||||
|
info = kdb_test
|
||||||
|
help = kdb_test
|
||||||
|
afk = kdb_test
|
||||||
|
purge = kdb_test
|
@@ -10,6 +10,7 @@ from selenium.webdriver.remote.webelement import WebElement
|
|||||||
from selenium.webdriver.support import expected_conditions
|
from selenium.webdriver.support import expected_conditions
|
||||||
from selenium.webdriver.support.wait import WebDriverWait
|
from selenium.webdriver.support.wait import WebDriverWait
|
||||||
|
|
||||||
|
from ui_tests_shared.command_selectors_enum import CommandSelectorsEnum
|
||||||
from ui_tests_shared.test_case_with_app import TestCaseWithApp
|
from ui_tests_shared.test_case_with_app import TestCaseWithApp
|
||||||
from ui_tests_shared.ui import UI
|
from ui_tests_shared.ui import UI
|
||||||
|
|
||||||
@@ -27,11 +28,25 @@ 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):
|
def send_message(cls, msg: str):
|
||||||
|
if UI.driver.current_url != cls._test_settings.cmd_url:
|
||||||
UI.driver.get(cls._test_settings.cmd_url)
|
UI.driver.get(cls._test_settings.cmd_url)
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
cmd_element_ident = (By.XPATH, '/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_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)
|
||||||
|
UI.driver.find_element(By.XPATH, CommandSelectorsEnum.msg_input.value).send_keys(Keys.ENTER)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def send_command(cls, cmd: str, selector: CommandSelectorsEnum, reload=True):
|
||||||
|
if reload or 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 = UI.driver.find_element(*cmd_element_ident)
|
||||||
cmd_element.send_keys(f'/{cmd}')
|
cmd_element.send_keys(f'/{cmd}')
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
@@ -40,9 +55,8 @@ class CommandTestCaseWithApp(TestCaseWithApp):
|
|||||||
WebDriverWait(UI.driver, 20, ignored_exceptions=ignored_exceptions).until(
|
WebDriverWait(UI.driver, 20, ignored_exceptions=ignored_exceptions).until(
|
||||||
expected_conditions.presence_of_element_located((
|
expected_conditions.presence_of_element_located((
|
||||||
By.XPATH,
|
By.XPATH,
|
||||||
'/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]'
|
selector.value
|
||||||
))
|
))
|
||||||
).click()
|
).click()
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
UI.driver.find_element(By.XPATH, '/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').send_keys(
|
UI.driver.find_element(By.XPATH, CommandSelectorsEnum.cmd_chat_input.value).send_keys(Keys.ENTER)
|
||||||
Keys.ENTER)
|
|
||||||
|
@@ -12,6 +12,9 @@ class TestSettings(ConfigurationModelABC):
|
|||||||
self._login_url = ''
|
self._login_url = ''
|
||||||
self._me_page_url = ''
|
self._me_page_url = ''
|
||||||
self._cmd_url = ''
|
self._cmd_url = ''
|
||||||
|
self._guild_id = 0
|
||||||
|
self._bot_id = 0
|
||||||
|
self._test_user_id = 0
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def login_url(self) -> str:
|
def login_url(self) -> str:
|
||||||
@@ -25,11 +28,26 @@ class TestSettings(ConfigurationModelABC):
|
|||||||
def cmd_url(self) -> str:
|
def cmd_url(self) -> str:
|
||||||
return self._cmd_url
|
return self._cmd_url
|
||||||
|
|
||||||
|
@property
|
||||||
|
def guild_id(self) -> int:
|
||||||
|
return self._guild_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def bot_id(self) -> int:
|
||||||
|
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']
|
||||||
self._me_page_url = settings['MePageUrl']
|
self._me_page_url = settings['MePageUrl']
|
||||||
self._cmd_url = settings['CmdURL']
|
self._cmd_url = settings['CmdURL']
|
||||||
|
self._guild_id = settings['GuildId']
|
||||||
|
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,12 +2,16 @@ 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:
|
try:
|
||||||
return asyncio.run(coro(*args, **kwargs))
|
if cls._loop is None:
|
||||||
|
cls._loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
|
return cls._loop.run_until_complete(coro(*args, **kwargs))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@@ -16,6 +16,7 @@ class TestCaseWithApp(unittest.TestCase):
|
|||||||
_config: Optional[ConfigurationABC] = None
|
_config: Optional[ConfigurationABC] = None
|
||||||
_services: Optional[ServiceProviderABC] = None
|
_services: Optional[ServiceProviderABC] = None
|
||||||
_test_settings: Optional[TestSettings] = None
|
_test_settings: Optional[TestSettings] = None
|
||||||
|
_loop = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
@@ -24,7 +25,11 @@ class TestCaseWithApp(unittest.TestCase):
|
|||||||
import nest_asyncio
|
import nest_asyncio
|
||||||
|
|
||||||
nest_asyncio.apply()
|
nest_asyncio.apply()
|
||||||
asyncio.run(app.run_async())
|
if cls._loop is None:
|
||||||
|
cls._loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
|
cls._loop.run_until_complete(app.run_async())
|
||||||
|
# asyncio.run(app.run_async())
|
||||||
|
|
||||||
cls._config = Declarations.app.config
|
cls._config = Declarations.app.config
|
||||||
cls._services = Declarations.app.services
|
cls._services = Declarations.app.services
|
||||||
|
@@ -19,8 +19,15 @@ class UI:
|
|||||||
_test_settings: Optional[TestSettings] = None
|
_test_settings: Optional[TestSettings] = None
|
||||||
|
|
||||||
options = webdriver.ChromeOptions()
|
options = webdriver.ChromeOptions()
|
||||||
|
options.add_argument("user-data-dir=selenium-data")
|
||||||
options.add_experimental_option('useAutomationExtension', False)
|
options.add_experimental_option('useAutomationExtension', False)
|
||||||
options.add_experimental_option("excludeSwitches", ["enable-automation"])
|
options.add_experimental_option("excludeSwitches", ["enable-automation"])
|
||||||
|
options.add_experimental_option("prefs", {
|
||||||
|
"profile.default_content_setting_values.media_stream_mic": 1,
|
||||||
|
"profile.default_content_setting_values.media_stream_camera": 1,
|
||||||
|
"profile.default_content_setting_values.geolocation": 1,
|
||||||
|
"profile.default_content_setting_values.notifications": 1
|
||||||
|
})
|
||||||
driver = webdriver.Chrome(options=options)
|
driver = webdriver.Chrome(options=options)
|
||||||
|
|
||||||
_is_logged_in = False
|
_is_logged_in = False
|
||||||
@@ -38,6 +45,11 @@ class UI:
|
|||||||
|
|
||||||
cls.driver.get(cls._test_settings.login_url)
|
cls.driver.get(cls._test_settings.login_url)
|
||||||
|
|
||||||
|
try:
|
||||||
|
WebDriverWait(cls.driver, 10).until(expected_conditions.url_matches(cls._test_settings.me_page_url))
|
||||||
|
cls._is_logged_in = True
|
||||||
|
return
|
||||||
|
except Exception as e:
|
||||||
WebDriverWait(cls.driver, 20).until(expected_conditions.presence_of_element_located((By.NAME, 'email')))
|
WebDriverWait(cls.driver, 20).until(expected_conditions.presence_of_element_located((By.NAME, 'email')))
|
||||||
|
|
||||||
mail_element = cls.driver.find_element(By.NAME, 'email')
|
mail_element = cls.driver.find_element(By.NAME, 'email')
|
||||||
|
@@ -0,0 +1,48 @@
|
|||||||
|
import discord
|
||||||
|
from selenium.webdriver.common.by import By
|
||||||
|
|
||||||
|
from 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
|
||||||
|
from ui_tests_shared.ui import UI
|
||||||
|
|
||||||
|
|
||||||
|
class AFKCommandTestCase(CommandTestCaseWithApp):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tearDownClass(cls):
|
||||||
|
btn = UI.driver.find_elements(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')
|
||||||
|
if len(btn) == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
btn[0].click()
|
||||||
|
|
||||||
|
@Async.async_func
|
||||||
|
async def test_error_message(self):
|
||||||
|
correct_response = self._t.transform('modules.base.afk_command_channel_missing_message')
|
||||||
|
self.assertIsNotNone(correct_response)
|
||||||
|
self.send_command('afk', CommandSelectorsEnum.afk, reload=False)
|
||||||
|
|
||||||
|
def check(m: discord.Message):
|
||||||
|
return m.author.id == self._test_settings.bot_id
|
||||||
|
|
||||||
|
response = await self._bot.wait_for('message', check=check, timeout=10)
|
||||||
|
self.assertEqual(response.content, correct_response)
|
||||||
|
|
||||||
|
@Async.async_func
|
||||||
|
async def test_move(self):
|
||||||
|
# correct_response = self._t.transform('modules.base.pong')
|
||||||
|
# self.assertIsNotNone(correct_response)
|
||||||
|
UI.driver.find_element(By.XPATH, '//*[@id="channels"]/ul/li[20]/div/div/div/a').click()
|
||||||
|
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, reload=False)
|
||||||
|
|
||||||
|
def check2(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 == 910199452915093594
|
||||||
|
member, before, after = await self._bot.wait_for('voice_state_update', check=check2, timeout=10)
|
||||||
|
self.assertIsNotNone(after.channel)
|
||||||
|
self.assertEqual(after.channel.id, 910199452915093594)
|
||||||
|
# self.assertEqual(response.content, correct_response)
|
@@ -1,19 +1,20 @@
|
|||||||
import discord
|
import discord
|
||||||
|
|
||||||
|
from ui_tests_shared.command_selectors_enum import CommandSelectorsEnum
|
||||||
from ui_tests_shared.command_test_case_with_app import CommandTestCaseWithApp
|
from ui_tests_shared.command_test_case_with_app import CommandTestCaseWithApp
|
||||||
from ui_tests_shared.decorators import Async
|
from ui_tests_shared.decorators import Async
|
||||||
|
|
||||||
|
|
||||||
class HelpTestCase(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')
|
self.send_command('help', CommandSelectorsEnum.help)
|
||||||
|
|
||||||
def check(m: discord.Message):
|
def check(m: discord.Message):
|
||||||
return m.content == correct_response and m.author.id == 998159802393964594
|
return 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)
|
||||||
await self._bot.close()
|
await self._bot.close()
|
@@ -0,0 +1,53 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
from unittest import skip
|
||||||
|
|
||||||
|
import discord
|
||||||
|
|
||||||
|
import bot
|
||||||
|
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
|
||||||
|
from 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 InfoCommandTestCase(CommandTestCaseWithApp):
|
||||||
|
|
||||||
|
def get_embed(self) -> discord.Embed:
|
||||||
|
client_utils: ClientUtilsServiceABC = self._services.get_service(ClientUtilsServiceABC)
|
||||||
|
client = client_utils.get_client(self._test_settings.bot_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')
|
||||||
|
start_time = str(datetime.now())
|
||||||
|
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
|
||||||
|
|
||||||
|
@skip('stage db not ready yet')
|
||||||
|
@Async.async_func
|
||||||
|
async def test_info(self):
|
||||||
|
correct_response = self.get_embed()
|
||||||
|
self.send_command('info', CommandSelectorsEnum.info)
|
||||||
|
|
||||||
|
def check(m: discord.Message):
|
||||||
|
return m.embeds[0] == correct_response and m.author.id == self._test_settings.bot_id
|
||||||
|
|
||||||
|
response: discord.Message = await self._bot.wait_for('message', check=check, timeout=10)
|
||||||
|
self.assertEqual(len(response.embeds), 1)
|
||||||
|
|
||||||
|
self.assertEqual(response.embeds[0], correct_response)
|
||||||
|
await self._bot.close()
|
@@ -1,19 +1,20 @@
|
|||||||
import discord
|
import discord
|
||||||
|
|
||||||
|
from ui_tests_shared.command_selectors_enum import CommandSelectorsEnum
|
||||||
from ui_tests_shared.command_test_case_with_app import CommandTestCaseWithApp
|
from ui_tests_shared.command_test_case_with_app import CommandTestCaseWithApp
|
||||||
from ui_tests_shared.decorators import Async
|
from ui_tests_shared.decorators import Async
|
||||||
|
|
||||||
|
|
||||||
class PingTestCase(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)
|
||||||
self.send_command('ping')
|
self.send_command('ping', CommandSelectorsEnum.ping)
|
||||||
|
|
||||||
def check(m: discord.Message):
|
def check(m: discord.Message):
|
||||||
return m.content == correct_response and m.author.id == 998159802393964594
|
return 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)
|
@@ -0,0 +1,34 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
|
import discord
|
||||||
|
|
||||||
|
from 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')
|
||||||
|
|
||||||
|
@Async.async_func
|
||||||
|
async 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.author.id == self._test_settings.bot_id
|
||||||
|
|
||||||
|
response = await self._bot.wait_for('message', check=check, timeout=10)
|
||||||
|
self.assertEqual(response.content, correct_response)
|
||||||
|
time.sleep(20)
|
||||||
|
channel = self._bot.get_channel(911578680998895687)
|
||||||
|
message_count = 0
|
||||||
|
async for _ in channel.history(limit=None):
|
||||||
|
message_count += 1
|
||||||
|
self.assertEqual(message_count, 0)
|
Reference in New Issue
Block a user