Projet

Général

Profil

0001-tests-make-field-conditions-work-with-unicode-string.patch

Frédéric Péters, 30 octobre 2018 10:07

Télécharger (2,15 ko)

Voir les différences:

Subject: [PATCH] tests: make field conditions work with unicode strings
 (#27664)

 tests/test_form_pages.py | 25 +++++++++++++++++++++++++
 wcs/variables.py         |  2 +-
 2 files changed, 26 insertions(+), 1 deletion(-)
tests/test_form_pages.py
5261 5261
    assert '<span class="label">Bar</span>' in resp.body
5262 5262
    assert '<span class="label">Foo</span>' not in resp.body
5263 5263

  
5264
def test_field_unicode_condition(pub):
5265
    FormDef.wipe()
5266
    formdef = FormDef()
5267
    formdef.name = 'Foo'
5268
    formdef.fields = [
5269
        fields.PageField(id='0', label='2nd page', type='page'),
5270
        fields.StringField(type='string', id='1', label='Bar', size='40',
5271
            required=True, varname='bar'),
5272
        fields.PageField(id='3', label='1st page', type='page'),
5273
        fields.StringField(type='string', id='4', label='Baz', size='40',
5274
            required=True, varname='baz',
5275
            condition={'type': 'django', 'value': 'form_var_bar == "éléphant"'}),
5276
    ]
5277
    formdef.store()
5278

  
5279
    resp = get_app(pub).get('/foo/')
5280
    resp.form['f1'] = 'hello'
5281
    resp = resp.form.submit('submit')
5282
    assert not 'f4' in resp.form.fields
5283

  
5284
    resp = get_app(pub).get('/foo/')
5285
    resp.form['f1'] = 'éléphant'
5286
    resp = resp.form.submit('submit')
5287
    assert 'f4' in resp.form.fields
5288

  
5264 5289
def test_field_live_condition(pub):
5265 5290
    FormDef.wipe()
5266 5291
    formdef = FormDef()
wcs/variables.py
360 360
        return unicode(str(self), get_publisher().site_charset)
361 361

  
362 362
    def __eq__(self, other):
363
        return str(self) == str(other)
363
        return unicode(self) == unicode(other)
364 364

  
365 365
    def __getitem__(self, key):
366 366
        if isinstance(key, int):
367
-