0001-workflows-make-computed-fields-support-both-ezt-and-.patch
tests/test_workflows.py | ||
---|---|---|
103 | 103 |
assert root['statuses'][1]['forced_endpoint'] is True |
104 | 104 |
assert root['statuses'][1]['endpoint'] is True |
105 | 105 | |
106 |
def test_variable_compute(pub): |
|
107 |
FormDef.wipe() |
|
108 |
formdef = FormDef() |
|
109 |
formdef.name = 'foobar' |
|
110 |
formdef.fields = [StringField(id='1', label='Test', type='string', varname='foo'),] |
|
111 |
formdef.store() |
|
112 | ||
113 |
formdata = formdef.data_class()() |
|
114 |
formdata.data = {'1': 'hello'} |
|
115 |
formdata.store() |
|
116 |
pub.substitutions.feed(formdata) |
|
117 | ||
118 |
item = JumpWorkflowStatusItem() |
|
119 | ||
120 |
# straight string |
|
121 |
assert item.compute('blah') == 'blah' |
|
122 | ||
123 |
# ezt string |
|
124 |
assert item.compute('[form_var_foo]') == 'hello' |
|
125 |
# ezt string, but not ezt asked |
|
126 |
assert item.compute('[form_var_foo]', do_ezt=False) == '[form_var_foo]' |
|
127 |
# ezt string, with an error |
|
128 |
assert item.compute('[end]', raises=False) == '[end]' |
|
129 |
with pytest.raises(Exception): |
|
130 |
item.compute('[end]', raises=True) |
|
131 | ||
132 |
# python expression |
|
133 |
assert item.compute('=form_var_foo') == 'hello' |
|
134 |
# python expression, with an error |
|
135 |
assert item.compute('=1/0', raises=False) == '=1/0' |
|
136 |
with pytest.raises(Exception): |
|
137 |
item.compute('=1/0', raises=True) |
|
138 | ||
106 | 139 |
def test_jump_nothing(pub): |
107 | 140 |
FormDef.wipe() |
108 | 141 |
formdef = FormDef() |
... | ... | |
171 | 204 |
formdef.name = 'foobar' |
172 | 205 |
formdef.store() |
173 | 206 |
pub.substitutions.feed(formdef) |
207 |
formdef.data_class().wipe() |
|
174 | 208 |
formdata = formdef.data_class()() |
175 | 209 |
item = JumpWorkflowStatusItem() |
176 | 210 |
item.condition = 'form_objects.count < 2' |
wcs/workflows.py | ||
---|---|---|
1484 | 1484 |
value = getattr(self, '%s_parse' % f)(value) |
1485 | 1485 |
setattr(self, f, value) |
1486 | 1486 | |
1487 |
def compute(self, var, raises=False): |
|
1487 |
def compute(self, var, do_ezt=True, raises=False):
|
|
1488 | 1488 |
if not isinstance(var, basestring): |
1489 | 1489 |
return var |
1490 |
if not var.startswith('='): |
|
1490 | ||
1491 |
if not var.startswith('=') and not do_ezt: |
|
1491 | 1492 |
return var |
1493 | ||
1492 | 1494 |
vars = get_publisher().substitutions.get_context_variables() |
1495 |
if not var.startswith('='): |
|
1496 |
try: |
|
1497 |
processor = ezt.Template(compress_whitespace=False) |
|
1498 |
processor.parse(var) |
|
1499 |
fd = StringIO() |
|
1500 |
processor.generate(fd, vars) |
|
1501 |
return fd.getvalue() |
|
1502 |
except ezt.EZTException: |
|
1503 |
if raises: |
|
1504 |
raise |
|
1505 |
return var |
|
1506 | ||
1493 | 1507 |
try: |
1494 | 1508 |
return eval(var[1:], get_publisher().get_global_eval_dict(), vars) |
1495 | 1509 |
except: |
... | ... | |
1877 | 1891 | |
1878 | 1892 |
url = formdata.get_url() |
1879 | 1893 |
try: |
1880 |
mail_body = template_on_formdata(formdata, self.compute(self.body)) |
|
1894 |
mail_body = template_on_formdata(formdata, self.compute(self.body, do_ezt=False))
|
|
1881 | 1895 |
except ezt.EZTException: |
1882 | 1896 |
get_logger().error('error in template for email body [%s], mail could not be generated' % url) |
1883 | 1897 |
return |
1884 | 1898 | |
1885 | 1899 |
try: |
1886 |
mail_subject = template_on_formdata(formdata, self.compute(self.subject)) |
|
1900 |
mail_subject = template_on_formdata(formdata, self.compute(self.subject, do_ezt=False))
|
|
1887 | 1901 |
except ezt.EZTException: |
1888 | 1902 |
get_logger().error('error in template for email subject [%s], mail could not be generated' % url) |
1889 | 1903 |
return |
... | ... | |
2052 | 2066 |
return |
2053 | 2067 | |
2054 | 2068 |
try: |
2055 |
sms_body = template_on_formdata(formdata, self.compute(self.body)) |
|
2069 |
sms_body = template_on_formdata(formdata, self.compute(self.body, do_ezt=False))
|
|
2056 | 2070 |
except ezt.EZTException: |
2057 | 2071 |
url = formdata.get_url() |
2058 | 2072 |
get_logger().error('error in template for sms [%s], sms could not be generated' % url) |
2059 |
- |