From 394ebf9a8dc77cfc0673e2edf0715a5a2679d5a6 Mon Sep 17 00:00:00 2001
From: Nicolas ROCHE <nroche@entrouvert.com>
Date: Tue, 27 Aug 2019 15:55:43 +0200
Subject: [PATCH 2/4] tests: assert xml import-export works (#31823)

---
 tests/test_workflow_import.py | 84 +++++++++++++++++------------------
 1 file changed, 42 insertions(+), 42 deletions(-)

diff --git a/tests/test_workflow_import.py b/tests/test_workflow_import.py
index bfe823b5..dbf72ef5 100644
--- a/tests/test_workflow_import.py
+++ b/tests/test_workflow_import.py
@@ -53,13 +53,13 @@ def assert_xml_import_export_works(wf, include_id=False):
 
 def test_empty(pub):
     wf = Workflow(name='empty')
-    assert_import_export_works(wf)
+    assert_xml_import_export_works(wf)
 
 def test_status(pub):
     wf = Workflow(name='status')
     st1 = wf.add_status('Status1', 'st1')
     st2 = wf.add_status('Status2', 'st2')
-    assert_import_export_works(wf)
+    assert_xml_import_export_works(wf)
 
 def test_status_actions(pub):
     wf = Workflow(name='status')
@@ -72,7 +72,7 @@ def test_status_actions(pub):
     st1.items.append(commentable)
     commentable.parent = st1
 
-    assert_import_export_works(wf)
+    assert_xml_import_export_works(wf)
 
 def test_status_colour_css_class(pub):
     wf = Workflow(name='status')
@@ -80,20 +80,20 @@ def test_status_colour_css_class(pub):
     st1.extra_css_class = 'hello'
     st1.colour = 'FF0000'
     st2 = wf.add_status('Status2', 'st2')
-    assert_import_export_works(wf)
+    assert_xml_import_export_works(wf)
 
 def test_status_forced_endpoint(pub):
     wf = Workflow(name='status')
     st1 = wf.add_status('Status1', 'st1')
     st1.forced_endpoint = True
     st2 = wf.add_status('Status2', 'st2')
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert wf2.possible_status[0].forced_endpoint is True
     assert wf2.possible_status[1].forced_endpoint is False
 
 def test_default_wf(pub):
     wf = Workflow.get_default_workflow()
-    assert_import_export_works(wf)
+    assert_xml_import_export_works(wf)
 
 
 def test_action_dispatch(pub):
@@ -115,7 +115,7 @@ def test_action_dispatch(pub):
     st1.items.append(dispatch)
     dispatch.parent = st1
 
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
 
     # checks role id is imported as integer
     assert(wf2.possible_status[0].items[0].role_id == '5')
@@ -124,24 +124,24 @@ def test_action_dispatch(pub):
     # now roles are managed: cannot create them
     dispatch.role_id = 'unknown'
     with pytest.raises(WorkflowImportError, match=r'.*Unknown referenced role.*'):
-        wf2 = assert_import_export_works(wf)
+        wf2 = assert_xml_import_export_works(wf)
     # but allow computed roles
     dispatch.role_id = '=form_var_bar'
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert(wf2.possible_status[0].items[0].role_id == '=form_var_bar')
     dispatch.role_id = 'Role {{ form_var_foo }}'
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert(wf2.possible_status[0].items[0].role_id == 'Role {{ form_var_foo }}')
     dispatch.role_id = 'Role [form_var_foo]'
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert(wf2.possible_status[0].items[0].role_id == 'Role [form_var_foo]')
 
     dispatch.role_id = 'Rolé [form_var_foo]'
-    wf2 = assert_import_export_works(wf, include_id=False)
+    wf2 = assert_xml_import_export_works(wf, include_id=False)
     assert wf2.possible_status[0].items[0].role_id == 'Rolé [form_var_foo]'
 
     dispatch.role_id = 'Rolé [form_var_foo]'
-    wf2 = assert_import_export_works(wf, include_id=True)
+    wf2 = assert_xml_import_export_works(wf, include_id=True)
     assert wf2.possible_status[0].items[0].role_id == 'Rolé [form_var_foo]'
 
 def test_status_actions_named_role(pub):
@@ -155,7 +155,7 @@ def test_status_actions_named_role(pub):
     st1.items.append(commentable)
     commentable.parent = st1
 
-    assert_import_export_works(wf)
+    assert_xml_import_export_works(wf)
 
 
 def test_status_actions_named_existing_role(pub):
@@ -174,7 +174,7 @@ def test_status_actions_named_existing_role(pub):
     st1.items.append(commentable)
     commentable.parent = st1
 
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert '<item role_id="2">Test Role named existing role</item>' in ET.tostring(indent(wf.export_to_xml()))
     assert wf2.possible_status[0].items[0].by == ['2']
 
@@ -208,7 +208,7 @@ def test_status_actions_named_missing_role(pub):
     st1.items.append(commentable)
     commentable.parent = st1
 
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
 
     # check that role name has precedence over id
     xml_export_orig = ET.tostring(export_to_indented_xml(wf))
@@ -254,7 +254,7 @@ def test_display_form_action(pub):
     st1.items.append(display_form)
     display_form.parent = st1
 
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     # formdef.max_field_id is recalculated when importing a FormWorkflowStatusItem
     assert wf2.possible_status[0].items[0].formdef.max_field_id == len(display_form.formdef.fields)
 
@@ -280,7 +280,7 @@ def test_export_to_model_action(pub):
     export_to.parent = st1
 
     assert wf.possible_status[0].items[0].model_file.base_filename == 'bar'
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert wf2.possible_status[0].items[0].model_file.base_filename == 'bar'
     assert wf2.possible_status[0].items[0].model_file.get_file().read() == file_content
 
@@ -311,7 +311,7 @@ def test_export_to_model_action(pub):
 def test_export_roles(pub):
     wf = Workflow(name='roles')
     wf.roles = {'foo': 'Bar'}
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert wf2.roles == wf.roles
 
 
@@ -331,14 +331,14 @@ def test_jump_action(pub):
     st1.items.append(jump)
     jump.parent = st1
 
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert wf2.possible_status[0].items[0].condition == {'type': 'python', 'value': '"foo"'}
     assert wf2.possible_status[0].items[0].trigger == 'bar'
     assert wf2.possible_status[0].items[0].timeout == 1200
 
     # check with a formula as timeout
     jump.timeout = '=1200'
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert wf2.possible_status[0].items[0].timeout == '=1200'
 
     # legacy condition value
@@ -362,12 +362,12 @@ def test_commentable_action(pub):
     st1.items.append(commentable)
     commentable.parent = st1
 
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert wf2.possible_status[0].items[0].button_label is None
     assert wf2.possible_status[0].items[0].required is False
 
     commentable.required = True
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert wf2.possible_status[0].items[0].required is True
 
     # import legacy comment without required attribute
@@ -384,7 +384,7 @@ def test_variables_formdef(pub):
     from wcs.workflows import WorkflowVariablesFieldsFormDef
     wf.variables_formdef = WorkflowVariablesFieldsFormDef(workflow=wf)
     wf.variables_formdef.fields.append(StringField(label='Test', type='string'))
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert wf2.variables_formdef.fields[0].label == 'Test'
 
 def test_wscall_action(pub):
@@ -402,7 +402,7 @@ def test_wscall_action(pub):
     st1.items.append(wscall)
     wscall.parent = st1
 
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     wscall2 = wf2.possible_status[0].items[0]
     assert wscall2.url == 'http://test/'
     assert wscall2.varname == 'varname'
@@ -423,7 +423,7 @@ def test_backoffice_info_text(pub):
     st1.items.append(commentable)
     commentable.parent = st1
 
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert wf2.possible_status[0].backoffice_info_text == '<p>Foo</p>'
     assert wf2.possible_status[0].items[0].backoffice_info_text == '<p>Bar</p>'
 
@@ -447,10 +447,10 @@ def test_global_actions(pub):
     assert trigger.key == 'manual'
     trigger.roles = [role.id]
 
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert wf2.global_actions[0].triggers[0].roles == [role.id]
 
-    wf2 = assert_import_export_works(wf, True)
+    wf2 = assert_xml_import_export_works(wf, True)
 
 def test_backoffice_fields(pub):
     wf = Workflow(name='bo fields')
@@ -459,7 +459,7 @@ def test_backoffice_fields(pub):
         StringField(id='bo1', label='1st backoffice field',
             type='string', varname='backoffice_blah'),
     ]
