Skip to content

Commit

Permalink
Fix for the demo suite (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
berrydenhartog authored Jul 13, 2024
2 parents 88db620 + 847a43c commit 2f543f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
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

0 comments on commit 2f543f6

Please sign in to comment.