Exemplo n.º 1
0
Arquivo: cli.py Projeto: hut/todoman
def new(ctx, summary, list, todo_properties, read_description, interactive):
    '''
    Create a new task with SUMMARY.
    '''

    todo = Todo(new=True, list=list)

    default_due = ctx.config['main']['default_due']
    if default_due:
        todo.due = todo.created_at + timedelta(hours=default_due)

    for key, value in todo_properties.items():
        if value:
            setattr(todo, key, value)
    todo.summary = ' '.join(summary)

    if read_description:
        todo.description = '\n'.join(sys.stdin)

    if interactive or (not summary and interactive is None):
        ui = TodoEditor(todo, ctx.db.lists(), ctx.ui_formatter)
        ui.edit()
        click.echo()  # work around lines going missing after urwid

    if not todo.summary:
        raise click.UsageError('No SUMMARY specified')

    ctx.db.save(todo)
    click.echo(ctx.formatter.detailed(todo))
Exemplo n.º 2
0
def test_filename_uid_colision(create, default_database, runner, todos):
    create("ABC.ics", "SUMMARY:My UID is not ABC\nUID:NOTABC\n")
    assert len(list(todos())) == 1

    todo = Todo(new=False)
    todo.uid = "ABC"
    todo.list = next(default_database.lists())
    default_database.save(todo)

    assert len(list(todos())) == 2
Exemplo n.º 3
0
def test_filename_uid_colision(create, default_database, runner, todos):
    create('ABC.ics', 'SUMMARY:My UID is not ABC\n' 'UID:NOTABC\n')
    len(list(todos())) == 1

    todo = Todo(new=False)
    todo.uid = 'ABC'
    todo.list = next(default_database.lists())
    default_database.save(todo)

    len(list(todos())) == 2
Exemplo n.º 4
0
def test_edit(runner, default_database, todos):
    todo = Todo(new=True)
    todo.list = next(default_database.lists())
    todo.summary = 'Eat paint'
    todo.due = datetime.datetime(2016, 10, 3)
    default_database.save(todo)

    result = runner.invoke(cli, ['edit', '1', '--due', '2017-02-01'])
    assert not result.exception
    assert '2017-02-01' in result.output

    todo = next(todos(status='ANY'))
    assert todo.due == datetime.datetime(2017, 2, 1, tzinfo=tzlocal())
    assert todo.summary == 'Eat paint'
Exemplo n.º 5
0
def test_edit(runner, default_database, todos):
    todo = Todo(new=True)
    todo.list = next(default_database.lists())
    todo.summary = "Eat paint"
    todo.due = datetime.datetime(2016, 10, 3)
    default_database.save(todo)

    result = runner.invoke(cli, ["edit", "1", "--due", "2017-02-01"])
    assert not result.exception
    assert "2017-02-01" in result.output

    todo = next(todos(status="ANY"))
    assert todo.due == datetime.datetime(2017, 2, 1, tzinfo=tzlocal())
    assert todo.summary == "Eat paint"
Exemplo n.º 6
0
def test_is_completed():
    completed_at = datetime(2017, 3, 19, 14, tzinfo=pytz.UTC)

    todo = Todo()
    assert todo.is_completed is False

    todo.completed_at = completed_at
    assert todo.is_completed is True

    todo.percent_complete = 20
    todo.complete()
    assert todo.is_completed is True
    assert todo.completed_at == datetime.now(pytz.UTC)
    assert todo.percent_complete == 100
    assert todo.status == "COMPLETED"
