def test_complete_task_already_done():
    # FIXME: Student's task
    """
    If the task is already done, it should raise a:
        `TaskAlreadyDoneException`
    """
    tasks = [{
        'task': 'Email team updates',
        'description': 'Some more details',
        'due_on': datetime(2018, 3, 1, 9),
        'status': 'pending'
    }, {
        'task': 'Update project plan',
        'description': 'Important before investors meeting',
        'due_on': datetime(2018, 2, 28, 9),
        'status': 'done'
    }, {
        'task': 'Book conference room',
        'description': None,
        'due_on': datetime(2018, 3, 1, 8, 30),
        'status': 'pending'
    }]

    with pytest.raises(TaskAlreadyDoneException):
        todos.complete_task(tasks, 'Update project plan')
def test_complete_task_doesnt_exist_fails():
    # FIXME: Student's task
    """
    If the task doesn't exist (either name or position), it should raise:
        `TaskDoesntExistException`
    """
    tasks = []

    with pytest.raises(TaskDoesntExistException):
        todos.complete_task(tasks, 'DOES NOT EXIST')

    with pytest.raises(TaskDoesntExistException):
        todos.complete_task(tasks, '9')
Ejemplo n.º 3
0
def test_complete_task_doesnt_exist_fails_by_id():
    """
    If the task (provided by ID) doesn't exist it should raise:
        `TaskDoesntExistException`
    """
    tasks = [{
        'task': 'Email team updates',
        'description': 'Some more details',
        'due_on': datetime(2018, 3, 1, 9),
        'status': 'pending'
    }]

    with pytest.raises(TaskDoesntExistException):
        todos.complete_task(tasks, '9')
Ejemplo n.º 4
0
def complete(ctx, name):
    new_tasks = todos.complete_task(ctx.obj['json_data'], name)

    serialized = todos.serialize(new_tasks)
    with open(ctx.obj['data_file_path'], 'w') as fp:
        fp.write(_json_dumps(serialized))
    click.echo("Task {}. Done!".format(name))
def test_complete_task_by_name():
    tasks = [{
        'task': 'Email team updates',
        'description': 'Some more details',
        'due_on': datetime(2018, 3, 1, 9),
        'status': 'pending'
    }, {
        'task': 'Update project plan',
        'description': 'Important before investors meeting',
        'due_on': datetime(2018, 2, 28, 9),
        'status': 'done'
    }, {
        'task': 'Book conference room',
        'description': None,
        'due_on': datetime(2018, 3, 1, 8, 30),
        'status': 'pending'
    }]

    new_tasks = todos.complete_task(tasks, 'Email team updates')

    assert new_tasks == [
        {
            'task': 'Email team updates',
            'description': 'Some more details',
            'due_on': datetime(2018, 3, 1, 9),
            'status': 'done'  # Was updated
        },
        {
            'task': 'Update project plan',
            'description': 'Important before investors meeting',
            'due_on': datetime(2018, 2, 28, 9),
            'status': 'done'
        },
        {
            'task': 'Book conference room',
            'description': None,
            'due_on': datetime(2018, 3, 1, 8, 30),
            'status': 'pending'
        }
    ]

    # Original tasks were not changed
    assert tasks == [{
        'task': 'Email team updates',
        'description': 'Some more details',
        'due_on': datetime(2018, 3, 1, 9),
        'status': 'pending'
    }, {
        'task': 'Update project plan',
        'description': 'Important before investors meeting',
        'due_on': datetime(2018, 2, 28, 9),
        'status': 'done'
    }, {
        'task': 'Book conference room',
        'description': None,
        'due_on': datetime(2018, 3, 1, 8, 30),
        'status': 'pending'
    }]
Ejemplo n.º 6
0
def test_complete_task_by_id():
    """
    The task to complete can be given by either the name, or the order
    within the JSON file (starting from 1).
    """
    tasks = [{
        'task': 'Email team updates',
        'description': 'Some more details',
        'due_on': datetime(2018, 3, 1, 9),
        'status': 'pending'
    }, {
        'task': 'Update project plan',
        'description': 'Important before investors meeting',
        'due_on': datetime(2018, 2, 28, 9),
        'status': 'done'
    }, {
        'task': 'Book conference room',
        'description': None,
        'due_on': datetime(2018, 3, 1, 8, 30),
        'status': 'pending'
    }]

    new_tasks = todos.complete_task(tasks, "1")

    assert new_tasks == [{
        'task': 'Email team updates',
        'description': 'Some more details',
        'due_on': datetime(2018, 3, 1, 9),
        'status': 'done'  # Was updated
    }, {
        'task': 'Update project plan',
        'description': 'Important before investors meeting',
        'due_on': datetime(2018, 2, 28, 9),
        'status': 'done'
    }, {
        'task': 'Book conference room',
        'description': None,
        'due_on': datetime(2018, 3, 1, 8, 30),
        'status': 'pending'
    }]