-    wf2 = assert_import_export_works(wf, True)
+    wf2 = assert_xml_import_export_works(wf, True)
 
 def test_complex_dispatch_action(pub):
     wf = Workflow(name='status')
@@ -485,7 +485,7 @@ def test_complex_dispatch_action(pub):
     st1.items.append(dispatch)
     dispatch.parent = st1
 
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert wf2.possible_status[0].items[0].variable == dispatch.variable
     assert wf2.possible_status[0].items[0].rules == dispatch.rules
     assert wf2.possible_status[0].items[0].dispatch_type == 'automatic'
@@ -512,7 +512,7 @@ def test_complex_dispatch_action(pub):
 
     # check rules are not exported with dispatch type is not automatic
     dispatch.dispatch_type = 'manual'
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert wf2.possible_status[0].items[0].dispatch_type == 'manual'
     assert not wf2.possible_status[0].items[0].rules
     xml_export = export_to_indented_xml(wf, include_id=True)
@@ -530,12 +530,12 @@ def test_display_message_action(pub):
     st1.items.append(display)
     display.parent = st1
 
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert wf2.possible_status[0].items[0].message == display.message
     for role_id in display.to:
         assert role_id in wf2.possible_status[0].items[0].to
 
-    wf2 = assert_import_export_works(wf, include_id=True)
+    wf2 = assert_xml_import_export_works(wf, include_id=True)
 
 def test_sendmail_other_destination(pub):
     wf = Workflow(name='status')
