From 84ae90f323be196c9152e6b917c44884a78d6237 Mon Sep 17 00:00:00 2001 From: kraanzu Date: Sat, 19 Oct 2024 12:48:20 +0530 Subject: [PATCH] feat: better dates + clear data before generation --- tests/generate_test_data.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/generate_test_data.py b/tests/generate_test_data.py index d7c378db..81ec8078 100644 --- a/tests/generate_test_data.py +++ b/tests/generate_test_data.py @@ -1,5 +1,8 @@ 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() @@ -7,10 +10,18 @@ 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( @@ -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 @@ -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)]