Skip to content
Merged
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
27 changes: 27 additions & 0 deletions TM1py/Services/ChoreService.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,33 @@ def exists(self, chore_name: str, **kwargs) -> bool:
url = format_url("/api/v1/Chores('{}')", chore_name)
return self._exists(url, **kwargs)

def search_for_process_name(self, process_name: str, **kwargs) -> List[Chore]:
""" Return chore details for any/all chores that contain specified process name in tasks

:param process_name: string, a valid ti process name; spaces will be elimniated
"""
url = format_url(
"/api/v1/Chores?$filter=Tasks/any(t: replace(tolower(t/Process/Name), ' ', '') eq '{}')" \
"&$expand=Tasks($expand=*,Chore($select=Name),Process($select=Name))",
process_name.lower().replace(' ', '')
)
response = self._rest.GET(url, **kwargs)
return [Chore.from_dict(chore_as_dict) for chore_as_dict in response.json()['value']]

def search_for_parameter_value(self, parameter_value: str, **kwargs) -> List[Chore]:
""" Return chore details for any/all chores that have a specified value set in the chore parameter settings
*this will NOT check the process parameter default, rather the defined parameter value saved in the chore

:param parameter_value: string, will search wildcard for string in parameter value using Contains(string)
"""
url = format_url(
"/api/v1/Chores?$filter=Tasks/any(t: t/Parameters/any(p: contains(tolower(p/Value), '{}')))" \
"&$expand=Tasks($expand=*,Process($select=Name),Chore($select=Name))",
parameter_value.lower()
)
response = self._rest.GET(url, **kwargs)
return [Chore.from_dict(chore_as_dict) for chore_as_dict in response.json()['value']]

@deactivate_activate
def update(self, chore: Chore, **kwargs):
""" update chore on TM1 Server
Expand Down
19 changes: 19 additions & 0 deletions Tests/ChoreService_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,22 @@ def test_get_all_names(self):
self.assertIn(self.chore_name2, all_chore_names)
self.assertIn(self.chore_name3, all_chore_names)

def test_search_for_process_name_happy_case(self):
chore_names = self.tm1.chores.search_for_process_name(process_name=process_name1)
self.assertEqual(2, len(chore_names))
self.assertEqual(self.chore_name1, chore_names[0].name)
self.assertEqual(self.chore_name2, chore_names[1].name)

def test_search_for_parameter_value_no_match(self):
chore_names = self.tm1.chores.search_for_parameter_value(parameter_value='NotAParamValue')
self.assertEqual([], chore_names)

def test_search_for_parameter_value_happy_case(self):
chore_names = self.tm1.chores.search_for_parameter_value(parameter_value='UK')
self.assertEqual(2, len(chore_names))
self.assertEqual(self.chore_name1, chore_names[0].name)
self.assertEqual(self.chore_name2, chore_names[1].name)

def test_update_chore_dst(self):
# get chore
c = self.tm1.chores.get(self.chore_name1)
Expand Down Expand Up @@ -400,6 +416,9 @@ def test_exists(self):
self.assertTrue(self.tm1.chores.exists(self.chore_name2))
self.assertTrue(self.tm1.chores.exists(self.chore_name3))
self.assertFalse(self.tm1.chores.exists(uuid.uuid4()))
def test_search_for_process_name_no_match(self):
chore_names = self.tm1.chores.search_for_process_name(process_name="NotAProcessName")
self.assertEqual([], chore_names)

@classmethod
def teardown_class(cls):
Expand Down