workflow: use uuid for variable field ids (#73656) #95
|
@ -1,6 +1,7 @@
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import uuid
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -1793,36 +1794,39 @@ def test_workflows_variables(pub):
|
||||||
|
|
||||||
# check it's been saved correctly
|
# check it's been saved correctly
|
||||||
assert 'foobar' in resp.text
|
assert 'foobar' in resp.text
|
||||||
assert len(Workflow.get(1).variables_formdef.fields) == 1
|
workflow = Workflow.get(1)
|
||||||
assert Workflow.get(1).variables_formdef.fields[0].key == 'string'
|
assert len(workflow.variables_formdef.fields) == 1
|
||||||
assert Workflow.get(1).variables_formdef.fields[0].label == 'foobar'
|
assert workflow.variables_formdef.fields[0].key == 'string'
|
||||||
|
assert workflow.variables_formdef.fields[0].label == 'foobar'
|
||||||
|
uuid.UUID(workflow.variables_formdef.fields[0].id) # no ValueError
|
||||||
|
|
||||||
|
|
||||||
def test_workflows_variables_edit(pub):
|
def test_workflows_variables_edit(pub):
|
||||||
test_workflows_variables(pub)
|
test_workflows_variables(pub)
|
||||||
|
workflow = Workflow.get(1)
|
||||||
|
|
||||||
app = login(get_app(pub))
|
app = login(get_app(pub))
|
||||||
resp = app.get('/backoffice/workflows/1/')
|
resp = app.get('/backoffice/workflows/1/')
|
||||||
resp = resp.click(href='variables/', index=0)
|
resp = resp.click(href='variables/', index=0)
|
||||||
assert resp.location == 'http://example.net/backoffice/workflows/1/variables/fields/'
|
assert resp.location == 'http://example.net/backoffice/workflows/1/variables/fields/'
|
||||||
resp = resp.follow()
|
resp = resp.follow()
|
||||||
resp = resp.click('Edit', href='1/')
|
resp = resp.click('Edit', href='%s/' % workflow.variables_formdef.fields[0].id)
|
||||||
assert resp.forms[0]['varname$name'].value == 'foobar'
|
assert resp.forms[0]['varname$name'].value == 'foobar'
|
||||||
assert 'varname$select' not in resp.forms[0].fields
|
assert 'varname$select' not in resp.forms[0].fields
|
||||||
|
|
||||||
workflow = Workflow.get(1)
|
|
||||||
baz_status = workflow.add_status(name='baz')
|
baz_status = workflow.add_status(name='baz')
|
||||||
baz_status.add_action('displaymsg')
|
baz_status.add_action('displaymsg')
|
||||||
workflow.store()
|
workflow.store()
|
||||||
|
|
||||||
resp = app.get('/backoffice/workflows/1/variables/fields/')
|
resp = app.get('/backoffice/workflows/1/variables/fields/')
|
||||||
resp = resp.click('Edit', href='1/')
|
resp = resp.click('Edit', href='%s/' % workflow.variables_formdef.fields[0].id)
|
||||||
assert 'varname$select' in resp.forms[0].fields
|
assert 'varname$select' in resp.forms[0].fields
|
||||||
resp.forms[0]['varname$select'].value = '1*1*message'
|
resp.forms[0]['varname$select'].value = '1*1*message'
|
||||||
resp = resp.forms[0].submit('submit')
|
resp = resp.forms[0].submit('submit')
|
||||||
|
|
||||||
assert Workflow.get(1).variables_formdef.fields[0].key == 'string'
|
workflow = Workflow.get(1)
|
||||||
assert Workflow.get(1).variables_formdef.fields[0].varname == '1*1*message'
|
assert workflow.variables_formdef.fields[0].key == 'string'
|
||||||
|
assert workflow.variables_formdef.fields[0].varname == '1*1*message'
|
||||||
|
|
||||||
|
|
||||||
def test_workflows_variables_edit_with_all_action_types(pub):
|
def test_workflows_variables_edit_with_all_action_types(pub):
|
||||||
|
@ -1848,14 +1852,16 @@ def test_workflows_variables_edit_with_all_action_types(pub):
|
||||||
assert resp.location == 'http://example.net/backoffice/workflows/1/variables/fields/'
|
assert resp.location == 'http://example.net/backoffice/workflows/1/variables/fields/'
|
||||||
resp = resp.follow()
|
resp = resp.follow()
|
||||||
|
|
||||||
|
workflow = Workflow.get(1)
|
||||||
resp = app.get('/backoffice/workflows/1/variables/fields/')
|
resp = app.get('/backoffice/workflows/1/variables/fields/')
|
||||||
resp = resp.click('Edit', href='1/')
|
resp = resp.click('Edit', href='%s/' % workflow.variables_formdef.fields[0].id)
|
||||||
assert 'varname$select' in resp.forms[0].fields
|
assert 'varname$select' in resp.forms[0].fields
|
||||||
resp.forms[0]['varname$name'].value = 'xxx'
|
resp.forms[0]['varname$name'].value = 'xxx'
|
||||||
resp = resp.forms[0].submit('submit')
|
resp = resp.forms[0].submit('submit')
|
||||||
|
|
||||||
assert Workflow.get(1).variables_formdef.fields[0].key == 'string'
|
workflow = Workflow.get(1)
|
||||||
assert Workflow.get(1).variables_formdef.fields[0].varname == 'xxx'
|
assert workflow.variables_formdef.fields[0].key == 'string'
|
||||||
|
assert workflow.variables_formdef.fields[0].varname == 'xxx'
|
||||||
|
|
||||||
|
|
||||||
def test_workflows_variables_delete(pub):
|
def test_workflows_variables_delete(pub):
|
||||||
|
@ -1932,7 +1938,7 @@ def test_workflows_variables_with_export_to_model_action(pub):
|
||||||
|
|
||||||
app = login(get_app(pub))
|
app = login(get_app(pub))
|
||||||
resp = app.get('/backoffice/workflows/1/variables/fields/')
|
resp = app.get('/backoffice/workflows/1/variables/fields/')
|
||||||
resp = resp.click('Edit', href='1/')
|
resp = resp.click('Edit', href='%s/' % workflow.variables_formdef.fields[0].id)
|
||||||
|
|
||||||
|
|
||||||
def test_workflows_export_to_model_in_status(pub):
|
def test_workflows_export_to_model_in_status(pub):
|
||||||
|
@ -1990,9 +1996,10 @@ def test_workflows_variables_replacement(pub):
|
||||||
resp.forms[0]['label'] = 'foobar'
|
resp.forms[0]['label'] = 'foobar'
|
||||||
resp.forms[0]['type'] = 'string'
|
resp.forms[0]['type'] = 'string'
|
||||||
resp = resp.forms[0].submit().follow()
|
resp = resp.forms[0].submit().follow()
|
||||||
|
workflow = Workflow.get(1)
|
||||||
|
|
||||||
# edit
|
# edit
|
||||||
resp = resp.click('Edit', href='1/')
|
resp = resp.click('Edit', href='%s/' % workflow.variables_formdef.fields[0].id)
|
||||||
resp.form['varname$select'].value = '1*1*message'
|
resp.form['varname$select'].value = '1*1*message'
|
||||||
resp = resp.form.submit('submit').follow()
|
resp = resp.form.submit('submit').follow()
|
||||||
|
|
||||||
|
|
|
@ -576,7 +576,6 @@ class WorkflowVariablesFieldsFormDef(FormDef):
|
||||||
self.readonly = True
|
self.readonly = True
|
||||||
if workflow.variables_formdef and workflow.variables_formdef.fields:
|
if workflow.variables_formdef and workflow.variables_formdef.fields:
|
||||||
self.fields = self.workflow.variables_formdef.fields
|
self.fields = self.workflow.variables_formdef.fields
|
||||||
self.max_field_id = max(lax_int(x.id) for x in self.fields or [])
|
|
||||||
else:
|
else:
|
||||||
self.fields = []
|
self.fields = []
|
||||||
|
|
||||||
|
@ -588,6 +587,9 @@ class WorkflowVariablesFieldsFormDef(FormDef):
|
||||||
base_url = get_publisher().get_backoffice_url()
|
base_url = get_publisher().get_backoffice_url()
|
||||||
return '%s/workflows/%s/variables/fields/' % (base_url, self.workflow.id)
|
return '%s/workflows/%s/variables/fields/' % (base_url, self.workflow.id)
|
||||||
|
|
||||||
|
def get_new_field_id(self):
|
||||||
|
return str(uuid.uuid4())
|
||||||
|
|
||||||
def store(self, comment=None, *args, **kwargs):
|
def store(self, comment=None, *args, **kwargs):
|
||||||
for field in self.fields:
|
for field in self.fields:
|
||||||
if hasattr(field, 'widget_class'):
|
if hasattr(field, 'widget_class'):
|
||||||
|
|
Loading…
Reference in New Issue