def test_edit(runner, default_database): todo = FileTodo() todo.list = next(default_database.lists()) todo.summary = 'Eat paint' todo.due = datetime.datetime(2016, 10, 3) todo.save() result = runner.invoke(cli, ['edit', '1', '--due', '2017-02-01']) assert not result.exception assert '2017-02-01' in result.output default_database.update_cache() todo = next(default_database.todos(all=True)) assert todo.due == datetime.datetime(2017, 2, 1, tzinfo=tzlocal()) assert todo.summary == 'Eat paint'
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 = FileTodo() todo.due = now_for_tz(tz) + timedelta(hours=i) todo.summary = '{}'.format(i) db.save(todo, l) 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"
def test_sorting_fields(tmpdir, runner, default_database): tasks = [] for i in range(1, 10): days = datetime.timedelta(days=i) todo = FileTodo(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) todo.save() 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()
def test_due_aware(tmpdir, runner, create): now = datetime.now() 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 = FileTodo() todo.due = (now + timedelta(hours=i)).replace(tzinfo=tzlocal()) \ .astimezone(pytz.timezone(tz)) todo.summary = '{}'.format(i) db.save(todo, l) 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"