How to use the todoman.model.Database function in todoman

To help you get started, we’ve selected a few todoman examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pimutils / todoman / tests / test_model.py View on Github external
def test_retain_unknown_fields(tmpdir, create, default_database):
    """
    Test that we retain unknown fields after a load/save cycle.
    """
    create(
        'test.ics', 'UID:AVERYUNIQUEID\n'
        'SUMMARY:RAWR\n'
        'X-RAWR-TYPE:Reptar\n'
    )

    db = Database([tmpdir.join('default')], tmpdir.join('cache.sqlite'))
    todo = db.todo(1, read_only=False)

    todo.description = 'Rawr means "I love you" in dinosaur.'
    default_database.save(todo)

    path = tmpdir.join('default').join('test.ics')
    with path.open() as f:
        vtodo = f.read()
    lines = vtodo.splitlines()

    assert 'SUMMARY:RAWR' in lines
    assert 'DESCRIPTION:Rawr means "I love you" in dinosaur.' in lines
    assert 'X-RAWR-TYPE:Reptar' in lines
github pimutils / todoman / tests / test_model.py View on Github external
def test_list_colour_cache_invalidation(tmpdir, sleep):
    tmpdir.join('default').mkdir()
    with tmpdir.join('default').join('color').open('w') as f:
        f.write('#8ab6d2')

    db = Database([tmpdir.join('default')], tmpdir.join('cache.sqlite3'))
    list_ = next(db.lists())

    assert list_.colour == '#8ab6d2'

    sleep()

    with tmpdir.join('default').join('color').open('w') as f:
        f.write('#f874fd')

    db = Database([tmpdir.join('default')], tmpdir.join('cache.sqlite3'))
    list_ = next(db.lists())

    assert list_.colour == '#f874fd'
github pimutils / todoman / tests / test_model.py View on Github external
def test_change_paths(tmpdir, create):
    old_todos = set('abcdefghijk')
    for x in old_todos:
        create('{}.ics'.format(x), 'SUMMARY:{}\n'.format(x), x)

    tmpdir.mkdir('3')

    db = Database([tmpdir.join(x) for x in old_todos],
                  tmpdir.join('cache.sqlite'))

    assert {t.summary for t in db.todos()} == old_todos

    db.paths = [str(tmpdir.join('3'))]
    db.update_cache()

    assert len(list(db.lists())) == 1
    assert not list(db.todos())
github pimutils / todoman / tests / test_model.py View on Github external
def test_list_displayname(tmpdir):
    tmpdir.join('default').mkdir()
    with tmpdir.join('default').join('displayname').open('w') as f:
        f.write('personal')

    db = Database([tmpdir.join('default')], tmpdir.join('cache.sqlite3'))
    list_ = next(db.lists())

    assert list_.name == 'personal'
    assert str(list_) == 'personal'
github pimutils / todoman / tests / test_model.py View on Github external
def test_duplicate_list(tmpdir):
    tmpdir.join('personal1').mkdir()
    with tmpdir.join('personal1').join('displayname').open('w') as f:
        f.write('personal')

    tmpdir.join('personal2').mkdir()
    with tmpdir.join('personal2').join('displayname').open('w') as f:
        f.write('personal')

    with pytest.raises(AlreadyExists):
        Database(
            [tmpdir.join('personal1'),
             tmpdir.join('personal2')],
            tmpdir.join('cache.sqlite3'),
        )
github pimutils / todoman / tests / test_model.py View on Github external
def test_list_colour(tmpdir):
    tmpdir.join('default').mkdir()
    with tmpdir.join('default').join('color').open('w') as f:
        f.write('#8ab6d2')

    db = Database([tmpdir.join('default')], tmpdir.join('cache.sqlite3'))
    list_ = next(db.lists())

    assert list_.colour == '#8ab6d2'
github pimutils / todoman / tests / test_cli.py View on Github external
def test_default_priority(tmpdir, runner, create):
    """Test setting the due date using the default_due config parameter"""
    path = tmpdir.join('config')
    path.write('default_priority = 3\n', 'a')

    runner.invoke(cli, ['new', '-l', 'default', 'aaa'])
    db = Database([tmpdir.join('default')], tmpdir.join('/default_list'))
    todo = list(db.todos())[0]

    assert todo.priority == 3
github pimutils / todoman / tests / test_model.py View on Github external
def test_list_no_colour(tmpdir):
    tmpdir.join('default').mkdir()

    db = Database([tmpdir.join('default')], tmpdir.join('cache.sqlite3'))
    list_ = next(db.lists())

    assert list_.colour is None
github pimutils / todoman / tests / test_cli.py View on Github external
def test_dtstamp(tmpdir, runner, create):
    """Test that we add the DTSTAMP to new entries as per RFC5545."""
    result = runner.invoke(cli, ['new', '-l', 'default', 'test event'])
    assert not result.exception

    db = Database([tmpdir.join('default')], tmpdir.join('/dtstamp_cache'))
    todo = list(db.todos())[0]
    assert todo.dtstamp is not None
    assert todo.dtstamp == datetime.datetime.now(tz=tzlocal())
github pimutils / todoman / todoman / cli.py View on Github external
ctx.formatter_class = formatters.DefaultFormatter

        color = color or ctx.config['main']['color']
        if color == 'always':
            click_ctx.color = True
        elif color == 'never':
            click_ctx.color = False

        paths = [
            path for path in glob.iglob(expanduser(ctx.config["main"]["path"]))
            if isdir(path)
        ]
        if len(paths) == 0:
            raise exceptions.NoListsFound(ctx.config["main"]["path"])

        ctx.db = Database(paths, ctx.config['main']['cache_path'])

        # Make python actually use LC_TIME, or the user's locale settings
        locale.setlocale(locale.LC_TIME, "")