Example #1
0
def test_memory_task_repository_delete_not_found(
        memory_task_repository: MemoryTaskRepository) -> None:
    task = Task("Fix my bike")
    task.uid = 'T-MISSING'
    with raises(EntityNotFoundError):
        memory_task_repository.delete(task)
    assert len(memory_task_repository.tasks) == 3
Example #2
0
def test_memory_task_repository_add_with_uid(
        memory_task_repository: MemoryTaskRepository) -> None:
    task = Task("Improve the repository")
    task.uid = "ABC123"
    memory_task_repository.add(task)
    assert len(memory_task_repository.tasks) == 4
    assert memory_task_repository.tasks['ABC123'] == task
    assert memory_task_repository.sequence == 5
Example #3
0
def test_memory_task_repository_update(
        memory_task_repository: MemoryTaskRepository) -> None:
    task = Task("Buy the milk and the eggs")
    task.uid = 'T-1'
    assert memory_task_repository.tasks['T-1'].name == "Buy the milk"
    memory_task_repository.update(task)
    assert len(memory_task_repository.tasks) == 3
    assert memory_task_repository.tasks['T-1'].name == (
        "Buy the milk and the eggs")
Example #4
0
def test_json_task_repository_delete_not_found(
        json_task_repository: JsonTaskRepository) -> None:
    task = Task("Fix my bike")
    task.uid = 'T-MISSING'
    with raises(EntityNotFoundError):
        json_task_repository.delete(task)
    with open(json_task_repository.filename, 'r') as f:
        data = json.load(f)
    assert len(data['tasks']) == 3
Example #5
0
def memory_task_repository() -> MemoryTaskRepository:
    memory_task_repository = MemoryTaskRepository()
    tasks_dict = {
        'T-1': Task("Buy the milk"),
        'T-2': Task("Make conference presentation"),
        'T-3': Task("Clean the kitchen")
    }
    memory_task_repository.sequence = 4
    memory_task_repository.load(tasks_dict)
    return memory_task_repository
def task_repository() -> MemoryTaskRepository:
    task_repository = MemoryTaskRepository()
    tasks_dict = {
        'T-1': Task("Buy the milk", uid="T-1"),
        'T-2': Task("Make conference presentation", uid="T-2"),
        'T-3': Task("Clean the kitchen", uid="T-3")
    }
    task_repository.sequence = 4
    task_repository.load(tasks_dict)
    return task_repository
Example #7
0
def test_json_task_repository_add_with_uid(
        json_task_repository: JsonTaskRepository) -> None:
    task = Task("General")
    task.uid = "ABC123"
    json_task_repository.add(task)
    with open(json_task_repository.filename, 'r') as f:
        data = json.load(f)
    assert len(data['tasks']) == 4
    assert data['tasks']['ABC123']['uid'] == task.uid
    assert data['tasks']['ABC123']['name'] == task.name
    assert data['_sequences']['tasks'] == 5
Example #8
0
def test_json_task_repository_update(
        json_task_repository: JsonTaskRepository) -> None:
    task = Task("Buy the milk and eggs")
    task.uid = 'T-1'
    with open(json_task_repository.filename, 'r') as f:
        data = json.load(f)
    assert data['tasks']['T-1']['name'] == "Buy the milk"
    json_task_repository.update(task)
    with open(json_task_repository.filename, 'r') as f:
        data = json.load(f)
    assert len(data['tasks']) == 3
    assert data['tasks']['T-1']['name'] == "Buy the milk and eggs"
Example #9
0
    def create_task(self, task_dict: Dict[str, any]):
        project_id = task_dict.get('project_id')
        # Validate that the project exists
        self.project_repository.get(project_id)

        # Intantiate a Task object
        task = Task(**task_dict)

        # Set the task stage to 'New'
        task.stage = 'New'

        # Add the new task to the task repository
        self.task_repository.add(task)
Example #10
0
def test_memory_task_repository_add(
        memory_task_repository: MemoryTaskRepository) -> None:
    task = Task("Improve the repository")
    memory_task_repository.add(task)
    assert len(memory_task_repository.tasks) == 4
    assert memory_task_repository.tasks['T-4'] == task
    assert memory_task_repository.sequence == 5
