Beispiel #1
0
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)
Beispiel #2
0
    def test_repository_doesnt_add_entities_equal_to_cache_ones(
        self,
        repo: Repository,
        entity: Entity,
        caplog: LogCaptureFixture,
        merge: bool,
    ) -> None:
        """
        Given: A repository with an entity in the cache
        When: Adding the same entity
        Then: The entity is not added to the staged entities

        This way we save database calls for things that haven't changed.
        """
        caplog.set_level(logging.DEBUG)
        repo.cache.add(entity)

        repo.add(entity, merge=merge)  # act

        assert (
            "repository_orm.adapters.data.abstract",
            logging.DEBUG,
            f"Skipping the addition of entity {entity} as it hasn't changed",
        ) in caplog.record_tuples
    def test_repository_can_save_two_entities_without_id_full_repo(
            self, repo: Repository, inserted_int_entity: Entity,
            merge: bool) -> None:
        """
        Given: A repository with an entity whose id_ type is an int
        When: adding two entities without id
        Then: the id of the new entities is one unit greater than the last one.
        """
        first_entity = inserted_int_entity.__class__(
            name="First entity without id")
        second_entity = inserted_int_entity.__class__(
            name="Second entity without id")
        repo.add([first_entity, second_entity], merge=merge)

        repo.commit()  # act

        entities = repo.all(type(inserted_int_entity))
        assert len(entities) == 3
        # ignore: we know that the entities have an int id_
        assert entities[1].id_ == inserted_int_entity.id_ + 1  # type: ignore
        assert entities[1].name == "First entity without id"
        # ignore: we know that the entities have an int id_
        assert entities[2].id_ == inserted_int_entity.id_ + 2  # type: ignore
        assert entities[2].name == "Second entity without id"
Beispiel #4
0
    def test_repository_can_save_an_entity_without_id_in_empty_repo(
        self,
        repo: Repository,
        int_entity: Entity,
        merge: bool,
    ) -> None:
        """
        Given: An empty repository and an entity whose id_ type is an int
        When: adding an entity without id
        Then: the id 0 is set
        """
        entity = int_entity.__class__(name="Entity without id")
        added_entity = repo.add(entity, merge=merge)

        repo.commit()  # act

        entities = repo.all(type(entity))
        assert len(entities) == 1
        assert added_entity.id_ == 0
        assert entities[0].id_ == 0
Beispiel #5
0
def _close_task(
    repo: Repository,
    task: Task,
    state: TaskState,
    close_date_str: str = "now",
    delete_parent: bool = False,
) -> None:
    """Close a task.

    It gathers the common actions required to complete or delete tasks.
    """
    close_date = convert_date(close_date_str)

    task.close(state, close_date)

    repo.add(task)

    # If it's a child task of another task
    if task.parent_id is not None:
        log.info(
            f"Closing child task {task.id_}: {task.description} with state {state}"
        )
        parent_task = repo.get(task.parent_id, [Task, RecurrentTask])
        # If we want to close the parent of the task.
        if delete_parent:
            parent_task.close(state, close_date)
            repo.add(parent_task)
            log.info(
                f"Closing parent task {parent_task.id_}: {parent_task.description} with"
                f" state {state}")
        # If it's a child task of a recurrent one, we need to spawn the next child.
        elif isinstance(parent_task, RecurrentTask):
            new_child_task = parent_task.breed_children(task)
            repo.add(new_child_task)
            log.info(
                f"Added child task {new_child_task.id_}: {new_child_task.description}",
            )
    # If it's a simple task
    else:
        log.info(
            f"Closing task {task.id_}: {task.description} with state {state}")
        if delete_parent:
            log.info(f"Task {task.id_} doesn't have a parent")
Beispiel #6
0
def insert_task_e2e(repo_e2e: Repository) -> Task:
    """Insert a task in the end to end repository."""
    task = factories.TaskFactory.create(state="backlog")
    repo_e2e.add(task)
    repo_e2e.commit()
    return task