Feat(API): Database schema and models defined

- Wrote tests for database migrations and populate with test data
This commit is contained in:
minhtrannhat
2022-12-23 19:57:21 -05:00
parent ad5596c61c
commit c641ddd47d
14 changed files with 269 additions and 1 deletions

View File

View File

@@ -0,0 +1,17 @@
import pytest
from asyncpg.exceptions import UniqueViolationError # type: ignore
from quart_db import Connection
from backend.models.member import insert_member, select_member_by_email
async def test_insert_member(connection: Connection) -> None:
await insert_member(connection, "casing@todo.minhtrannhat.com", "")
with pytest.raises(UniqueViolationError):
await insert_member(connection, "Casing@todo.minhtrannhat.com", "")
async def test_select_member_by_email(connection: Connection) -> None:
await insert_member(connection, "casing@todo.minhtrannhat.com", "")
member = await select_member_by_email(connection, "Casing@todo.minhtrannhat.com")
assert member is not None

View File

@@ -0,0 +1,31 @@
import pytest
from quart_db import Connection
from backend.models.todo import delete_todo, insert_todo, select_todo, update_todo
@pytest.mark.parametrize(
"member_id, deleted",
[(1, True), (2, False)],
)
async def test_delete_todo(
connection: Connection, member_id: int, deleted: bool
) -> None:
todo = await insert_todo(connection, 1, "Task", False, None)
await delete_todo(connection, todo.id, member_id)
new_todo = await select_todo(connection, todo.id, 1)
assert (new_todo is None) is deleted
@pytest.mark.parametrize(
"member_id, complete",
[(1, True), (2, False)],
)
async def test_update_todo(
connection: Connection, member_id: int, complete: bool
) -> None:
todo = await insert_todo(connection, 1, "Task", False, None)
await update_todo(connection, todo.id, member_id, "Task", True, None)
new_todo = await select_todo(connection, todo.id, 1)
assert new_todo is not None
assert new_todo.complete is complete