@@ -547,11 +547,11 @@ def test_sendmail_other_destination(pub):
     sendmail.parent = st1
 
     Role.wipe()
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert Role.count() == 0
 
     sendmail.to = ['_submitter', '=form_var_plop', '[form_var_plop]', '{{ form_var_plop }}', 'foobar@localhost']
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert Role.count() == 0
     assert wf2.possible_status[0].items[0].to == sendmail.to
 
@@ -564,11 +564,11 @@ def test_sendmail_attachments(pub):
     sendmail.parent = st1
 
     sendmail.attachments = ['form_var_file_raw', 'form_fbo1']
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert wf2.possible_status[0].items[0].attachments == sendmail.attachments
 
     sendmail.attachments = []
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert wf2.possible_status[0].items[0].attachments == []
 
 def test_sms(pub):
@@ -594,7 +594,7 @@ def test_criticality_level(pub):
         WorkflowCriticalityLevel(name='red', colour='FF0000'),
     ]
 
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     assert wf2.criticality_levels[0].name == 'green'
     assert wf2.criticality_levels[1].name == 'yellow'
 
@@ -629,7 +629,7 @@ def test_profile_action(pub):
     st1.items.append(item)
     item.parent = st1
 
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     item2 = wf2.possible_status[0].items[0]
     assert item2.fields == [{'field_id': '__email', 'value': '=form_var_foo'}]
 
@@ -643,7 +643,7 @@ def test_set_backoffice_fields_action(pub):
     st1.items.append(item)
     item.parent = st1
 
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
     item2 = wf2.possible_status[0].items[0]
     assert item2.fields == [{'field_id': 'bo1', 'value': '=form_var_foo'}]
 
@@ -655,11 +655,11 @@ def test_action_condition(pub):
     st1.items.append(sendmail)
     sendmail.parent = st1
 
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
 
     sendmail.condition = {}  # should not be created any longer
     wf2 = Workflow.import_from_xml_tree(wf.export_to_xml(False), False)
     assert wf2.possible_status[0].items[0].condition is None
 
     sendmail.condition = {'type': 'python', 'value': 'True'}
-    wf2 = assert_import_export_works(wf)
+    wf2 = assert_xml_import_export_works(wf)
-- 
2.23.0.rc1

