Skip to content

Commit

Permalink
Fixes on GitProject
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusWirtz committed Oct 2, 2022
1 parent 340beae commit 1b8a59b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
42 changes: 27 additions & 15 deletions TM1py/Objects/GitProject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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'),
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion TM1py/Services/GitService.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion Tests/TM1Project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 1b8a59b

Please sign in to comment.