Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for the demo suite #95

Merged
merged 1 commit into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions tad/core/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from sqlalchemy.engine import Engine
from sqlalchemy.pool import QueuePool, StaticPool
from sqlmodel import Session, SQLModel, create_engine, select
from sqlmodel import Session, SQLModel, create_engine, select, update

from tad.core.config import get_settings
from tad.models import Status, Task, User
Expand Down Expand Up @@ -35,15 +35,16 @@ def check_db():


def remove_old_demo_objects(session: Session):
task = session.exec(select(Task).where(Task.title == "First task")).first()
if task:
session.delete(task)
session.exec(update(Task).values(status_id=None, user_id=None)) # type: ignore
user = session.exec(select(User).where(User.name == "Robbert")).first()
if user:
session.delete(user)
status = session.exec(select(Status).where(Status.name == "Todo")).first()
status = session.exec(select(Status).where(Status.name == "todo")).first()
if status:
session.delete(status)
task = session.exec(select(Task).where(Task.title == "First task")).first()
if task:
session.delete(task)
session.commit()


Expand Down Expand Up @@ -87,6 +88,7 @@ def add_demo_tasks(session: Session, status: Status | None, number_of_tasks: int
status_id=status.id,
)
)
session.exec(update(Task).values(status_id=status.id)) # type: ignore
session.commit()


Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_remove_old_demo_objects(db: DatabaseTestUtils):
db_session.delete = MagicMock()

user = User(name="Robbert", avatar=None)
status = Status(name="Todo", sort_order=1)
status = Status(name="todo", sort_order=1)
task = Task(title="First task", description="This is the first task", sort_order=1, status_id=status.id)
db.given([user, status, task])

Expand Down
Loading