Exemplo n.º 1
0
    def test_task_new(self):
        local_task_file = "task_new task.md"
        test_file = os.path.join(self.test_dir, local_task_file)
        due = datetime.datetime.strptime("2020-08-19", due_date_fmt)
        t = Task.new("a144", test_file, 4, due, 3, "todo", ["r21"])
        self.assertTrue(os.path.exists(test_file))
        self.assertEqual(t.dexid, "a144")
        self.assertEqual(t.effort, 4)
        self.assertEqual(t.importance, 3)
        self.assertEqual(t.status, "todo")
        self.assertListEqual(t.flags, ["r21"])
        ref_time = datetime.datetime.strptime("2020-08-19", due_date_fmt)
        self.assertTrue(ref_time == t.due)

        # test an existing file without a dexcode
        local_task_file = "task_without_dexcode.md"
        test_file = os.path.join(self.test_dir, local_task_file)
        t = Task.new("a145", test_file, 4, due, 2, "todo", ["r7"])
        with open(t.path, "r") as f:
            self.assertTrue(t.dexcode in f.read())
Exemplo n.º 2
0
    def create_new_task(self,
                        name: str,
                        effort: int,
                        due: datetime.datetime,
                        importance: int,
                        status: str,
                        flags: list,
                        edit_content: bool = False) -> Task:
        """
        Can be used non atomically. Arguments are mostly the same as for Task.

        Args:
            name (str): The name of the new task. Will be converted to a path by Project for use with Task.
            effort:
            due:
            importance:
            status:
            flags:
            edit_content:

        Returns:
            Task (the created task).
        """

        fname = name + task_extension
        path = os.path.join(os.path.join(self.path, tasks_subdir), fname)

        if status in (abandoned_str, done_str):
            raise DexException(
                "Cannot make a new task with an initially inactive status!")

        if path in [t.path for t in self.tasks.all]:
            raise FileOverwriteError(
                f"Task already exists with the name: {name}")

        all_task_numbers = [
            int(copy.deepcopy(t.dexid).replace(self.id, ""))
            for t in self._tasks
        ]
        max_task_numbers = max(all_task_numbers) if all_task_numbers else 0
        new_task_number = max_task_numbers + 1
        new_task_id = f"{self.id}{new_task_number}"
        t = Task.new(new_task_id,
                     path,
                     effort,
                     due,
                     importance,
                     status,
                     flags,
                     edit_content=edit_content)
        self._tasks.append(t)
        return t