From 3ce823f20955fd5ae6ee9c7b2545a61aa70656f2 Mon Sep 17 00:00:00 2001 From: stijndcl Date: Thu, 23 Jun 2022 11:09:43 +0200 Subject: [PATCH 1/7] Stash --- didier/cogs/owner.py | 8 ++++---- didier/data/modals/custom_commands.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/didier/cogs/owner.py b/didier/cogs/owner.py index 1e2d6b3..60fbe78 100644 --- a/didier/cogs/owner.py +++ b/didier/cogs/owner.py @@ -36,7 +36,7 @@ class Owner(commands.Cog): self.client.tree.copy_global_to(guild=guild) await self.client.tree.sync(guild=guild) else: - self.client.tree.clear_commands(guild=None) + # self.client.tree.clear_commands(guild=None) await self.client.tree.sync() await ctx.message.add_reaction("🔄") @@ -73,14 +73,14 @@ class Owner(commands.Cog): @add_slash.command(name="custom", description="Add a custom command") async def add_custom_slash(self, interaction: discord.Interaction): """Slash command to add a custom command""" - if not self.client.is_owner(interaction.user): + if not await self.client.is_owner(interaction.user): return interaction.response.send_message( "Je hebt geen toestemming om dit commando uit te voeren.", ephemeral=True ) - await interaction.response.defer(ephemeral=True) + # await interaction.response.defer(ephemeral=True) modal = CreateCustomCommand() - await interaction.response.send_message(modal) + await interaction.response.send_modal(modal) @commands.group(name="Edit") async def edit(self, ctx: commands.Context): diff --git a/didier/data/modals/custom_commands.py b/didier/data/modals/custom_commands.py index 18d9809..35f7f74 100644 --- a/didier/data/modals/custom_commands.py +++ b/didier/data/modals/custom_commands.py @@ -6,10 +6,10 @@ import discord class CreateCustomCommand(discord.ui.Modal, title="Custom Command"): """Modal shown to visually create custom commands""" - name: discord.ui.TextInput = discord.ui.TextInput(label="Name", placeholder="Name of the command...") + name: discord.ui.TextInput = discord.ui.TextInput(label="Name", placeholder="Name of the command") response: discord.ui.TextInput = discord.ui.TextInput( - label="Response", style=discord.TextStyle.long, placeholder="Response of the command...", max_length=2000 + label="Response", style=discord.TextStyle.long, placeholder="Response of the command", max_length=2000 ) async def on_submit(self, interaction: discord.Interaction) -> None: From cc8f8b1ee4485200ba1d22dd28b79ac696641324 Mon Sep 17 00:00:00 2001 From: stijndcl Date: Thu, 23 Jun 2022 11:24:12 +0200 Subject: [PATCH 2/7] Try to fix tests --- didier/cogs/owner.py | 1 - tests/conftest.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/didier/cogs/owner.py b/didier/cogs/owner.py index 60fbe78..91fe500 100644 --- a/didier/cogs/owner.py +++ b/didier/cogs/owner.py @@ -36,7 +36,6 @@ class Owner(commands.Cog): self.client.tree.copy_global_to(guild=guild) await self.client.tree.sync(guild=guild) else: - # self.client.tree.clear_commands(guild=None) await self.client.tree.sync() await ctx.message.add_reaction("🔄") diff --git a/tests/conftest.py b/tests/conftest.py index c2c5e0a..3c5761b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -19,7 +19,7 @@ def event_loop() -> Generator: @pytest.fixture(scope="session") -def tables(event_loop): +def tables(): """Initialize a database before the tests, and then tear it down again Starts from an empty database and runs through all the migrations to check those as well while we're at it From 6b91e792e6c5c3e4f99ee2f07532803464770adb Mon Sep 17 00:00:00 2001 From: stijndcl Date: Thu, 23 Jun 2022 11:38:58 +0200 Subject: [PATCH 3/7] Use event loop fixture again --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 3c5761b..c2c5e0a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -19,7 +19,7 @@ def event_loop() -> Generator: @pytest.fixture(scope="session") -def tables(): +def tables(event_loop): """Initialize a database before the tests, and then tear it down again Starts from an empty database and runs through all the migrations to check those as well while we're at it From 85a7750d09989f8c3121f8eed03824194382773b Mon Sep 17 00:00:00 2001 From: stijndcl Date: Thu, 23 Jun 2022 11:53:21 +0200 Subject: [PATCH 4/7] No longer run migrations in tests --- tests/conftest.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index c2c5e0a..6c04eb6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,11 +3,10 @@ from typing import AsyncGenerator, Generator from unittest.mock import MagicMock import pytest - -from alembic import command, config from sqlalchemy.ext.asyncio import AsyncSession from database.engine import engine +from database.models import Base from didier import Didier @@ -19,15 +18,12 @@ def event_loop() -> Generator: @pytest.fixture(scope="session") -def tables(event_loop): - """Initialize a database before the tests, and then tear it down again - Starts from an empty database and runs through all the migrations to check those as well - while we're at it - """ - alembic_config = config.Config("alembic.ini") - command.upgrade(alembic_config, "head") - yield - command.downgrade(alembic_config, "base") +async def tables(event_loop): + """Initialize a database before the tests, and then tear it down again""" + async with engine.begin() as connection: + await connection.run_sync(Base.metadata.create_all) + yield + await connection.run_sync(Base.metadata.drop_all) @pytest.fixture From 36909f04bda531a3b2b3d474ead417f49566ea7e Mon Sep 17 00:00:00 2001 From: stijndcl Date: Thu, 23 Jun 2022 11:56:25 +0200 Subject: [PATCH 5/7] Use alembic test package --- .github/workflows/python.yml | 2 +- requirements-dev.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 382bc76..81260bd 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -53,7 +53,7 @@ jobs: - name: Install dependencies run: pip3 install -r requirements.txt -r requirements-dev.txt - name: Run Pytest - run: pytest tests + run: pytest tests --test-alembic env: DB_TEST_SQLITE: false DB_NAME: didier_action diff --git a/requirements-dev.txt b/requirements-dev.txt index ef7679c..6438912 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,6 +3,7 @@ black==22.3.0 mypy==0.961 pylint==2.14.1 pytest==7.1.2 +pytest-alembic==0.8.2 pytest-asyncio==0.18.3 pytest-env==0.6.2 sqlalchemy2-stubs==0.0.2a23 From ee03cf7d8cb87be04d77c60b2cddbd3a82e3131b Mon Sep 17 00:00:00 2001 From: stijndcl Date: Thu, 23 Jun 2022 12:04:29 +0200 Subject: [PATCH 6/7] Try to fix tables fixture --- tests/conftest.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 6c04eb6..e38928a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ import asyncio +import os from typing import AsyncGenerator, Generator from unittest.mock import MagicMock @@ -22,8 +23,6 @@ async def tables(event_loop): """Initialize a database before the tests, and then tear it down again""" async with engine.begin() as connection: await connection.run_sync(Base.metadata.create_all) - yield - await connection.run_sync(Base.metadata.drop_all) @pytest.fixture From 257eae6fa71643fd3c6e562803524d37a01aa856 Mon Sep 17 00:00:00 2001 From: stijndcl Date: Thu, 23 Jun 2022 12:09:54 +0200 Subject: [PATCH 7/7] Remove pytest-alembic --- .github/workflows/python.yml | 2 +- requirements-dev.txt | 1 - tests/conftest.py | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 81260bd..382bc76 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -53,7 +53,7 @@ jobs: - name: Install dependencies run: pip3 install -r requirements.txt -r requirements-dev.txt - name: Run Pytest - run: pytest tests --test-alembic + run: pytest tests env: DB_TEST_SQLITE: false DB_NAME: didier_action diff --git a/requirements-dev.txt b/requirements-dev.txt index 6438912..ef7679c 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,7 +3,6 @@ black==22.3.0 mypy==0.961 pylint==2.14.1 pytest==7.1.2 -pytest-alembic==0.8.2 pytest-asyncio==0.18.3 pytest-env==0.6.2 sqlalchemy2-stubs==0.0.2a23 diff --git a/tests/conftest.py b/tests/conftest.py index e38928a..799c3bc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,4 @@ import asyncio -import os from typing import AsyncGenerator, Generator from unittest.mock import MagicMock