Polarion work items¶
Usage¶
This chapter details some common operations
Updating a field¶
The workitem can be updated and saved. The example below loads a workitem, changes the title and loads it again to show the changes have happened in Polarion.
workitem = project.getWorkitem('PYTH-510')
print(f'Title: {workitem.title}')
print(f'Status: {workitem.status.id}')
print(f'Type: {workitem.type.id}')
workitem.title = 'A custom new title!'
workitem.save()
reload_workitem = project.getWorkitem('PYTH-510')
print(f'Title: {reload_workitem.title}')
print(f'Status: {reload_workitem.status.id}')
print(f'Type: {reload_workitem.type.id}')
Prints:
Title: title?
Status: open
Type: task
Title: A custom new title!
Status: open
Type: task
Setting a new status¶
Polarion status changes can be made by choosing one fo the available options for the workitem.
workitem = project.getWorkitem('PYTH-510')
print(f'Status: {workitem.status.id}')
actions = workitem.getAvailableActions()
print(f' Actions: {actions}')
workitem.preformAction(actions[0])
reload_workitem = project.getWorkitem('PYTH-510')
print(f'Status: {reload_workitem.status.id}')
prints:
Status: open
Actions: ['start_progress', 'mark_done', 'mark_verified', 'reject']
Status: inprogress
The rules set in Polarion apply to these actions. Failing to meet the rules will result in an exception:
Exception has occurred: Fault
com.polarion.core.util.exceptions.UserFriendlyRuntimeException: 'Mark Done' failed for Work Item 'PYTH-510': The required field 'assignee' of Work Item 'PYTH-510' is empty
If a status requires other properties to be set, for example the resolution, then you can query options like so:
workitem = project.getWorkitem('PYTH-510')
print(f'Status: {workitem.status.id}')
actions = workitem.getAvailableActions()
print(f' Actions: {actions}')
resolutions = workitem.getResolutionEnum()
project_resolutions = project.getEnum('resolution')
print(f'Workitem resolutions: {resolutions}')
print(f'Project resolutions: {project_resolutions}')
workitem.setResolution(project_resolutions[11])
workitem.preformAction(actions[1])
reload_workitem = project.getWorkitem('PYTH-510')
print(f'Status: {reload_workitem.status.id}')
Print:
Status: open
Actions: ['start_progress', 'mark_done', 'mark_verified', 'reject']
Workitem resolutions: []
Project resolutions: ['done', 'valid', 'unsupported', 'wontdo', 'invalid', 'obsolete', 'duplicate', 'inactive', 'incomplete', 'other', 'cannotreproduce', 'later']
Status: done
In this case not workitem specific resolutions are available (Polarion project setting) so only the project resolutions can be used.
Warning
Currently there is no option available to check which resolutions are correct for the workflow defined in Polarion. You can set any resolution.
Changing the assignee¶
The assignee can be changed by getting a user from the project and setting it as assignee.
workitem = project.getWorkitem('PYTH-524')
j = project.findUser('john')
workitem.addAssignee(j)
Workitem class¶
-
class
polarion.workitem.Workitem(polarion, project, id=None, uri=None, new_workitem_type=None)¶ Create a Polarion workitem object either from and id or from an Polarion uri.
- Parameters
polarion – Polarion client object
project – Polarion Project object
id – Workitem ID
uri – Polarion uri
-
class
HyperlinkRoles(value)¶ Hyperlink reference type enum
-
addAssignee(user: polarion.user.User, remove_others=False)¶ Adds a user as assignee
- Parameters
user – The user object to add
remove_others – Set to True to make the new user the only assigned user.
-
addComment(title, comment, parent=None)¶ Adds a comment to the workitem.
- Parameters
title – Title of the comment (will be None for a reply)
comment – The comment, may contain html
parent – A parent comment, if none provided it’s a root comment.
-
addHyperlink(url, hyperlink_type: polarion.workitem.Workitem.HyperlinkRoles)¶ Adds a hyperlink to the workitem.
- Parameters
url – The URL to add
hyperlink_type – Select internal or external hyperlink
-
getAssignedUsers()¶ Get an array of assigned users
- Returns
An array of User objects
- Return type
User[]
-
getAuthor()¶ Get the author of the workitem
- Returns
Author
- Return type
User
-
getAvailableActions()¶ Get all actions option for this workitem without details
- Returns
An array of strings of the actions
- Return type
string[]
-
getAvailableActionsDetails()¶ Get all actions option for this workitem with defails
- Returns
An array of dictionaries of the actions
- Return type
dict[]
-
getAvailableStatus()¶ Get all available status option for this workitem
- Returns
An array of string of the statusses
- Return type
string[]
-
getDescription()¶ Get a comment if available. The comment may contain HTML if edited in Polarion!
- Returns
The content of the description, may contain HTML
- Return type
string
-
getResolutionEnum()¶ tries to get the resolution enum of this workitem type When it fails to get it, the list will be empty
- Returns
An array of strings of the resolutions
- Return type
string[]
-
getSeverityEnum()¶ tries to get the severity enum of this workitem type When it fails to get it, the list will be empty
- Returns
An array of strings of the severities
- Return type
string[]
-
getStatusEnum()¶ tries to get the status enum of this workitem type When it fails to get it, the list will be empty
- Returns
An array of strings of the statusses
- Return type
string[]
-
hasTestSteps()¶ Checks if the workitem has test steps
- Returns
True/False
- Return type
boolean
-
preformAction(action_name)¶ Preform selected action. An exception will be thorn if some prerequisite is not set.
- Parameters
action_name – string containing the action name
-
preformActionId(actionId: int)¶ Preform selected action. An exception will be thorn if some prerequisite is not set.
- Parameters
actionId – number for the action to preform
-
removeAssignee(user: polarion.user.User)¶ Remove a user from the assignees
- Parameters
user – The user object to remove
-
save()¶ Update the workitem in polarion
-
setDescription(description)¶ Sets the description and saves the workitem
- Parameters
description – the description
-
setResolution(resolution)¶ Sets the resolution and saves the workitem
- Parameters
resolution – the resolution
-
setStatus(status)¶ Sets the status opf the workitem and saves the workitem, not respecting any project configured limits or requirements.
- Parameters
status – name of the status