diff --git a/TM1py/Objects/Chore.py b/TM1py/Objects/Chore.py index 987b671e..458afe46 100644 --- a/TM1py/Objects/Chore.py +++ b/TM1py/Objects/Chore.py @@ -126,6 +126,13 @@ def execution_path(self) -> Dict: def add_task(self, task: ChoreTask): self._tasks.append(task) + def insert_task(self, new_task: ChoreTask): + task_list = self.tasks + for task in task_list[new_task._step:]: + task._step = task._step + 1 + task_list.insert(new_task._step, new_task) + self.tasks = task_list + def activate(self): self._active = True diff --git a/Tests/Chore_test.py b/Tests/Chore_test.py index 2d617373..83a61f27 100644 --- a/Tests/Chore_test.py +++ b/Tests/Chore_test.py @@ -1,10 +1,11 @@ import unittest - + from TM1py import Chore, ChoreStartTime, ChoreFrequency, ChoreTask - - -class TestChore(unittest.TestCase): - chore = Chore( +from TM1py.Objects import Chore + +class TestChore(unittest.TestCase): + def setUp(self): + self.chore = Chore( name="chore", start_time=ChoreStartTime(2023, 8, 4, 10, 0, 0), dst_sensitivity=False, @@ -30,11 +31,96 @@ class TestChore(unittest.TestCase): def test_from_dict_and_construct_body(self): text = self.chore.body - + chore = Chore.from_json(text) - + self.assertEqual(self.chore, chore) + + def test_insert_task_as_step_0(self): + self.chore.insert_task( + ChoreTask( + step=0, + process_name="}bedrock.cube.clone", + parameters=[ + {'Name': 'pLogOutput', 'Value': 0}, + {'Name': 'pStrictErrorHandling', 'Value': 1}, + {'Name': 'pWaitSec', 'Value': 5}])) + expected_chore = Chore( + name="chore", + start_time=ChoreStartTime(2023, 8, 4, 10, 0, 0), + dst_sensitivity=False, + active=True, + execution_mode="SingleCommit", + frequency=ChoreFrequency(1, 0, 0, 0), + tasks=[ + ChoreTask( + step=0, + process_name="}bedrock.cube.clone", + parameters=[ + {'Name': 'pLogOutput', 'Value': 0}, + {'Name': 'pStrictErrorHandling', 'Value': 1}, + {'Name': 'pWaitSec', 'Value': 5}]), + ChoreTask( + step=1, + process_name="}bedrock.server.wait", + parameters=[ + {'Name': 'pLogOutput', 'Value': 0}, + {'Name': 'pStrictErrorHandling', 'Value': 1}, + {'Name': 'pWaitSec', 'Value': 4}]), - + ChoreTask( + step=2, + process_name="}bedrock.server.wait", + parameters=[ + {'Name': 'pLogOutput', 'Value': 0}, + {'Name': 'pStrictErrorHandling', 'Value': 1}, + {'Name': 'pWaitSec', 'Value': 5}]), + ]) + self.assertEqual(self.chore, expected_chore) + + def test_insert_task_as_step_1(self): + self.chore.insert_task( + ChoreTask( + step=1, + process_name="}bedrock.cube.clone", + parameters=[ + {'Name': 'pLogOutput', 'Value': 0}, + {'Name': 'pStrictErrorHandling', 'Value': 1}, + {'Name': 'pWaitSec', 'Value': 5}])) + expected_chore = Chore( + name="chore", + start_time=ChoreStartTime(2023, 8, 4, 10, 0, 0), + dst_sensitivity=False, + active=True, + execution_mode="SingleCommit", + frequency=ChoreFrequency(1, 0, 0, 0), + tasks=[ + ChoreTask( + step=0, + process_name="}bedrock.server.wait", + parameters=[ + {'Name': 'pLogOutput', 'Value': 0}, + {'Name': 'pStrictErrorHandling', 'Value': 1}, + {'Name': 'pWaitSec', 'Value': 4}]), + ChoreTask( + step=1, + process_name="}bedrock.cube.clone", + parameters=[ + {'Name': 'pLogOutput', 'Value': 0}, + {'Name': 'pStrictErrorHandling', 'Value': 1}, + {'Name': 'pWaitSec', 'Value': 5}]), + ChoreTask( + step=2, + process_name="}bedrock.server.wait", + parameters=[ + {'Name': 'pLogOutput', 'Value': 0}, + {'Name': 'pStrictErrorHandling', 'Value': 1}, + {'Name': 'pWaitSec', 'Value': 5}]), + ]) + self.assertEqual(self.chore, expected_chore) + + if __name__ == '__main__': unittest.main() + + \ No newline at end of file