Skip to content

Commit

Permalink
feat: better dates + clear data before generation
Browse files Browse the repository at this point in the history
  • Loading branch information
kraanzu committed Oct 19, 2024
1 parent aadca02 commit 84ae90f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tests/generate_test_data.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import faker
from random import randint

from sqlalchemy import MetaData
from sqlalchemy.orm import Session
from dooit.api import Todo, Workspace, manager

manager.register_engine()

f = faker.Faker()


def delete_all_data(session: Session):
meta = MetaData()
meta.reflect(bind=session.get_bind())
for table in reversed(meta.sorted_tables):
session.execute(table.delete())
session.commit()


def gen_todo(parent):
words = randint(2, 9)
description = " ".join(f.words(nb=words))
due = f.date_time()
due = f.date_between(start_date="-1y", end_date="+1y")
urgency = randint(2, 5) if randint(0, 10) == 5 else 1

todo = Todo(
Expand All @@ -22,6 +33,8 @@ def gen_todo(parent):

if isinstance(parent, Todo):
todo.parent_todo = parent
todo.due = None
todo.urgency = 0
else:
todo.parent_workspace = parent

Expand All @@ -43,6 +56,8 @@ def gen_workspace(parent=None):
return workspace


delete_all_data(manager.session)

w1 = gen_workspace()
w1_childs = [gen_workspace(w1) for _ in range(5)]

Expand Down

0 comments on commit 84ae90f

Please sign in to comment.