5040 |
5040 |
assert card.data['bo0'] == '1' # got called
|
5041 |
5041 |
|
5042 |
5042 |
|
|
5043 |
def test_call_external_workflow_use_caller_variable(pub):
|
|
5044 |
FormDef.wipe()
|
|
5045 |
CardDef.wipe()
|
|
5046 |
LoggedError.wipe()
|
|
5047 |
|
|
5048 |
# carddef workflow, with global action to set a value in a backoffice field
|
|
5049 |
carddef_wf = Workflow(name='Carddef Workflow')
|
|
5050 |
carddef_wf.backoffice_fields_formdef = WorkflowBackofficeFieldsFormDef(carddef_wf)
|
|
5051 |
carddef_wf.backoffice_fields_formdef.fields = [
|
|
5052 |
StringField(id='bo0', varname='bo', type='string', label='bo variable'),
|
|
5053 |
]
|
|
5054 |
global_action = carddef_wf.add_global_action('Update')
|
|
5055 |
global_action.append_item('set-backoffice-fields')
|
|
5056 |
setbo = global_action.items[0]
|
|
5057 |
setbo.fields = [{'field_id': 'bo0',
|
|
5058 |
'value': '{{ caller_form_var_email }}'}]
|
|
5059 |
trigger = global_action.append_trigger('webservice')
|
|
5060 |
trigger.identifier = 'update'
|
|
5061 |
carddef_wf.store()
|
|
5062 |
|
|
5063 |
# associated carddef
|
|
5064 |
carddef = CardDef()
|
|
5065 |
carddef.name = 'Data'
|
|
5066 |
carddef.fields = [
|
|
5067 |
StringField(id='0', label='string', varname='card_string'),
|
|
5068 |
]
|
|
5069 |
carddef.workflow = carddef_wf
|
|
5070 |
carddef.store()
|
|
5071 |
|
|
5072 |
# and sample carddata
|
|
5073 |
carddata = carddef.data_class()()
|
|
5074 |
carddata.data = {'0': 'Text'}
|
|
5075 |
carddata.store()
|
|
5076 |
|
|
5077 |
# formdef workflow that will trigger the global action
|
|
5078 |
wf = Workflow(name='External actions')
|
|
5079 |
wf.add_status('Action')
|
|
5080 |
|
|
5081 |
update_global_action = wf.add_global_action('Update linked object data')
|
|
5082 |
update_action = update_global_action.append_item('external_workflow_global_action')
|
|
5083 |
update_action.slug = 'carddef:%s' % carddef.url_name
|
|
5084 |
update_action.trigger_id = 'action:update'
|
|
5085 |
wf.store()
|
|
5086 |
|
|
5087 |
# associated formdef
|
|
5088 |
formdef = FormDef()
|
|
5089 |
formdef.name = 'External action form'
|
|
5090 |
formdef.fields = [EmailField(id='1', label='Email', varname='email')]
|
|
5091 |
formdef.workflow = wf
|
|
5092 |
formdef.store()
|
|
5093 |
|
|
5094 |
# and formdata
|
|
5095 |
formdata = formdef.data_class()()
|
|
5096 |
formdata.data = {'1': 'foo@example.com'}
|
|
5097 |
formdata.store()
|
|
5098 |
formdata.just_created()
|
|
5099 |
formdata.perform_workflow()
|
|
5100 |
|
|
5101 |
# run, against no parent
|
|
5102 |
perform_items([update_action], formdata)
|
|
5103 |
card = carddef.data_class().get(carddata.id)
|
|
5104 |
assert 'bo0' not in card.data # not called
|
|
5105 |
|
|
5106 |
# appropriate parent
|
|
5107 |
formdata.submission_context = {
|
|
5108 |
'orig_object_type': 'carddef',
|
|
5109 |
'orig_formdata_id': str(carddata.id),
|
|
5110 |
'orig_formdef_id': str(carddef.id),
|
|
5111 |
}
|
|
5112 |
formdata.store()
|
|
5113 |
perform_items([update_action], formdata)
|
|
5114 |
card = carddef.data_class().get(carddata.id)
|
|
5115 |
assert card.data['bo0'] == 'foo@example.com' # got called
|
|
5116 |
|
|
5117 |
|
5043 |
5118 |
def test_edit_carddata_with_data_sourced_object(pub):
|
5044 |
5119 |
FormDef.wipe()
|
5045 |
5120 |
CardDef.wipe()
|