Feat(API): Database schema and models defined
- Wrote tests for database migrations and populate with test data
This commit is contained in:
0
backend/tests/models/__init__.py
Normal file
0
backend/tests/models/__init__.py
Normal file
17
backend/tests/models/test_member.py
Normal file
17
backend/tests/models/test_member.py
Normal 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
|
31
backend/tests/models/test_todo.py
Normal file
31
backend/tests/models/test_todo.py
Normal 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
|
Reference in New Issue
Block a user