workflows: add multiple jump labels to webservice action (#10495)

This commit is contained in:
Frédéric Péters 2018-10-16 07:19:04 +02:00
parent 5756c52526
commit 929e23c2d0
4 changed files with 36 additions and 20 deletions

View File

@ -1370,6 +1370,11 @@ def test_webservice_call(http_requests, pub):
item = WebserviceCallStatusItem()
item.parent = st1
assert item.get_jump_label(st1.id) == 'Webservice'
assert item.get_jump_label('sterr') == 'Error calling webservice'
item.label = 'Plop'
assert item.get_jump_label(st1.id) == 'Webservice "Plop"'
assert item.get_jump_label('sterr') == 'Error calling webservice "Plop"'
item.url = 'http://remote.example.net/500'
item.action_on_5xx = 'sterr' # jump to status
formdata.status = 'wf-st1'
@ -1836,20 +1841,20 @@ def test_webservice_target_status(pub):
item = WebserviceCallStatusItem()
item.parent = status1
assert item.get_target_status() == []
assert item.get_target_status() == [status1.id]
item.action_on_app_error = status1.id
item.action_on_4xx = status2.id
item.action_on_5xx = status2.id
targets = item.get_target_status()
assert len(item.get_target_status()) == 3
assert targets.count(status1) == 1
assert len(item.get_target_status()) == 4
assert targets.count(status1) == 2
assert targets.count(status2) == 2
item.action_on_bad_data = 'st3' # doesn't exist
targets = item.get_target_status()
assert len(item.get_target_status()) == 3
assert targets.count(status1) == 1
assert len(item.get_target_status()) == 4
assert targets.count(status1) == 2
assert targets.count(status2) == 2
def test_timeout(two_pubs):

View File

@ -152,11 +152,11 @@ def graphviz(workflow, url_prefix='', select=None, svg=True,
for status in workflow.possible_status:
i = status.id
for item in status.items:
next_status_ids = [x.id for x in item.get_target_status()
if x.id and x.id != status.id]
next_status_ids = [x.id for x in item.get_target_status() if x.id]
if not next_status_ids:
next_status_ids = [status.id]
done = {}
url = 'status/%s/items/%s/' % (i, item.id)
for next_id in next_status_ids:
if next_id in done:
# don't display multiple arrows for same action and target
@ -164,15 +164,14 @@ def graphviz(workflow, url_prefix='', select=None, svg=True,
continue
print >>out, 'status%s -> status%s' % (i, next_id)
done[next_id] = True
url = 'status/%s/items/%s/' % (i, item.id)
label = item.get_jump_label()
label = label.replace('"', '\\"')
label = label.decode('utf8')
label = textwrap.fill(label, 20, break_long_words=False)
label = label.encode('utf8')
label = label.replace('\n', '\\n')
print >>out, '[label="%s"' % label,
print >>out, ',URL="%s%s"]' % (url_prefix, url)
label = item.get_jump_label(target_id=next_id)
label = label.replace('"', '\\"')
label = label.decode('utf8')
label = textwrap.fill(label, 20, break_long_words=False)
label = label.encode('utf8')
label = label.replace('\n', '\\n')
print >>out, '[label="%s"' % label,
print >>out, ',URL="%s%s"]' % (url_prefix, url)
print >>out, '}'
out = out.getvalue()

View File

@ -421,7 +421,10 @@ class WebserviceCallStatusItem(WorkflowStatusItem):
raise AbortActionException()
def get_target_status(self):
targets = []
# always return self status as a target so it's included in the
# workflow visualisation as a "normal" action, in addition to
# jumps related to error handling.
targets = [self.parent]
for attribute in ('action_on_app_error', 'action_on_4xx', 'action_on_5xx',
'action_on_bad_data', 'action_on_network_errors'):
value = getattr(self, attribute)
@ -439,8 +442,17 @@ class WebserviceCallStatusItem(WorkflowStatusItem):
targets.append(target)
return targets
def get_jump_label(self):
return _('Error calling webservice')
def get_jump_label(self, target_id):
if target_id == self.parent.id:
if self.label:
return _('Webservice "%s"') % self.label
else:
return _('Webservice')
else:
if self.label:
return _('Error calling webservice "%s"') % self.label
else:
return _('Error calling webservice')
def _kv_data_export_to_xml(self, xml_item, charset, include_id, attribute):
assert attribute

View File

@ -1760,7 +1760,7 @@ class WorkflowStatusItem(XmlSerialisable):
return targets
def get_jump_label(self):
def get_jump_label(self, target_id):
'''Return the label to use on a workflow graph arrow'''
if getattr(self, 'label', None):
label = self.label