Skip to content

Commit

Permalink
Created test and documentation for adding required fields upon workit…
Browse files Browse the repository at this point in the history
…em creation.
  • Loading branch information
Jesper Raemaekers committed Apr 10, 2022
1 parent b0ab45c commit e134d6c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/workitem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ A new workitem can be created using :func:`~Project.createWorkitem`.
new_task = project.createWorkitem('changerequest')
# Add fields to the creation. Needed if there are required fields upon creation.
new_task = project..createWorkitem('task', new_workitem_fields={'title': 'New title'})
Updating a field
^^^^^^^^^^^^^^^^

Expand Down
5 changes: 4 additions & 1 deletion polarion/workitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ def __init__(self, polarion, project, id=None, uri=None, new_workitem_type=None,

if new_workitem_fields is not None:
for new_field in new_workitem_fields:
self._polarion_item[new_field] = new_workitem_fields[new_field]
if new_field in self._polarion_item:
self._polarion_item[new_field] = new_workitem_fields[new_field]
else:
raise Exception(f'{new_field} in new_workitem_fields is not recognised as a workitem field')

# and create it
new_uri = service.createWorkItem(self._polarion_item)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_polarion_workitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ def test_create_workitem(self):
self.assertEqual(executed_workitem, checking_workitem,
msg='Workitems not identical')

# Check that fields can be supplied with the call
executed_workitem = self.executing_project.createWorkitem('task', new_workitem_fields={'title': 'Test title!'})
checking_workitem = self.checking_project.getWorkitem(
executed_workitem.id)

self.assertEqual(executed_workitem, checking_workitem,
msg='Workitems not identical when created with supplied fields')

# Check that fields are checks for validity
with self.assertRaises(Exception):
executed_workitem = self.executing_project.createWorkitem('task', new_workitem_fields={'wrong-field': 'what happens?'})

def test_title_change(self):
executed_workitem = self.global_workitem
checking_workitem = self.checking_project.getWorkitem(
Expand Down

0 comments on commit e134d6c

Please sign in to comment.