From 600a30e5a8d1dc6d23e4f9423b37c2830d34f29b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 30 Oct 2018 09:44:29 +0100 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(-) diff --git a/tests/test_form_pages.py b/tests/test_form_pages.py index ae8557880..63b721231 100644 --- a/tests/test_form_pages.py +++ b/tests/test_form_pages.py @@ -5261,6 +5261,31 @@ def test_field_condition(pub): assert 'Bar' in resp.body assert 'Foo' not in resp.body +def test_field_unicode_condition(pub): + FormDef.wipe() + formdef = FormDef() + formdef.name = 'Foo' + formdef.fields = [ + fields.PageField(id='0', label='2nd page', type='page'), + fields.StringField(type='string', id='1', label='Bar', size='40', + required=True, varname='bar'), + fields.PageField(id='3', label='1st page', type='page'), + fields.StringField(type='string', id='4', label='Baz', size='40', + required=True, varname='baz', + condition={'type': 'django', 'value': 'form_var_bar == "éléphant"'}), + ] + formdef.store() + + resp = get_app(pub).get('/foo/') + resp.form['f1'] = 'hello' + resp = resp.form.submit('submit') + assert not 'f4' in resp.form.fields + + resp = get_app(pub).get('/foo/') + resp.form['f1'] = 'éléphant' + resp = resp.form.submit('submit') + assert 'f4' in resp.form.fields + def test_field_live_condition(pub): FormDef.wipe() formdef = FormDef() diff --git a/wcs/variables.py b/wcs/variables.py index 01384a868..71a25b227 100644 --- a/wcs/variables.py +++ b/wcs/variables.py @@ -360,7 +360,7 @@ class LazyFieldVar(object): return unicode(str(self), get_publisher().site_charset) def __eq__(self, other): - return str(self) == str(other) + return unicode(self) == unicode(other) def __getitem__(self, key): if isinstance(key, int): -- 2.19.1