def test_update_task(self): input = Task(name="TestTask",description = "A test description") yield self._persistenceLayer.save_task(input) input.name = "TestTaskModified" yield self._persistenceLayer.save_task(input) exp = input obs = yield self._persistenceLayer.load_task(id = input.cid) self.assertEquals(obs,exp)
def test_save_and_load_tasks(self): input =[] input.append(Task(name="TestTaskOne",description = "A test description")) input.append(Task(name="TestTaskTwo",description = "Another test description",status="active")) yield self._persistenceLayer.save_tasks(input) exp = input obs = yield self._persistenceLayer.load_tasks() self.assertEquals(obs,exp)
def load_tasks(self, environmentId = None ,*args,**kwargs): """Save the task object .""" lTasks = [] if environmentId is not None: rows = yield self.select(environmentId = str(environmentId), order = "id") else: rows = yield self.select(order = "id") for row in rows: id,name,description,status = row task = Task(name = name,description=description,status=status) task.cid = uuid.UUID(id) lTasks.append(task) defer.returnValue(lTasks)
def load_task(self,id = None, environmentId = None ,*args,**kwargs): """Retrieve data from task object.""" if id is not None: rows = yield self.select(id = str(id)) elif environmentId is not None: rows = yield self.select(environmentId = str(environmentId)) result=None if len(rows)>0: id,name,description,status = rows[0] result = Task(name = name,description=description,status=status) result.cid = uuid.UUID(id) else: raise TaskNotFound() defer.returnValue(result)
def load_task(self, id=None, environmentId=None, *args, **kwargs): """Retrieve data from task object.""" if id is not None: rows = yield self.select(id=str(id)) elif environmentId is not None: rows = yield self.select(environmentId=str(environmentId)) result = None if len(rows) > 0: id, name, description, status = rows[0] result = Task(name=name, description=description, status=status) result.cid = uuid.UUID(id) else: raise TaskNotFound() defer.returnValue(result)
def load_tasks(self, environmentId=None, *args, **kwargs): """Save the task object .""" lTasks = [] if environmentId is not None: rows = yield self.select(environmentId=str(environmentId), order="id") else: rows = yield self.select(order="id") for row in rows: id, name, description, status = row task = Task(name=name, description=description, status=status) task.cid = uuid.UUID(id) lTasks.append(task) defer.returnValue(lTasks)
def test_delete_task(self): input = Task(name="TestTask",description = "A test description") yield self._persistenceLayer.save_task(input) exp = input obs = yield self._persistenceLayer.load_task(id = input.cid) self.assertEquals(obs,exp) yield self._persistenceLayer.delete_task(input) obs = self._persistenceLayer.load_task(id = input.cid) self.assertFailure(obs ,TaskNotFound )
def add_task(self,name="Default Task",description="Default task description",status = "inactive",params={},*args,**kwargs): """ Add a new task to the list of task of the current environment Params: name: the name of the task Desciption: short description of task """ task = Task(parent= self._parentEnvironment, name = name, description = description, status = status) #yield task.setup() self._tasks[task.cid] = task yield self._persistenceLayer.save_task(task) log.msg("Added task named:",name ," description:",description,"with id",task.cid, system="task manager", logLevel=logging.CRITICAL) self._signal_dispatcher.send_message("task.created",self,task) defer.returnValue(task)
def test_save_and_load_tasks_of_environment(self): parentEnvironement = Environment(name="TestEnvironment",description = "A test description") task1 = Task(name="TestTaskOne",description = "A test description") task1._parent = parentEnvironement task2 = Task(name="TestTaskTwo",description = "Another test description",status="active") task2._parent = parentEnvironement input =[task1,task2] parentEnvironement2 = Environment(name="TestEnvironment2",description = "A test description") task3 = Task(name="TestTaskThree",description = "A test description") task3._parent = parentEnvironement2 yield self._persistenceLayer.save_tasks(input) yield self._persistenceLayer.save_task(task3) exp = input obs = yield self._persistenceLayer.load_tasks(parentEnvironement.cid) self.assertEquals(obs,exp) exp = [task3] obs = yield self._persistenceLayer.load_tasks(parentEnvironement2.cid) self.assertEquals(obs,exp)
def test_delete_task_exception(self): input = Task(name="TestTask",description = "A test description") obs = self._persistenceLayer.delete_task(input) self.assertFailure(obs ,TaskNotFound )