1182 |
1182 |
|
1183 |
1183 |
formdef = FormDef()
|
1184 |
1184 |
formdef.name = 'test global action'
|
1185 |
|
formdef.fields = []
|
1186 |
|
|
|
1185 |
formdef.fields = [
|
|
1186 |
fields.StringField(id='1', label='1st field', type='string', varname='foo'),
|
|
1187 |
]
|
1187 |
1188 |
workflow = Workflow.get_default_workflow()
|
1188 |
1189 |
workflow.id = '2'
|
1189 |
1190 |
action = workflow.add_global_action('FOOBAR')
|
... | ... | |
1196 |
1197 |
form_action.varname = 'blah'
|
1197 |
1198 |
form_action.formdef = WorkflowFormFieldsFormDef(item=form_action)
|
1198 |
1199 |
form_action.formdef.fields.append(
|
1199 |
|
fields.StringField(id='1', label='Test', varname='test', type='string', required=True)
|
|
1200 |
fields.StringField(
|
|
1201 |
id='1',
|
|
1202 |
label='Test',
|
|
1203 |
varname='test',
|
|
1204 |
type='string',
|
|
1205 |
required=True,
|
|
1206 |
prefill={'type': 'string', 'value': 'a{{form_var_foo}}b'},
|
|
1207 |
),
|
1200 |
1208 |
)
|
1201 |
1209 |
register_comment = action.add_action('register-comment')
|
1202 |
1210 |
register_comment.comment = 'HELLO {{ form_workflow_form_blah_var_test }}'
|
1203 |
1211 |
trigger = action.triggers[0]
|
1204 |
1212 |
trigger.roles = [x.id for x in pub.role_class.select() if x.name == 'foobar']
|
1205 |
1213 |
|
|
1214 |
button1 = action.add_action('choice')
|
|
1215 |
button1.label = 'button1'
|
|
1216 |
button1.condition = {'type': 'django', 'value': 'form_var_foo != "plop"'}
|
|
1217 |
|
|
1218 |
button2 = action.add_action('choice')
|
|
1219 |
button2.label = 'button2'
|
|
1220 |
button2.condition = {'type': 'django', 'value': 'form_var_foo == "plop"'}
|
|
1221 |
|
1206 |
1222 |
workflow.store()
|
1207 |
1223 |
formdef.workflow_id = workflow.id
|
1208 |
1224 |
formdef.workflow_roles = {'_receiver': 1}
|
1209 |
1225 |
formdef.store()
|
1210 |
1226 |
|
1211 |
1227 |
formdata = formdef.data_class()()
|
|
1228 |
formdata.data = {'1': 'plop'}
|
1212 |
1229 |
formdata.just_created()
|
1213 |
1230 |
formdata.store()
|
1214 |
1231 |
|
... | ... | |
1220 |
1237 |
resp = resp.follow() # -> back to form
|
1221 |
1238 |
assert 'Error: empty action' in resp.text
|
1222 |
1239 |
|
|
1240 |
button1.by = trigger.roles
|
|
1241 |
button2.by = trigger.roles
|
1223 |
1242 |
form_action.by = trigger.roles
|
1224 |
1243 |
workflow.store()
|
1225 |
1244 |
|
... | ... | |
1227 |
1246 |
resp = resp.form.submit('button-action-1')
|
1228 |
1247 |
resp = resp.follow()
|
1229 |
1248 |
assert 'This is a message' in resp.text
|
|
1249 |
assert resp.form['fblah_1'].value == 'aplopb' # field was prefilled
|
|
1250 |
resp.form['fblah_1'] = ''
|
|
1251 |
assert not resp.pyquery('button[value="button1"]') # not displayed
|
|
1252 |
assert resp.pyquery('button[value="button2"]') # displayed
|
1230 |
1253 |
resp = resp.form.submit('submit')
|
|
1254 |
# error as the field was empty
|
1231 |
1255 |
assert resp.pyquery('#form_error_fblah_1').text() == 'required field'
|
1232 |
1256 |
resp.form['fblah_1'] = 'GLOBAL INTERACTIVE ACTION'
|
1233 |
1257 |
resp = resp.form.submit('submit')
|