예제 #1
0
def test_create_multiple_tasks():
    tasks = todos.new()

    todos.create_task(
        tasks, 'Email team updates',
        description='Some more details',
        due_on=datetime(2018, 3, 1, 9))

    assert tasks == [{
        'task': 'Email team updates',
        'description': 'Some more details',
        'due_on': datetime(2018, 3, 1, 9),
        'status': 'pending'
    }]

    todos.create_task(
        tasks, 'Update project plan',
        description='Important before investors meeting',
        due_on=datetime(2018, 3, 5, 9))

    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, 3, 5, 9),
        'status': 'pending'
    }]
예제 #2
0
def test_create_new_task_basic():
    tasks = todos.new()
    todos.create_task(tasks, 'Email team updates')

    assert tasks == [{
        'task': 'Email team updates',
        'description': None,
        'due_on': None,
        'status': 'pending'
    }]
예제 #3
0
def test_create_new_task_invalid_due_date():
    """
    If the date passed is invalid it should raise an:
        `InvalidTaskDueDateException`
    """
    tasks = todos.new()

    with pytest.raises(InvalidTaskDueDateException):
        todos.create_task(
            tasks, 'Email team updates',
            description='Some more details',
            due_on='not-a-datetime-object')
예제 #4
0
def test_create_new_task_with_description():
    tasks = todos.new()

    todos.create_task(
        tasks, 'Email team updates',
        description='Some more details')

    assert tasks == [{
        'task': 'Email team updates',
        'description': 'Some more details',
        'due_on': None,
        'status': 'pending'
    }]
예제 #5
0
def test_create_new_task_due_date_string_date():
    tasks = todos.new()

    todos.create_task(
        tasks, 'Email team updates',
        description='Some more details',
        due_on='2018-03-01')

    assert tasks == [{
        'task': 'Email team updates',
        'description': 'Some more details',
        'due_on': datetime(2018, 3, 1),  # datetime object automatically added
        'status': 'pending'
    }]
예제 #6
0
def test_create_new_task_with_description_and_due_date():
    tasks = todos.new()

    todos.create_task(
        tasks, 'Email team updates',
        description='Some more details',
        due_on=datetime(2018, 3, 1, 9))

    assert tasks == [{
        'task': 'Email team updates',
        'description': 'Some more details',
        'due_on': datetime(2018, 3, 1, 9),
        'status': 'pending'
    }]
예제 #7
0
def cli(ctx, debug, indent, data_file):
    ctx.obj['debug'] = debug
    ctx.obj['indent'] = indent
    _debug('Debug mode is %s' % ('on' if debug else 'off'))

    data_file_path = os.path.abspath(data_file)
    ctx.obj['data_file'] = data_file
    ctx.obj['data_file_path'] = data_file_path

    if not os.path.exists(data_file_path):
        with open(data_file_path, 'w') as fp:
            _debug('Task file created: {}'.format(data_file_path))
            tasks = todos.new()
            fp.write(_json_dumps(tasks))
    elif os.path.isdir(data_file_path):
        ctx.fail('Data file {} is a directory'.format(data_file))

    with open(data_file_path, 'r') as fp:
        # Task 1: Check the format of file and prevent:
        # json.decoder.JSONDecodeError
        ctx.obj['json_data'] = todos.unserialize(fp.read())
        _debug('Read tasks from task file {}'.format(data_file_path))
예제 #8
0
def test_create_todos_template():
    tasks = todos.new()
    assert tasks == []