Skip to content

Commit

Permalink
Add insert task function to chore
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Kunkel authored and MariusWirtz committed Feb 25, 2025
1 parent bf1e1c4 commit f9e3e5e
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 8 deletions.
7 changes: 7 additions & 0 deletions TM1py/Objects/Chore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
102 changes: 94 additions & 8 deletions Tests/Chore_test.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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()


0 comments on commit f9e3e5e

Please sign in to comment.