def test_sorting_fields(tmpdir, runner, default_database): tasks = [] for i in range(1, 10): days = datetime.timedelta(days=i) todo = Todo() 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 = tuple(field for field in dir(Todo) if not field.startswith('_')) @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_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()
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()