0001-misc-don-t-create-subvariables-for-strings-53641.patch
tests/form_pages/test_computed_field.py | ||
---|---|---|
5 | 5 | |
6 | 6 |
from wcs import fields |
7 | 7 |
from wcs.formdef import FormDef |
8 |
from wcs.qommon.substitution import CompatibilityNamesDict |
|
8 | 9 |
from wcs.wscalls import NamedWsCall |
9 | 10 | |
10 | 11 |
from ..utilities import clean_temporary_pub, create_temporary_pub, get_app, login |
... | ... | |
353 | 354 |
resp.form['f0'] = 'hello' |
354 | 355 |
live_resp = app.post('/test/live', params=resp.form.submit_fields()) |
355 | 356 |
assert live_resp.json['result']['2']['content'] == '<p>XxxxYhelloZ</p>' |
357 | ||
358 | ||
359 |
def test_computed_field_inspect_keys(pub): |
|
360 |
create_user(pub) |
|
361 | ||
362 |
FormDef.wipe() |
|
363 |
formdef = FormDef() |
|
364 |
formdef.name = 'test' |
|
365 |
formdef.fields = [ |
|
366 |
fields.ComputedField(id='1', label='computed', varname='computed', value_template='{{ "xxx" }}'), |
|
367 |
] |
|
368 |
formdef.store() |
|
369 |
formdef.data_class().wipe() |
|
370 | ||
371 |
formdata = formdef.data_class()() |
|
372 |
formdata.data = {'1': 'xxx'} |
|
373 | ||
374 |
substvars = CompatibilityNamesDict() |
|
375 |
substvars.update(formdata.get_substitution_variables()) |
|
376 |
assert 'form_var_computed' in substvars.get_flat_keys() |
|
377 |
assert substvars['form_var_computed'] == 'xxx' |
|
378 | ||
379 |
formdata.data = {'1': {'foo': 'bar'}} |
|
380 |
assert 'form_var_computed_foo' in substvars.get_flat_keys() |
|
381 |
assert substvars['form_var_computed_foo'] == 'bar' |
wcs/variables.py | ||
---|---|---|
800 | 800 |
if isinstance(structured_value, list): |
801 | 801 |
for i, value in enumerate(structured_value): |
802 | 802 |
walk(str(i), value) |
803 |
else:
|
|
803 |
elif isinstance(structured_value, dict):
|
|
804 | 804 |
walk('', structured_value) |
805 | 805 | |
806 | 806 |
return keys |
807 |
- |