Skip to content

Commit

Permalink
Add creation of task list instance with new file
Browse files Browse the repository at this point in the history
  • Loading branch information
meatballs committed Mar 17, 2020
1 parent 6d213cc commit 959da7f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions blockbuster/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class TaskList:
@classmethod
def from_file(cls, file):
task = cls(file=file)
file.touch()
task.read_file()
return task

Expand Down
13 changes: 12 additions & 1 deletion tests/test_tasklist.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# pylint: disable=protected-access, redefined-outer-name
from hashlib import sha256
from pathlib import Path

import blockbuster.core.model as model
from blockbuster.core import TASKS_ADDED, TASKS_DELETED, TASKS_UPDATED
from blockbuster.core.model import Event, Task, TaskList
Expand All @@ -8,14 +11,22 @@ def test_tasks_hash(test_tasks, test_tasks_hash):
assert model._tasks_hash(test_tasks) == test_tasks_hash


def test_from_file(test_file, test_tasks, test_tasks_hash):
def test_from_existing_file(test_file, test_tasks, test_tasks_hash):
task_list = TaskList.from_file(test_file)
assert len(task_list.tasks) == len(test_tasks)
for task in task_list.tasks:
assert isinstance(task, Task)
assert task_list.tasks_hash == test_tasks_hash


def test_from_new_file(tmp_path):
test_file = Path(tmp_path, "new_test_file")
task_list = TaskList.from_file(test_file)
assert test_file.exists()
assert task_list.tasks == []
assert task_list.tasks_hash == sha256("".encode("UTF-8")).hexdigest()


def test_add_tasks(additions, test_file, test_tasks):
task_list = TaskList.from_file(test_file)
event = task_list.add_tasks(additions)
Expand Down

0 comments on commit 959da7f

Please sign in to comment.