Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update multiple parts of wi. #129

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/workitem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,20 @@ The workitem class implements the __eq__ method allowing it to be compared.
if workitem1 == workitem2:
#...
Context Manager
^^^^^^^^^^^^^^^

It is possible to use the context manager with a workitem.
This is useful, when updating many attributes of it.
Execution speed increases, because the workitem is only updated / saved once, when exiting the context manager.

.. code:: python
with workitem as wi:
wi.addAttachment(path_to_file, 'file title')
wi.addComment('comment')
# any many more
List of available attributes
----------------------------
Expand Down
8 changes: 4 additions & 4 deletions polarion/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ def __init__(self, polarion, test_run, polarion_record, index):
self._polarion_record = polarion_record
self._index = index

self._skip_save = False
self._postpone_save = False

self._buildWorkitemFromPolarion()

def __enter__(self):
self._skip_save = True
self._postpone_save = True
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self._skip_save = False
self._postpone_save = False
self.save()

def _buildWorkitemFromPolarion(self):
Expand Down Expand Up @@ -301,7 +301,7 @@ def save(self):
"""
Saves the current test record
"""
if self._skip_save:
if self._postpone_save:
return

new_item = {}
Expand Down
11 changes: 11 additions & 0 deletions polarion/workitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self, polarion, project, id=None, uri=None, new_workitem_type=None,
self._project = project
self._id = id
self._uri = uri
self._postpone_save = False

service = self._polarion.getService('Tracker')

Expand Down Expand Up @@ -88,6 +89,14 @@ def __init__(self, polarion, project, id=None, uri=None, new_workitem_type=None,

self._buildWorkitemFromPolarion()

def __enter__(self):
self._postpone_save = True
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self._postpone_save = False
self.save()

def _buildWorkitemFromPolarion(self):
if self._polarion_item is not None and not self._polarion_item.unresolvable:
self._original_polarion = copy.deepcopy(self._polarion_item)
Expand Down Expand Up @@ -774,6 +783,8 @@ def save(self):
"""
Update the workitem in polarion
"""
if self._postpone_save:
return
updated_item = {}

for attr, value in self._polarion_item.__dict__.items():
Expand Down