Exemplo n.º 7
0
def test_sorting_fields(tmpdir, runner, default_database):
    tasks = []
    for i in range(1, 10):
        days = datetime.timedelta(days=i)

        todo = Todo(new=True)
        todo.list = next(default_database.lists())
        todo.due = datetime.datetime.now() + days
        todo.created_at = datetime.datetime.now() - days
        todo.summary = 'harhar{}'.format(i)
        tasks.append(todo)

        default_database.save(todo)

    fields = (
        'id',
        'uid',
        'summary',
        'due',
        'priority',
        'created_at',
        'completed_at',
        'dtstamp',
        'status',
        'description',
        'location',
        'categories',
    )

    @given(
        sort_key=st.lists(
            st.sampled_from(fields + tuple('-' + x for x in fields)),
            unique=True
        )
    )
    def run_test(sort_key):
        sort_key = ','.join(sort_key)
        result = runner.invoke(cli, ['list', '--sort', sort_key])
        assert not result.exception
        assert result.exit_code == 0
        assert len(result.output.strip().splitlines()) == len(tasks)

    run_test()
Exemplo n.º 8
0
def test_due_aware(tmpdir, runner, create, now_for_tz):
    db = Database([tmpdir.join('default')], tmpdir.join('cache.sqlite'))
    l = next(db.lists())

    for tz in ['CET', 'HST']:
        for i in [1, 23, 25, 48]:
            todo = Todo(new=True)
            todo.due = now_for_tz(tz) + timedelta(hours=i)
            todo.summary = '{}'.format(i)

            todo.list = l
            db.save(todo)

    todos = list(db.todos(due=24))

    assert len(todos) == 4
    assert todos[0].summary == "23"
    assert todos[1].summary == "23"
    assert todos[2].summary == "1"
    assert todos[3].summary == "1"
Exemplo n.º 9
0
def test_clone():
    now = datetime.now(tz=tzlocal())

    todo = Todo(new=True)
    todo.summary = "Organize a party"
    todo.location = "Home"
    todo.due = now
    todo.uid = "123"
    todo.id = "123"
    todo.filename = "123.ics"

    clone = todo.clone()

    assert todo.summary == clone.summary
    assert todo.location == clone.location
    assert todo.due == clone.due
    assert todo.uid != clone.uid
    assert len(clone.uid) > 32
    assert clone.id is None
    assert todo.filename != clone.filename
    assert clone.uid in clone.filename
Exemplo n.º 10
0
def test_sorting_fields(tmpdir, runner, default_database):
    tasks = []
    for i in range(1, 10):
        days = datetime.timedelta(days=i)

        todo = Todo(new=True)
        todo.list = next(default_database.lists())
        todo.due = datetime.datetime.now() + days
        todo.created_at = datetime.datetime.now() - days
        todo.summary = "harhar{}".format(i)
        tasks.append(todo)

        default_database.save(todo)

    fields = (
        "id",
        "uid",
        "summary",
        "due",
        "priority",
        "created_at",
        "completed_at",
        "dtstamp",
        "status",
        "description",
        "location",
        "categories",
    )

    @given(sort_key=st.lists(st.sampled_from(fields + tuple("-" + x
                                                            for x in fields)),
                             unique=True))
    def run_test(sort_key):
        sort_key = ",".join(sort_key)
        result = runner.invoke(cli, ["list", "--sort", sort_key])
        assert not result.exception
        assert result.exit_code == 0
        assert len(result.output.strip().splitlines()) == len(tasks)

    run_test()
Exemplo n.º 11
0
def test_is_completed():
    completed_at = datetime(2017, 3, 19, 14, tzinfo=pytz.UTC),

    todo = Todo()
    todo.completed_at = completed_at
    todo.percent_complete = 20

    todo.is_completed = True
    assert todo.completed_at == completed_at
    assert todo.percent_complete == 100
    assert todo.status == 'COMPLETED'

    todo.is_completed = False
    assert todo.completed_at is None
    assert todo.percent_complete == 0
    assert todo.status == 'NEEDS-ACTION'

    todo.is_completed = True
    now = datetime(2017, 3, 19, 15, tzinfo=pytz.UTC).astimezone(tzlocal())
    assert todo.completed_at == now
    assert todo.percent_complete == 100
    assert todo.status == 'COMPLETED'
Exemplo n.º 12
0
def test_todo_filename_absolute_path():
    Todo(filename="test.ics")
    with pytest.raises(ValueError):
        Todo(filename="/test.ics")