def test_print_report_report_allows_sorting( self, runner: CliRunner, repo_e2e: Repository, faker: Faker, ) -> None: """ Given: Three tasks When: printing the open report sorting first by ascending priority, and then by descending id. Then: The tasks are printed in the desired order """ tasks = [ Task(id_=0, description="Last", priority=3), Task(id_=1, description="Middle", priority=3), Task(id_=2, description="First", priority=1), ] for task in tasks: repo_e2e.add(task) repo_e2e.commit() expected_output = [ r".*", r" +ID +│ +Description +│ +Pri.*", r".*", fr" +{tasks[2].id_} +│ +{tasks[2].description} +│ +{tasks[2].priority}.*", fr" +{tasks[1].id_} +│ +{tasks[1].description} +│ +{tasks[1].priority}.*", fr" +{tasks[0].id_} +│ +{tasks[0].description} +│ +{tasks[0].priority}.*", r".*", ] result = runner.invoke(cli, ["report", "open", "sort:+priority,-id_"]) assert result.exit_code == 0 assert report_prints_expected(result.stdout, expected_output, result.stderr)
def test_task_closing(open_task: Task) -> None: """ Given: An open task When: The close method is called Then: The current date is registered and the state is transitioned to closed. """ now = datetime.now() open_task.close() # act assert open_task.state == "done" assert open_task.active is False assert open_task.closed == now
def test_sort_accepts_one_argument_defaults_ascending(self) -> None: """ Given: Three tasks with different priority When: sort is called with priority Then: The tasks are returned ordered by ascending priority order """ tasks = [ Task(id_=0, priority=4), Task(id_=1, priority=1), Task(id_=2, priority=5), ] result = views.sort_tasks(tasks.copy(), ["priority"]) assert result == [tasks[1], tasks[0], tasks[2]]
def test_print_open_report( self, runner: CliRunner, repo_e2e: Repository, faker: Faker, ) -> None: """Test that open returns the expected output.""" task = Task(description="Description", due=faker.date_time(), priority=3) repo_e2e.add(task) repo_e2e.commit() expected_output = [ r".*", r" +ID +│ +Description +│ +Pri.*", r".*", fr" +{task.id_} +│ +{task.description} +│ +{task.priority}.*", r".*", ] result = runner.invoke(cli, ["open"]) assert result.exit_code == 0 assert report_prints_expected(result.stdout, expected_output, result.stderr)
def test_sort_accepts_two_argument_one_ascending_other_descending(self) -> None: """ Given: Three tasks with different priority and id When: sort is called with +priority, -id_ Then: The tasks are returned ordered by increasing priority order, and then by decreasing id_ """ tasks = [ Task(id_=2, priority=4), Task(id_=0, priority=4), Task(id_=1, priority=1), ] result = views.sort_tasks(tasks.copy(), ["priority", "-id_"]) assert result == [tasks[2], tasks[0], tasks[1]]
def test_print_closed_report(self, runner: CliRunner, repo_e2e: Repository, insert_tasks_e2e: List[Task]) -> None: """Test that closed returns the expected output.""" task = Task(description="Description", priority=3) task.close() repo_e2e.add(task) repo_e2e.commit() expected_output = [ r".*", r" +ID +│ +Description +│ +Pri.*", r".*", fr" +{task.id_} +│ +{task.description} +│ +{task.priority}.*", r".*", ] result = runner.invoke(cli, ["closed"]) assert result.exit_code == 0 assert report_prints_expected(result.stdout, expected_output, result.stderr)
def test_print_report_report_allows_sorting_by_config( self, runner: CliRunner, repo_e2e: Repository, faker: Faker, config: Config, ) -> None: """ Given: Three tasks and the configuration report with the sorting criteria of first sorting by ascending priority, and then by descending id. When: printing the open report Then: The tasks are printed in the desired order """ tasks = [ Task(id_=0, description="Last", priority=3), Task(id_=1, description="Middle", priority=3), Task(id_=2, description="First", priority=1), ] for task in tasks: repo_e2e.add(task) repo_e2e.commit() config.set("reports.task_reports.open.sort", ["+priority", "-id_"]) config.save() expected_output = [ r".*", r" +ID +│ +Description +│ +Pri.*", r".*", fr" +{tasks[2].id_} +│ +{tasks[2].description} +│ +{tasks[2].priority}.*", fr" +{tasks[1].id_} +│ +{tasks[1].description} +│ +{tasks[1].priority}.*", fr" +{tasks[0].id_} +│ +{tasks[0].description} +│ +{tasks[0].priority}.*", r".*", ] result = runner.invoke(cli, ["report", "open"]) assert result.exit_code == 0 assert report_prints_expected(result.stdout, expected_output, result.stderr)
def test_print_core_reports(self, runner: CliRunner, repo_e2e: Repository, insert_tasks_e2e: List[Task]) -> None: """Test that report is able to print the core reports. These reports come by default with pydo. """ task = Task(description="Description", priority=3) task.close() repo_e2e.add(task) repo_e2e.commit() expected_output = [ r".*", r" +ID +│ +Description +│ +Pri.*", r".*", fr" +{task.id_} +│ +{task.description} +│ +{task.priority}.*", r".*", ] result = runner.invoke(cli, ["report", "closed"]) assert result.exit_code == 0 assert report_prints_expected(result.stdout, expected_output, result.stderr)
def test_raise_error_if_add_task_assigns_unvalid_agile_state( task_attributes: Dict[str, str], faker: Faker) -> None: """ Given: Nothing When: A Task is initialized with an invalid agile state Then: ValueError is raised """ task_attributes["state"] = faker.word() with pytest.raises( ValidationError, match= "value is not a valid enumeration member; permitted: 'backlog'", ): Task(**task_attributes)
def test_task_report_prints_task_attributes( repo: Repository, config: Config, capsys: CaptureFixture[Any], faker: Faker ) -> None: """Test that the open report prints the task attributes.""" task = Task(description="Description", due=faker.date_time(), priority=3) repo.add(task) repo.commit() expected_output = [ r".*", r" +ID +│ +Description +│ +Pri.*", r".*", fr" +{task.id_} +│ +{task.description} +│ +{task.priority}.*", r".*", ] out, err = run_report( "print_task_report", {"repo": repo, "config": config, "report_name": "open"}, capsys, ) # act assert report_prints_expected(out, expected_output, err)
def test_task_report_allows_task_filter( repo: Repository, config: Config, insert_multiple_tasks: List[Task], capsys: CaptureFixture[Any], ) -> None: """ Given: Many tasks and only one matches a criteria When: The open report is called with that criteria Then: Only one task is shown """ task = factories.TaskFactory.create(area="special_area") task = Task(description="Description", area="special_area") repo.add(task) repo.commit() task_selector = TaskSelector(task_filter={"area": "special_area"}) expected_output = [ r".*", r" +ID +│ +Description +│ +Area .*", r".*", fr" +{task.id_} +│ +{task.description} +│ +{task.area}.*", r".*", ] out, err = run_report( "print_task_report", { "repo": repo, "config": config, "report_name": "open", "task_selector": task_selector, }, capsys, ) # act assert report_prints_expected(out, expected_output, err)