Example #11
0
 def update_task(self, task_dict: Dict[str, any]):
     uid = task_dict.get('uid')
     old_task = self.task_repository.get(uid)
     old_task_dict = vars(old_task)
     old_task_dict.update(task_dict)
     new_task = Task(**old_task_dict)
     self.task_repository.update(new_task)
Example #12
0
 def get(self, uid: str) -> Task:
     with open(self.filename) as f:
         data = json.load(f)
         tasks = data.get('tasks', {})
     task_dict = tasks.get(uid)
     if not task_dict:
         raise EntityNotFoundError("The task was not found in file.")
     return Task(**task_dict)
Example #13
0
 def add(self, task: Task) -> None:
     with open(self.filename, 'r') as f:
         data = json.load(f)
     sequence = data.get('_sequences', {}).get('tasks', 1)
     task.uid = task.uid or ("T-" + str(sequence))
     data['tasks'][task.uid] = vars(task)
     data['_sequences']['tasks'] = sequence + 1
     with open(self.filename, 'w') as f:
         json.dump(data, f, default=json_serialize)
Example #14
0
def test_json_task_repository_add(
        json_task_repository: JsonTaskRepository) -> None:
    task = Task("Organize my documents")
    json_task_repository.add(task)
    with open(json_task_repository.filename, 'r') as f:
        data = json.load(f)
    assert len(data['tasks']) == 4
    assert data['tasks']['T-4']['uid'] == task.uid
    assert data['tasks']['T-4']['name'] == task.name
    assert data['_sequences']['tasks'] == 5
Example #15
0
def test_json_task_repository_delete(
        json_task_repository: JsonTaskRepository) -> None:
    with open(json_task_repository.filename, 'r') as f:
        data = json.load(f)
    task_dict = data['tasks']['T-1']
    task = Task(**task_dict)
    json_task_repository.delete(task)
    with open(json_task_repository.filename, 'r') as f:
        data = json.load(f)
    assert len(data['tasks']) == 2
    assert 'T-1' not in data['tasks']
Example #16
0
def json_file(tmpdir_factory):
    file_name = tmpdir_factory.mktemp('data').join('taskit.json')
    test_dictionary = {
        "projects": {
            'P-1': vars(Project("Personal", uid="P-1")),
            'P-2': vars(Project("Work", uid="P-2")),
            'P-3': vars(Project("Errands", uid="P-3"))
        },
        "tasks": {
            'T-1': vars(Task("Buy the milk",
                             uid="T-1", project_id="P-1", stage="New")),
            'T-2': vars(Task("Make conference presentation",
                             uid="T-2", project_id="P-2", stage="Progress")),
            'T-3': vars(Task("Clean the kitchen",
                             uid="T-3", project_id="P-1", stage="Done"))
        },
        "_sequences": {
            "projects": 4,
            "tasks": 4
        }
    }
    with open(str(file_name), 'w+') as f:
        json.dump(test_dictionary, f, default=json_serialize)
    return str(file_name)
def test_task_initilization_from_dict():
    now = datetime.now()
    task_dict = {
        'name': "Go to the gym",
        'uid': "T-007",
        'due_date': now,
        'priority': 3,
        'project_id': "P-001",
        'stage': "Draft",
        'comments': "Don't hesitate. Do it!"
    }
    task = Task(**task_dict)
    assert task.name == "Go to the gym"
    assert task.uid == "T-007"
    assert task.due_date == now
    assert task.priority == 3
    assert task.project_id == "P-001"
    assert task.stage == "Draft"
    assert task.comments == "Don't hesitate. Do it!"
 def add(self, task: Task) -> None:
     task.uid = task.uid or ("T-" + str(self.sequence))
     self.tasks[task.uid] = task
     self.sequence += 1
def task() -> Task:
    name = "Buy the milk"
    return Task(name=name)
Example #20
0
def test_memory_task_repository_load() -> None:
    memory_task_repository = MemoryTaskRepository()
    tasks_dict = {'T-1': Task("Buy the milk")}
    memory_task_repository.load(tasks_dict)
    assert memory_task_repository.tasks == tasks_dict