571 |
571 |
fields.DateField(id='3', label='date', varname='datefield'),
|
572 |
572 |
fields.ItemsField(id='4', label='items', items=['aa', 'ab', 'ac'], varname='itemsfield'),
|
573 |
573 |
fields.FileField(id='5', label='file', varname='filefield'),
|
|
574 |
fields.StringField(id='6', label='string2', varname='foo_foo_baz_baz'),
|
574 |
575 |
]
|
575 |
576 |
formdef.workflow_roles = {'_receiver': role.id}
|
576 |
577 |
formdef.geolocations = {'base': 'Base'}
|
... | ... | |
587 |
588 |
'4': ['aa', 'ac'],
|
588 |
589 |
'4_display': 'aa, ac',
|
589 |
590 |
'5': PicklableUpload('test.txt', 'text/plain'),
|
|
591 |
'6': 'other',
|
590 |
592 |
}
|
591 |
593 |
formdata.data['5'].receive(['hello world'])
|
592 |
594 |
formdata.geolocations = {'base': {'lat': 1, 'lon': 2}}
|
... | ... | |
645 |
647 |
assert context['form_var_foo_foo'] + 'ab' == 'barab'
|
646 |
648 |
for item in enumerate(context['form_var_foo_foo']):
|
647 |
649 |
assert item in [(0, 'b'), (1, 'a'), (2, 'r')]
|
|
650 |
assert context['form_var_foo_foo_baz_baz'] == 'other'
|
|
651 |
|
|
652 |
def test_lazy_variables_missing(pub, variable_test_data):
|
|
653 |
formdef = FormDef.select()[0]
|
|
654 |
formdata = formdef.data_class()()
|
|
655 |
formdata.just_created()
|
|
656 |
formdata.data = {
|
|
657 |
'0': 'bar',
|
|
658 |
}
|
|
659 |
pub.substitutions.reset()
|
|
660 |
pub.substitutions.feed(formdef)
|
|
661 |
pub.substitutions.feed(formdata)
|
|
662 |
for mode in (None, 'lazy'):
|
|
663 |
context = pub.substitutions.get_context_variables(mode=mode)
|
|
664 |
assert context['form_var_foo_foo_baz_baz'] is None
|
|
665 |
assert context['form_var_foo_foo'] == 'bar'
|
|
666 |
with pytest.raises(KeyError):
|
|
667 |
assert context['form_var_foo_foo_xxx'] == 'bar'
|
648 |
668 |
|
649 |
669 |
def test_lazy_conditions(pub, variable_test_data):
|
650 |
670 |
condition = Condition({'type': 'django', 'value': 'form_var_foo_foo == "bar"'})
|
... | ... | |
671 |
691 |
condition = Condition({'type': 'django', 'value': 'form_user_backoffice_access'})
|
672 |
692 |
assert condition.evaluate() is False
|
673 |
693 |
|
|
694 |
condition = Condition({'type': 'python', 'value':
|
|
695 |
'vars().get("form_var_foo_foo_xxx", "") == ""'})
|
|
696 |
assert condition.evaluate() is True
|
|
697 |
|
674 |
698 |
user = pub.user_class.select()[0]
|
675 |
699 |
user.is_admin = True
|
676 |
700 |
user.store()
|