Skip to content

Commit f9e3e5e

Browse files
Tobias KunkelMariusWirtz
Tobias Kunkel
authored andcommitted
Add insert task function to chore
1 parent bf1e1c4 commit f9e3e5e

File tree

2 files changed

+101
-8
lines changed

2 files changed

+101
-8
lines changed

TM1py/Objects/Chore.py

+7
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ def execution_path(self) -> Dict:
126126
def add_task(self, task: ChoreTask):
127127
self._tasks.append(task)
128128

129+
def insert_task(self, new_task: ChoreTask):
130+
task_list = self.tasks
131+
for task in task_list[new_task._step:]:
132+
task._step = task._step + 1
133+
task_list.insert(new_task._step, new_task)
134+
self.tasks = task_list
135+
129136
def activate(self):
130137
self._active = True
131138

Tests/Chore_test.py

+94-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import unittest
2-
2+
33
from TM1py import Chore, ChoreStartTime, ChoreFrequency, ChoreTask
4-
5-
6-
class TestChore(unittest.TestCase):
7-
chore = Chore(
4+
from TM1py.Objects import Chore
5+
6+
class TestChore(unittest.TestCase):
7+
def setUp(self):
8+
self.chore = Chore(
89
name="chore",
910
start_time=ChoreStartTime(2023, 8, 4, 10, 0, 0),
1011
dst_sensitivity=False,
@@ -30,11 +31,96 @@ class TestChore(unittest.TestCase):
3031

3132
def test_from_dict_and_construct_body(self):
3233
text = self.chore.body
33-
34+
3435
chore = Chore.from_json(text)
35-
36+
3637
self.assertEqual(self.chore, chore)
38+
39+
def test_insert_task_as_step_0(self):
40+
self.chore.insert_task(
41+
ChoreTask(
42+
step=0,
43+
process_name="}bedrock.cube.clone",
44+
parameters=[
45+
{'Name': 'pLogOutput', 'Value': 0},
46+
{'Name': 'pStrictErrorHandling', 'Value': 1},
47+
{'Name': 'pWaitSec', 'Value': 5}]))
48+
expected_chore = Chore(
49+
name="chore",
50+
start_time=ChoreStartTime(2023, 8, 4, 10, 0, 0),
51+
dst_sensitivity=False,
52+
active=True,
53+
execution_mode="SingleCommit",
54+
frequency=ChoreFrequency(1, 0, 0, 0),
55+
tasks=[
56+
ChoreTask(
57+
step=0,
58+
process_name="}bedrock.cube.clone",
59+
parameters=[
60+
{'Name': 'pLogOutput', 'Value': 0},
61+
{'Name': 'pStrictErrorHandling', 'Value': 1},
62+
{'Name': 'pWaitSec', 'Value': 5}]),
63+
ChoreTask(
64+
step=1,
65+
process_name="}bedrock.server.wait",
66+
parameters=[
67+
{'Name': 'pLogOutput', 'Value': 0},
68+
{'Name': 'pStrictErrorHandling', 'Value': 1},
69+
{'Name': 'pWaitSec', 'Value': 4}]),
3770

38-
71+
ChoreTask(
72+
step=2,
73+
process_name="}bedrock.server.wait",
74+
parameters=[
75+
{'Name': 'pLogOutput', 'Value': 0},
76+
{'Name': 'pStrictErrorHandling', 'Value': 1},
77+
{'Name': 'pWaitSec', 'Value': 5}]),
78+
])
79+
self.assertEqual(self.chore, expected_chore)
80+
81+
def test_insert_task_as_step_1(self):
82+
self.chore.insert_task(
83+
ChoreTask(
84+
step=1,
85+
process_name="}bedrock.cube.clone",
86+
parameters=[
87+
{'Name': 'pLogOutput', 'Value': 0},
88+
{'Name': 'pStrictErrorHandling', 'Value': 1},
89+
{'Name': 'pWaitSec', 'Value': 5}]))
90+
expected_chore = Chore(
91+
name="chore",
92+
start_time=ChoreStartTime(2023, 8, 4, 10, 0, 0),
93+
dst_sensitivity=False,
94+
active=True,
95+
execution_mode="SingleCommit",
96+
frequency=ChoreFrequency(1, 0, 0, 0),
97+
tasks=[
98+
ChoreTask(
99+
step=0,
100+
process_name="}bedrock.server.wait",
101+
parameters=[
102+
{'Name': 'pLogOutput', 'Value': 0},
103+
{'Name': 'pStrictErrorHandling', 'Value': 1},
104+
{'Name': 'pWaitSec', 'Value': 4}]),
105+
ChoreTask(
106+
step=1,
107+
process_name="}bedrock.cube.clone",
108+
parameters=[
109+
{'Name': 'pLogOutput', 'Value': 0},
110+
{'Name': 'pStrictErrorHandling', 'Value': 1},
111+
{'Name': 'pWaitSec', 'Value': 5}]),
112+
ChoreTask(
113+
step=2,
114+
process_name="}bedrock.server.wait",
115+
parameters=[
116+
{'Name': 'pLogOutput', 'Value': 0},
117+
{'Name': 'pStrictErrorHandling', 'Value': 1},
118+
{'Name': 'pWaitSec', 'Value': 5}]),
119+
])
120+
self.assertEqual(self.chore, expected_chore)
121+
122+
39123
if __name__ == '__main__':
40124
unittest.main()
125+
126+

0 commit comments

Comments
 (0)