workflows: properly import/export hidden comment button label (#5208)

This commit is contained in:
Frédéric Péters 2014-07-23 16:47:43 +02:00
parent 25ff55321b
commit 050d0ca811
2 changed files with 24 additions and 2 deletions

View File

@ -177,3 +177,18 @@ def test_jump_action():
assert wf2.possible_status[0].items[0].condition == '"foo"'
assert wf2.possible_status[0].items[0].trigger == 'bar'
assert wf2.possible_status[0].items[0].timeout == 1200
def test_commentable_action():
wf = Workflow(name='status')
st1 = wf.add_status('Status1', 'st1')
commentable = CommentableWorkflowStatusItem()
commentable.id = '_commentable'
commentable.by = ['_submitter', '_receiver']
commentable.button_label = None
st1.items.append(commentable)
commentable.parent = st1
wf2 = assert_import_export_works(wf)
assert wf2.possible_status[0].items[0].button_label is None

View File

@ -977,6 +977,8 @@ class CommentableWorkflowStatusItem(WorkflowStatusItem):
if self.button_label == 0:
pass
elif self.button_label is None:
# button_label being None is a special case meaning "no button", it
# should be handled differently than the "not filled" case
el = ET.SubElement(xml_item, 'button_label')
else:
el = ET.SubElement(xml_item, 'button_label')
@ -988,9 +990,14 @@ class CommentableWorkflowStatusItem(WorkflowStatusItem):
raise AssertionError('unknown type for button_label (%r)' % self.button_label)
def button_label_init_with_xml(self, element, charset):
if element is None or element.text is None:
if element is None:
return
self.button_label = element.text.encode(charset)
if element.text is None:
# this means element is self-closing, <button_label />, which maps
# to None, meaning "no button".
self.button_label = None
else:
self.button_label = element.text.encode(charset)
register_item_class(CommentableWorkflowStatusItem)