Skip to content
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
21 changes: 21 additions & 0 deletions tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,24 @@ def test_get_all_todos_works_with_local_connections(monkeypatch, tmp_path) -> No
insert_todo(Todo(task="alpha", category="study"))

assert len(get_all_todos()) == 1


def test_get_all_todos_returns_rows_ordered_by_position(monkeypatch, tmp_path) -> None:
db_path = tmp_path / "todos.db"
monkeypatch.setattr("trushell.database.DB_PATH", db_path)

_create_table()
with get_db_connection() as conn:
conn.execute(
"INSERT INTO todos VALUES (?, ?, ?, ?, ?, ?)",
("second", "work", "", None, 0, 1),
)
conn.execute(
"INSERT INTO todos VALUES (?, ?, ?, ?, ?, ?)",
("first", "work", "", None, 0, 0),
)

tasks = get_all_todos()

assert [task.task for task in tasks] == ["first", "second"]
assert [task.position for task in tasks] == [0, 1]
2 changes: 1 addition & 1 deletion trushell/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def insert_todo(todo: Todo) -> None:

def get_all_todos() -> List[Todo]:
with get_db_connection() as conn:
results = conn.execute("SELECT * FROM todos").fetchall()
results = conn.execute("SELECT * FROM todos ORDER BY position").fetchall()
return [Todo(*result) for result in results]


Expand Down
Loading