Skip to content

Commit

Permalink
add tests for pages and move task from api
Browse files Browse the repository at this point in the history
  • Loading branch information
uittenbroekrobbert committed May 24, 2024
1 parent 71bff01 commit cc4311c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
8 changes: 8 additions & 0 deletions tests/api/routes/test_pages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from fastapi.testclient import TestClient


def test_get_main_page(client: TestClient) -> None:
response = client.get("/pages/")
assert response.status_code == 200
assert response.headers["content-type"] == "text/html; charset=utf-8"
assert b"<!DOCTYPE html>" in response.content
5 changes: 2 additions & 3 deletions tests/api/routes/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
from tad.models.task import MoveTask


def test_get_root(client: TestClient) -> None:
def test_post_move_task(client: TestClient) -> None:
move_task: MoveTask = MoveTask(taskId="2", statusId="2", previousSiblingId="1", nextSiblingId="3")
print(move_task.model_dump_json(by_alias=True))
response = client.post("/tasks/move", json=move_task.model_dump(by_alias=True))
assert response.status_code == 200
assert response.headers["content-type"] == "text/html; charset=utf-8"
# assert b"<h1>Welcome to the Home Page</h1>" in response.content
assert b'class="progress_card_container"' in response.content
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
from tad.services.tasks import TasksService


def pytest_sessionstart(session):
def pytest_configure():
"""
Called after the Session object has been created and
before performing collection and entering the run test loop.
"""
# todo (robbert) creating an in memory database does not work right, tables seem to get lost?
settings.APP_DATABASE_FILE = "database.sqlite3.test" # set to none so we'll use an in memory database
# todo (robbert) this seems to be the only way to get the right session object (but I am not sure why)
SQLModel.metadata.create_all(get_engine())
with Session(get_engine()) as session:
tasks_repository = TasksRepository(session=session)
statuses_repository = StatusesRepository(session=session)
Expand All @@ -33,6 +34,5 @@ def pytest_sessionstart(session):
@pytest.fixture(scope="module")
def client() -> Generator[TestClient, None, None]:
with TestClient(app, raise_server_exceptions=True) as c:
SQLModel.metadata.create_all(get_engine())
c.timeout = 5
yield c

0 comments on commit cc4311c

Please sign in to comment.