Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add insert task function to chore #1219

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()