Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into workitem-required-fields
Browse files Browse the repository at this point in the history
# Conflicts:
#	polarion/project.py
  • Loading branch information
Jesper Raemaekers committed Apr 10, 2022
2 parents e134d6c + 0e6dc78 commit 8f31f69
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 3 deletions.
23 changes: 23 additions & 0 deletions polarion/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def __init__(self, polarion, project, polarion_record=None, uri=None, id=None, n
self._id = id

if new_plan_id is not None and new_plan_name is not None:
# get the ID from the plan if the ID if the plan is passed
if isinstance(new_plan_parent, Plan):
new_plan_parent = new_plan_parent.id
service = self._polarion.getService('Planning')
self._uri = service.createPlan(self._project.id, new_plan_name, new_plan_id, new_plan_parent, new_plan_template)

Expand Down Expand Up @@ -165,6 +168,26 @@ def save(self):
service.updatePlan(updated_plan)
self._reloadFromPolarion()

def getParent(self):
"""
Get the parent plan
:return: parent Plan
"""
return Plan(self._polarion, self._project, self.parent)

def getChildren(self):
"""
Get the child plans
:return: List of Plans, or empty list if there are no children.
"""
search_results = self._project.searchPlanFullItem(f'parent.id:{self.id}')
children = []
for plan in search_results:
if plan.id != self.id:
children.append(plan)
return children


def _reloadFromPolarion(self):
service = self._polarion.getService('Planning')
self._polarion_record = service.getPlanByUri(self._polarion_record.uri)
Expand Down
29 changes: 29 additions & 0 deletions polarion/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,35 @@ def createPlan(self, new_plan_name, new_plan_id, new_plan_template, new_plan_par
return Plan(self.polarion, self, new_plan_name=new_plan_name, new_plan_id=new_plan_id, new_plan_template=new_plan_template,
new_plan_parent=new_plan_parent)

def searchPlan(self, query='', order='Created', limit=-1):
"""Query for available plans. This will return the polarion data structures.
:param query: The query to use while searching
:param order: Order by
:param limit: The limit of plans, -1 for no limit
:return: The search results
:rtype: dict[]
"""
query += f' AND project.id:{self.id}'
service = self.polarion.getService('Planning')
return service.searchPlans(query, order, limit)

def searchPlanFullItem(self, query='', order='Created', limit=-1):
"""Query for available plans. This will query for the plans and then fetch all result. May take a while for a big search with many results.
:param query: The query to use while searching
:param order: Order by
:param limit: The limit of plans, -1 for no limit
:return: The search results
:rtype: Plan[]
"""
return_list = []
plans = self.searchPlan(query, order, limit)
for plan in plans:
return_list.append(Plan(self.polarion, self, polarion_record=plan))
return return_list


def createWorkitem(self, workitem_type: str, new_workitem_fields=None):
"""
Create a workitem based on the workitem type.
Expand Down
11 changes: 8 additions & 3 deletions polarion/workitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,14 @@ def _buildWorkitemFromPolarion(self):
setattr(self, key, value[key])
self._polarion_test_steps = None
try:
service_test = self._polarion.getService('TestManagement')
self._polarion_test_steps = service_test.getTestSteps(self.uri)
except Exception:
# get the custom fields
service = self._polarion.getService('Tracker')
custom_fields = service.getCustomFieldTypes(self.uri)
# check if any of the field has the test steps
if any(field.id == 'testSteps' for field in custom_fields):
service_test = self._polarion.getService('TestManagement')
self._polarion_test_steps = service_test.getTestSteps(self.uri)
except Exception as e:
# fail silently as there are probably not test steps for this workitem
# todo: logging support
pass
Expand Down
26 changes: 26 additions & 0 deletions tests/test_polarion_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,32 @@ def test_dates(self):
self.assertEqual(self.checking_plan.startDate.day, start_date.day, msg='Date is not equal')
self.assertEqual(self.checking_plan.startedOn.day, started_on_date.day, msg='Date is not equal')

def test_parent_children(self):
# get checking plan
self.checking_plan = self.executing_project.getPlan(self.executing_plan.id)

# check that there are no children
self.assertEqual(len(self.checking_plan.getChildren()), 0,
msg='No children should be here')

# create a child and check that there are children.
child_a = self.executing_project.createPlan('Test plan' + datetime.now().strftime("%d-%m-%Y-%H-%M-%S-%f"),
datetime.now().strftime("%d-%m-%Y-%H-%M-%S-%f"), 'iteration', new_plan_parent=self.executing_plan.id)


self.assertEqual(len(self.checking_plan.getChildren()), 1, msg='Added one child, but this is not in checking plan')
self.assertEqual(self.checking_plan.getChildren()[0].id, child_a.id, msg='Child id does not match')
self.assertEqual(child_a.getParent().id, self.executing_plan.id, msg='Parent id should match original parent')

# also check a sub child
sub_child = self.executing_project.createPlan('Test plan' + datetime.now().strftime("%d-%m-%Y-%H-%M-%S-%f"),
datetime.now().strftime("%d-%m-%Y-%H-%M-%S-%f"), 'iteration',
new_plan_parent=child_a)

self.assertEqual(child_a.getChildren()[0].id, sub_child.id, msg='Child id does not match')
self.assertEqual(sub_child.getParent().id, child_a.id, msg='Parent id should match original parent')





Expand Down

0 comments on commit 8f31f69

Please sign in to comment.