diff --git a/TM1py/Objects/GitProject.py b/TM1py/Objects/GitProject.py index 2ef3f8a5..8a0096b0 100644 --- a/TM1py/Objects/GitProject.py +++ b/TM1py/Objects/GitProject.py @@ -62,24 +62,33 @@ def __init__(self, task_name: str, chore: str = None, process: str = None, param self.dependencies = dependencies def construct_body(self) -> Dict: - inner_body = dict() + body = dict() if self.dependencies: - inner_body["Dependencies"] = self.dependencies + body["Dependencies"] = self.dependencies if self.chore: - inner_body["Chore"] = self.chore + body["Chore"] = self.chore else: - inner_body = { - "Process": self.process, + body = { + "Process": f"Processes('{self.process}')", "Parameters": self.parameters } - body = {self.task_name: inner_body} - return body + @classmethod + def from_dict(cls, task_name: str, task: Dict): + return cls( + task_name=task_name, + chore=task.get("Chore"), + process=task.get("Process"), + parameters=task.get("Parameters"), + dependencies=task.get("Dependencies"), + precondition=task.get("Precondition"), + ) + class TM1Project(TM1Object): """ Abstraction of Git tm1project @@ -90,7 +99,7 @@ def __init__( version: int = 1.0, name: Optional[str] = '', settings: Optional[Dict] = None, - tasks: Optional[List[TM1ProjectTask]] = None, + tasks: Optional[Dict[str, TM1ProjectTask]] = None, objects: Optional[Dict] = None, ignore: Optional[List] = None, files: Optional[List] = None, @@ -134,15 +143,15 @@ def __init__( def add_task(self, project_task: TM1ProjectTask): if self._tasks is None: - self._tasks = [] + self._tasks = dict() if project_task.task_name in self._tasks: raise ValueError(f"Task with name '{project_task.task_name}' already exists in TM1 project. " f"Task name must be unique") - self._tasks.append(project_task) + self._tasks[project_task.task_name] = project_task - def include_attribute_dimensions(self, tm1): + def include_all_attribute_dimensions(self, tm1): """ Add an ignore-exception for each attribute dimension @@ -226,7 +235,7 @@ def add_ignore(self, object_class: str, object_name: str): if object_name: ignore_entry += f"('{object_name}')" - if not ignore_entry in self.ignore: + if ignore_entry not in self.ignore: self.ignore.append(ignore_entry) @classmethod @@ -248,7 +257,10 @@ def from_dict(cls, tm1project_as_dict: Dict) -> 'TM1Project': version=tm1project_as_dict['Version'], name=tm1project_as_dict.get('Name'), settings=tm1project_as_dict.get('Settings'), - tasks=tm1project_as_dict.get('Tasks'), + tasks={ + task_name: TM1ProjectTask.from_dict(task_name, task) + for task_name, task + in tm1project_as_dict.get('Tasks').items()}, objects=tm1project_as_dict.get('Objects'), ignore=tm1project_as_dict.get('Ignore'), files=tm1project_as_dict.get('Files'), @@ -274,7 +286,7 @@ def _construct_body(self) -> Dict: 'Version': self._version, 'Name': self._name, 'Settings': self._settings, - 'Tasks': [task.construct_body() for task in self._tasks] if self._tasks else None, + 'Tasks': {name: task.construct_body() for name, task in self.tasks.items()} if self._tasks else None, 'Objects': self._objects, 'Ignore': self._ignore, 'Files': self._files, @@ -319,7 +331,7 @@ def settings(self, value: Dict): self._settings = value @property - def tasks(self) -> List: + def tasks(self) -> Dict: return self._tasks @tasks.setter diff --git a/TM1py/Services/GitService.py b/TM1py/Services/GitService.py index d3f15c7d..a2298d26 100644 --- a/TM1py/Services/GitService.py +++ b/TM1py/Services/GitService.py @@ -44,7 +44,7 @@ def tm1project_put(self, tm1_project: TM1Project) -> TM1Project: url = '/api/v1/!tm1project' body_json = tm1_project.body - response = self._rest.PUT(url=url,data=body_json) + response = self._rest.PUT(url=url, data=body_json) return TM1Project.from_dict(response.json()) def git_init(self, git_url: str, deployment: str, username: str = None, password: str = None, diff --git a/Tests/TM1Project.py b/Tests/TM1Project.py index 46209e6e..fd504604 100644 --- a/Tests/TM1Project.py +++ b/Tests/TM1Project.py @@ -13,7 +13,7 @@ def test_add_task_process(self): expected_body = { "Version": 1.0, "Name": "TM1py Tests", - "Tasks": [{"TaskA": {"Process": "bedrock.server.savedataall", "Parameters": None}}]} + "Tasks": {"TaskA": {"Process": "Processes('bedrock.server.savedataall')"}}} self.assertEqual(expected_body, project.body_as_dict)