def test_task(self) -> None: """Ensure tasks can be created and queried as expected""" assert self.db is not None, "No db initialized" db: MephistoDB = self.db project_name, project_id = get_test_project(db) # Check creation and retrieval of a task task_name_1 = "test_task" task_type = "mock" task_id_1 = db.new_task(task_name_1, task_type, project_id=project_id) self.assertIsNotNone(task_id_1) self.assertTrue(isinstance(task_id_1, str)) task_row = db.get_task(task_id_1) self.assertEqual(task_row["task_name"], task_name_1) self.assertEqual(task_row["task_type"], task_type) self.assertEqual(task_row["project_id"], project_id) self.assertIsNone(task_row["parent_task_id"]) task = Task.get(db, task_id_1) self.assertEqual(task.task_name, task_name_1) # Check creation of a task with a parent task, but no project task_name_2 = "test_task_2" task_id_2 = db.new_task(task_name_2, task_type) self.assertIsNotNone(task_id_2) self.assertTrue(isinstance(task_id_2, str)) task_row = db.get_task(task_id_2) self.assertEqual(task_row["task_name"], task_name_2) self.assertEqual(task_row["task_type"], task_type) self.assertIsNone(task_row["parent_task_id"]) self.assertIsNone(task_row["project_id"]) task = Task.get(db, task_id_2) self.assertEqual(task.task_name, task_name_2) # Check finding for tasks tasks = db.find_tasks() self.assertEqual(len(tasks), 2) self.assertTrue(isinstance(tasks[0], Task)) # Check finding for specific tasks tasks = db.find_tasks(task_name=task_name_1) self.assertEqual(len(tasks), 1) self.assertTrue(isinstance(tasks[0], Task)) self.assertEqual(tasks[0].db_id, task_id_1) self.assertEqual(tasks[0].task_name, task_name_1) tasks = db.find_tasks(project_id=project_id) self.assertEqual(len(tasks), 1) self.assertTrue(isinstance(tasks[0], Task)) self.assertEqual(tasks[0].db_id, task_id_1) self.assertEqual(tasks[0].task_name, task_name_1) tasks = db.find_tasks(task_name="fake_name") self.assertEqual(len(tasks), 0)
def test_task_fails(self) -> None: """Ensure task creation fails under specific cases""" assert self.db is not None, "No db initialized" db: MephistoDB = self.db # Cant get non-existent entry with self.assertRaises(EntryDoesNotExistException): task = Task.get(db, self.get_fake_id("Task")) task_name = "test_task" task_name_2 = "test_task_2" task_type = "mock" task_id = db.new_task(task_name, task_type) # Can't create same task again with self.assertRaises(EntryAlreadyExistsException): task_id = db.new_task(task_name, task_type) # Can't create task with invalid project with self.assertRaises(EntryDoesNotExistException): fake_id = self.get_fake_id("Project") task_id = db.new_task(task_name_2, task_type, project_id=fake_id) # Can't use no name with self.assertRaises(MephistoDBException): task_id = db.new_task("", task_type) # Ensure no tasks were created tasks = db.find_tasks() self.assertEqual(len(tasks), 1)
def get_task(self) -> "Task": """Return the task used to initialize this run""" if self.__task is None: from mephisto.data_model.task import Task self.__task = Task.get(self.db, self.task_id) return self.__task
def get_task(self) -> "Task": """Return the Task this agent is working within""" if self._task is None: if self._task_run is not None: self._task = self._task_run.get_task() else: from mephisto.data_model.task import Task self._task = Task.get(self.db, self.task_id) return self._task
def get_task(self) -> Task: """ Return the task run that this assignment is part of """ if self.__task is None: if self.__task_run is not None: self.__task = self.__task_run.get_task() else: self.__task = Task.get(self.db, self.task_id) return self.__task