Editing of custom commands, add posix flags

This commit is contained in:
stijndcl 2022-06-25 01:57:52 +02:00
parent 257eae6fa7
commit d6a560851b
9 changed files with 184 additions and 22 deletions

View file

@ -4,7 +4,8 @@ from sqlalchemy.ext.asyncio import AsyncSession
from database.crud import custom_commands as crud
from database.exceptions.constraints import DuplicateInsertException
from database.models import CustomCommand, CustomCommandAlias
from database.exceptions.not_found import NoResultFoundException
from database.models import CustomCommand
async def test_create_command_non_existing(database_session: AsyncSession):
@ -33,7 +34,7 @@ async def test_create_command_name_is_alias(database_session: AsyncSession):
await crud.create_command(database_session, "n", "other response")
async def test_create_alias_non_existing(database_session: AsyncSession):
async def test_create_alias(database_session: AsyncSession):
"""Test creating an alias when the name is still free"""
command = await crud.create_command(database_session, "name", "response")
await crud.create_alias(database_session, command.name, "n")
@ -43,6 +44,12 @@ async def test_create_alias_non_existing(database_session: AsyncSession):
assert command.aliases[0].alias == "n"
async def test_create_alias_non_existing(database_session: AsyncSession):
"""Test creating an alias when the command doesn't exist"""
with pytest.raises(NoResultFoundException):
await crud.create_alias(database_session, "name", "alias")
async def test_create_alias_duplicate(database_session: AsyncSession):
"""Test creating an alias when another alias already has this name"""
command = await crud.create_command(database_session, "name", "response")
@ -96,3 +103,17 @@ async def test_get_command_by_alias(database_session: AsyncSession):
async def test_get_command_non_existing(database_session: AsyncSession):
"""Test getting a command when it doesn't exist"""
assert await crud.get_command(database_session, "name") is None
async def test_edit_command(database_session: AsyncSession):
"""Test editing an existing command"""
command = await crud.create_command(database_session, "name", "response")
await crud.edit_command(database_session, command.name, "new name", "new response")
assert command.name == "new name"
assert command.response == "new response"
async def test_edit_command_non_existing(database_session: AsyncSession):
"""Test editing a command that doesn't exist"""
with pytest.raises(NoResultFoundException):
await crud.edit_command(database_session, "name", "n", "r")