tests: use publisher fixture in import/export workflow tests

This commit is contained in:
Frédéric Péters 2017-07-04 12:50:56 +02:00
parent 26ffeaf271
commit 30b71b3919
1 changed files with 33 additions and 35 deletions

View File

@ -1,3 +1,4 @@
import pytest
import sys
import shutil
import StringIO
@ -19,17 +20,14 @@ from wcs.fields import StringField
from qommon.misc import indent_xml as indent
from utilities import create_temporary_pub
def setup_module(module):
cleanup()
global pub
pub = create_temporary_pub()
from utilities import create_temporary_pub, clean_temporary_pub
@pytest.fixture
def pub(request):
return create_temporary_pub()
def teardown_module(module):
shutil.rmtree(pub.APP_DIR)
clean_temporary_pub()
def export_to_indented_xml(workflow, include_id=False):
workflow_xml = workflow.export_to_xml(include_id=include_id)
@ -41,17 +39,17 @@ def assert_import_export_works(wf, include_id=False):
assert ET.tostring(export_to_indented_xml(wf)) == ET.tostring(export_to_indented_xml(wf2))
return wf2
def test_empty():
def test_empty(pub):
wf = Workflow(name='empty')
assert_import_export_works(wf)
def test_status():
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)
def test_status_actions():
def test_status_actions(pub):
wf = Workflow(name='status')
st1 = wf.add_status('Status1', 'st1')
st2 = wf.add_status('Status2', 'st2')
@ -64,7 +62,7 @@ def test_status_actions():
assert_import_export_works(wf)
def test_status_colour_css_class():
def test_status_colour_css_class(pub):
wf = Workflow(name='status')
st1 = wf.add_status('Status1', 'st1')
st1.extra_css_class = 'hello'
@ -72,12 +70,12 @@ def test_status_colour_css_class():
st2 = wf.add_status('Status2', 'st2')
assert_import_export_works(wf)
def test_default_wf():
def test_default_wf(pub):
wf = Workflow.get_default_workflow()
assert_import_export_works(wf)
def test_action_dispatch():
def test_action_dispatch(pub):
wf = Workflow(name='status')
st1 = wf.add_status('Status1', 'st1')
@ -102,7 +100,7 @@ def test_action_dispatch():
assert(wf2.possible_status[0].items[0].role_id == '5')
def test_status_actions_named_role():
def test_status_actions_named_role(pub):
wf = Workflow(name='status')
st1 = wf.add_status('Status1', 'st1')
st2 = wf.add_status('Status2', 'st2')
@ -116,7 +114,7 @@ def test_status_actions_named_role():
assert_import_export_works(wf)
def test_status_actions_named_existing_role():
def test_status_actions_named_existing_role(pub):
role = Role()
role.id = '2'
role.name = 'Test Role named existing role'
@ -145,7 +143,7 @@ def test_status_actions_named_existing_role():
assert wf3.possible_status[0].items[0].by == ['2']
def test_status_actions_named_missing_role():
def test_status_actions_named_missing_role(pub):
role = Role()
role.id = '3'
role.name = 'Test Role A'
@ -198,7 +196,7 @@ def test_status_actions_named_missing_role():
assert wf3.possible_status[0].items[0].by == ['3']
def test_display_form_action():
def test_display_form_action(pub):
wf = Workflow(name='status')
st1 = wf.add_status('Status1', 'st1')
@ -217,7 +215,7 @@ def test_display_form_action():
assert wf2.possible_status[0].items[0].formdef.max_field_id == len(display_form.formdef.fields)
def test_export_to_model_action():
def test_export_to_model_action(pub):
wf = Workflow(name='status')
wf.store()
st1 = wf.add_status('Status1', 'st1')
@ -250,7 +248,7 @@ def test_export_to_model_action():
upload.fp = StringIO.StringIO()
upload.fp.write(file_content)
upload.fp.seek(0)
export_to.model_file = UploadedFile(publisher.WcsPublisher.APP_DIR, None, upload)
export_to.model_file = UploadedFile(pub.APP_DIR, None, upload)
st1.items = [export_to]
export_to.parent = st1
wf2 = assert_import_export_works(wf)
@ -266,14 +264,14 @@ def test_export_to_model_action():
wf3.possible_status[0].items[0].model_file.filename
def test_export_roles():
def test_export_roles(pub):
wf = Workflow(name='roles')
wf.roles = {'foo': 'Bar'}
wf2 = assert_import_export_works(wf)
assert wf2.roles == wf.roles
def test_jump_action():
def test_jump_action(pub):
wf = Workflow(name='status')
st1 = wf.add_status('Status1', 'st1')
st2 = wf.add_status('Status2', 'st2')
@ -295,7 +293,7 @@ def test_jump_action():
assert wf2.possible_status[0].items[0].timeout == 1200
def test_commentable_action():
def test_commentable_action(pub):
wf = Workflow(name='status')
st1 = wf.add_status('Status1', 'st1')
@ -310,7 +308,7 @@ def test_commentable_action():
assert wf2.possible_status[0].items[0].button_label is None
def test_variables_formdef():
def test_variables_formdef(pub):
wf = Workflow(name='variables')
from wcs.workflows import WorkflowVariablesFieldsFormDef
wf.variables_formdef = WorkflowVariablesFieldsFormDef(workflow=wf)
@ -318,7 +316,7 @@ def test_variables_formdef():
wf2 = assert_import_export_works(wf)
assert wf2.variables_formdef.fields[0].label == 'Test'
def test_wscall_action():
def test_wscall_action(pub):
wf = Workflow(name='status')
st1 = wf.add_status('Status1', 'st1')
@ -342,7 +340,7 @@ def test_wscall_action():
assert wscall2.post_data == {'one': '1', 'two': '=2', 'good:name': 'ok'}
assert wscall2.qs_data == {'one': '2', 'two': '=3', 'good:name': 'ok'}
def test_backoffice_info_text():
def test_backoffice_info_text(pub):
wf = Workflow(name='info texts')
st1 = wf.add_status('Status1', 'st1')
st1.backoffice_info_text = '<p>Foo</p>'
@ -358,7 +356,7 @@ def test_backoffice_info_text():
assert wf2.possible_status[0].backoffice_info_text == '<p>Foo</p>'
assert wf2.possible_status[0].items[0].backoffice_info_text == '<p>Bar</p>'
def test_global_actions():
def test_global_actions(pub):
role = Role()
role.id = '5'
role.name = 'Test Role'
@ -383,7 +381,7 @@ def test_global_actions():
wf2 = assert_import_export_works(wf, True)
def test_backoffice_fields():
def test_backoffice_fields(pub):
wf = Workflow(name='bo fields')
wf.backoffice_fields_formdef = WorkflowBackofficeFieldsFormDef(wf)
wf.backoffice_fields_formdef.fields = [
@ -392,7 +390,7 @@ def test_backoffice_fields():
]
wf2 = assert_import_export_works(wf, True)
def test_complex_dispatch_action():
def test_complex_dispatch_action(pub):
wf = Workflow(name='status')
st1 = wf.add_status('Status1', 'st1')
@ -442,7 +440,7 @@ def test_complex_dispatch_action():
assert wf2.possible_status[0].items[0].dispatch_type == 'automatic'
def test_display_message_action():
def test_display_message_action(pub):
wf = Workflow(name='status')
st1 = wf.add_status('Status1', 'st1')
@ -461,7 +459,7 @@ def test_display_message_action():
wf2 = assert_import_export_works(wf, include_id=True)
def test_sendmail_other_destination():
def test_sendmail_other_destination(pub):
wf = Workflow(name='status')
st1 = wf.add_status('Status1', 'st1')
@ -479,7 +477,7 @@ def test_sendmail_other_destination():
assert Role.count() == 0
assert wf2.possible_status[0].items[0].to == sendmail.to
def test_criticality_level():
def test_criticality_level(pub):
wf = Workflow(name='criticality level')
wf.criticality_levels = [
WorkflowCriticalityLevel(name='green'),
@ -491,7 +489,7 @@ def test_criticality_level():
assert wf2.criticality_levels[0].name == 'green'
assert wf2.criticality_levels[1].name == 'yellow'
def test_global_timeout_trigger():
def test_global_timeout_trigger(pub):
wf = Workflow(name='global actions')
ac1 = wf.add_global_action('Action', 'ac1')
trigger = ac1.append_trigger('timeout')
@ -503,7 +501,7 @@ def test_global_timeout_trigger():
assert wf2.global_actions[0].triggers[-1].anchor == trigger.anchor
def test_profile_action():
def test_profile_action(pub):
wf = Workflow(name='status')
st1 = wf.add_status('Status1', 'st1')
@ -517,7 +515,7 @@ def test_profile_action():
item2 = wf2.possible_status[0].items[0]
assert item2.fields == [{'field_id': '__email', 'value': '=form_var_foo'}]
def test_set_backoffice_fields_action():
def test_set_backoffice_fields_action(pub):
wf = Workflow(name='status')
st1 = wf.add_status('Status1', 'st1')