Exemplo n.º 1
0
    def test_modify_task_modifies_task_attributes(
        self,
        repo: FakeRepository,
        faker: Faker,
        task: Task,
        caplog: LogCaptureFixture,
    ) -> None:
        """
        Given: An existent task.
        When: Using modify_task to modify the description.
        Then: The description is modified.
        """
        now = datetime.now()
        description = faker.sentence()
        selector = TaskSelector(task_ids=[task.id_])
        change = TaskChanges(task_attributes={"description": description}, )

        services.modify_tasks(repo, selector, change)  # act

        modified_task = repo.get(task.id_, [Task])
        assert modified_task.description == description
        assert (modified_task.modified - now).total_seconds() < 2
        assert (
            "pydo.services",
            logging.INFO,
            f"Modified task {task.id_}.",
        ) in caplog.record_tuples
Exemplo n.º 2
0
    def test_modify_child_task_parent_notifies_orphan_if_no_parent(
        self,
        repo: FakeRepository,
        task: Task,
        caplog: LogCaptureFixture,
        faker: Faker,
    ) -> None:
        """
        Given: A task without parent
        When: modifying the task with modify_parent = True
        Then: A warning is shown that the task has no parent.
        """
        selector = TaskSelector(task_ids=[task.id_])
        description = faker.sentence()
        change = TaskChanges(task_attributes={"description": description})

        services.modify_tasks(repo, selector, change,
                              modify_parent=True)  # act

        modified_task = repo.get(task.id_, [Task])
        assert modified_task.description == description
        assert (
            "pydo.services",
            logging.WARNING,
            f"Task {task.id_} doesn't have a parent task.",
        ) in caplog.record_tuples
Exemplo n.º 3
0
    def test_modify_task_adds_tags(self, repo: FakeRepository, task: Task,
                                   faker: Faker) -> None:
        """
        Given: A task without tags
        When: modifying it to add a tag
        Then: the tags are added
        """
        selector = TaskSelector(task_ids=[task.id_])
        tag = faker.word()
        change = TaskChanges(tags_to_add=[tag])

        services.modify_tasks(repo, selector, change)  # act

        modified_task = repo.get(task.id_, [Task])
        assert modified_task.tags == [tag]
Exemplo n.º 4
0
    def test_modify_doesnt_change_task_if_change_changes_nothing(
            self, repo: FakeRepository, task: Task, caplog: LogCaptureFixture,
            faker: Faker) -> None:
        """
        Given: A task
        When: modifying it's description to the same value
        Then: The modified task log message is not shown
        """
        selector = TaskSelector(task_ids=[task.id_])
        change = TaskChanges(task_attributes={"description": task.description})

        services.modify_tasks(repo, selector, change)  # act

        assert (
            "pydo.services",
            logging.INFO,
            f"Modified task {task.id_}.",
        ) not in caplog.record_tuples
Exemplo n.º 5
0
    def test_modify_task_removes_tags(self, repo: FakeRepository, task: Task,
                                      faker: Faker) -> None:
        """
        Given: A task with a tag
        When: modifying it to remove the tag
        Then: the tags are removed, but the rest of the properties are kept.
        """
        tag = faker.word()
        selector = TaskSelector(task_ids=[task.id_])
        change = TaskChanges(tags_to_add=[tag])
        services.modify_tasks(repo, selector, change)
        change = TaskChanges(tags_to_remove=[tag])

        services.modify_tasks(repo, selector, change)  # act

        modified_task = repo.get(task.id_, [Task])
        assert modified_task.tags == []
        assert modified_task.description == task.description
Exemplo n.º 6
0
    def test_modify_raises_error_if_task_not_found(
            self, repo: FakeRepository, faker: Faker, task: Task,
            caplog: LogCaptureFixture) -> None:
        """
        Given: An inexistent task
        When: Using modify_tasks on an that task
        Then: An error is raised
        """
        selector = TaskSelector(task_ids=[9999999])
        change = TaskChanges(task_attributes={"description":
                                              faker.sentence()}, )

        with pytest.raises(
                EntityNotFoundError,
                match=
                "There are no entities of type Task in the repository with id",
        ):
            services.modify_tasks(repo, selector, change)  # act
Exemplo n.º 7
0
    def test_modify_task_warns_if_task_doesnt_have_any_tag(
            self, repo: FakeRepository, task: Task, caplog: LogCaptureFixture,
            faker: Faker) -> None:
        """
        Given: A task without a tag
        When: modifying it to remove the tag
        Then: A warning is shown that the task doesn't have any tag to remove
        """
        selector = TaskSelector(task_ids=[task.id_])
        tag = faker.word()
        change = TaskChanges(tags_to_remove=[tag])

        services.modify_tasks(repo, selector, change)  # act

        assert (
            "pydo.services",
            logging.WARNING,
            f"Task {task.id_} doesn't have the tag {tag} assigned.",
        ) in caplog.record_tuples
Exemplo n.º 8
0
    def test_modify_task_modifies_parent_attributes(
        self,
        repo: FakeRepository,
        caplog: LogCaptureFixture,
        faker: Faker,
        insert_parent_task: Tuple[RecurrentTask, Task],
    ) -> None:
        """
        Given: A recurrent task and it's child
        When: modifying the child with modify_parent = True
        Then: Both parent and child attributes are changed.
        """
        parent_task, child_task = insert_parent_task
        selector = TaskSelector(task_ids=[child_task.id_])
        description = faker.sentence()
        change = TaskChanges(task_attributes={"description": description})

        services.modify_tasks(repo, selector, change,
                              modify_parent=True)  # act

        modified_child_task = repo.get(child_task.id_, [Task])
        modified_parent_task = repo.get(parent_task.id_, [RecurrentTask])
        assert modified_child_task.description == description
        assert modified_parent_task.description == description