# HG changeset patch # User Sylvain Thénault # Date 1243598862 -7200 # Node ID ea9eab290dcda8be636c60eedccb5308d9c861ca # Parent e194335569d1acaee6c1fdf2a011ab77993ac2d7 tests broken; module deprecated; remove tests diff -r e194335569d1 -r ea9eab290dcd web/test/unittest_widgets.py --- a/web/test/unittest_widgets.py Fri May 29 14:04:26 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,375 +0,0 @@ -"""cubicweb.common.widget unit tests - -:organization: Logilab -:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. -:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr -:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses -""" - -from datetime import datetime -NOW = datetime.now() - -from logilab.common.testlib import unittest_main -from cubicweb.devtools.apptest import EnvBasedTC - -from cubicweb.common.mttransforms import HAS_TAL -from cubicweb.web.widgets import widget, AutoCompletionWidget - - -class WidgetsTC(EnvBasedTC): - - def get_widget(self, etype, rname, rtype): - rschema = self.schema[rname] - return widget(self.vreg, etype, rschema, rtype, role='subject') - - - def test_hidden_widget(self): - w = self.get_widget('State', 'eid', 'Int') - self.assertEquals(w.name, 'eid') - self.assertEquals(w.render_example(self.request()), '') - self.assertDictEquals(w.attrs, {}) - entity = self.etype_instance('State') - entity.eid = 'X' - self.assertEquals(w.required(entity), True) - self.assertEquals(w.render(entity), '') - self.assertEquals(w.edit_render(entity), - u'') - - def test_textarea_widget(self): - self.add_entity('CWProperty', pkey=u'ui.fckeditor', value=u'') - self.commit() - w = self.get_widget('State', 'description', 'String') - self.assertEquals(w.name, 'description') - self.assertEquals(w.render_example(self.request()), '') - self.assertDictEquals(w.attrs, {'accesskey': 'd'}) - entity = self.etype_instance('State') - entity.eid = 'X' - entity - self.assertEquals(w.required(entity), False) - self.assertEquals(w.render(entity), '') - if HAS_TAL: - tal_format = u'\n' - else: - tal_format = u'' - self.assertTextEquals(w.edit_render(entity), - u''' - - -
''' % tal_format) - - def test_textarea_widget_previous_value(self): - self.add_entity('CWProperty', pkey=u'ui.fckeditor', value=u'') - self.commit() - w = self.get_widget('State', 'description', 'String') - req = self.request() - req.data['formvalues'] = {'description:X': 'a description'} - entity = self.etype_instance('State', req) - entity.eid = 'X' - self.assertEquals(w.required(entity), False) - self.assertEquals(w.render(entity), '') - if HAS_TAL: - tal_format = u'\n' - else: - tal_format = u'' - self.assertTextEquals(w.edit_render(entity), - u''' - - -
''' % tal_format) - - def test_fckeditor_widget(self): - w = self.get_widget('State', 'description', 'String') - req = self.request() - entity = self.etype_instance('State', req) - entity.eid = 'X' - self.assertEquals(w.required(entity), False) - self.assertEquals(w.render(entity), '') - self.assertTextEquals(w.edit_render(entity), - u''' - - -''') - - def test_string_widget(self): - w = self.get_widget('Personne', 'nom', 'String') - self.assertEquals(w.name, 'nom') - self.assertEquals(w.render_example(self.request()), '') - self.assertDictEquals(w.attrs, {'accesskey': 'n', 'maxlength': 64, 'size': 40}) - entity = self.etype_instance('Personne') - entity.eid = 'X' - self.assertEquals(w.required(entity), True) - self.assertEquals(w.render(entity), '') - self.assertEquals(w.edit_render(entity), - u'\n' - '') - - def test_string_widget_previous_value(self): - w = self.get_widget('Personne', 'nom', 'String') - self.assertEquals(w.name, 'nom') - self.assertEquals(w.render_example(self.request()), '') - self.assertDictEquals(w.attrs, {'accesskey': 'n', 'maxlength': 64, 'size': 40}) - req = self.request() - req.data['formvalues'] = {'nom:X': 'a name'} - entity = self.etype_instance('Personne', req) - entity.eid = 'X' - self.assertEquals(w.required(entity), True) - self.assertEquals(w.render(entity), '') - self.assertEquals(w.edit_render(entity), - u'\n' - '') - - def test_static_combo_widget(self): - w = self.get_widget('Personne', 'promo', 'String') - self.assertEquals(w.name, 'promo') - self.assertEquals(w.render_example(self.request()), '') - self.assertDictEquals(w.attrs, {}) - entity = self.etype_instance('Personne') - entity.eid = 'X' - self.assertEquals(w.required(entity), False) - self.assertEquals(w.render(entity), '') - self.assertTextEquals(w.edit_render(entity), - u'\n\n' - '') - - def test_static_combo_widget_previous_value(self): - w = self.get_widget('Personne', 'promo', 'String') - self.assertEquals(w.name, 'promo') - self.assertEquals(w.render_example(self.request()), '') - self.assertDictEquals(w.attrs, {}) - req = self.request() - req.data['formvalues'] = {'promo:X': 'pasbon'} - entity = self.etype_instance('Personne', req) - entity.eid = 'X' - self.assertEquals(w.required(entity), False) - self.assertEquals(w.render(entity), '') - self.assertTextEquals(w.edit_render(entity), - u'\n\n' - '') - - def test_integer_widget(self): - w = self.get_widget('Personne', 'tel', 'Int') - self.assertEquals(w.name, 'tel') - self.assertEquals(w.render_example(self.request()), '23') - self.assertDictEquals(w.attrs, {'accesskey': 't', 'maxlength': 15, 'size': 5}) - entity = self.etype_instance('Personne') - entity.eid = 'X' - self.assertEquals(w.required(entity), False) - self.assertEquals(w.render(entity), '') - self.assertEquals(w.edit_render(entity), - u'\n' - '') - - def test_integer_widget_previous_value(self): - w = self.get_widget('Personne', 'tel', 'Int') - self.assertEquals(w.name, 'tel') - self.assertEquals(w.render_example(self.request()), '23') - self.assertDictEquals(w.attrs, {'accesskey': 't', 'maxlength': 15, 'size': 5}) - req = self.request() - req.data['formvalues'] = {'tel:X': '0123456789'} - entity = self.etype_instance('Personne', req) - entity.eid = 'X' - self.assertEquals(w.required(entity), False) - self.assertEquals(w.render(entity), '') - self.assertEquals(w.edit_render(entity), - u'\n' - '') - - def test_datetime_widget(self): - w = self.get_widget('Personne', 'datenaiss', 'Datetime') - self.assertEquals(w.name, 'datenaiss') - example = '%s, or without time: %s' % ( - NOW.strftime(self.vreg.property_value('ui.datetime-format')), - NOW.strftime(self.vreg.property_value('ui.date-format'))) - self.assertEquals(w.render_example(self.request()), example) - self.assertDictEquals(w.attrs, {'accesskey': 'd', 'maxlength': 16, 'size': 16}) - entity = self.etype_instance('Personne') - entity.eid = 'X' - self.assertEquals(w.required(entity), False) - self.assertEquals(w.render(entity), '') - self.assertEquals(w.edit_render(entity), - u'\n' - '' - '\n' % (NOW.year, NOW.month)) - - def test_datetime_widget_previous_value(self): - w = self.get_widget('Personne', 'datenaiss', 'Datetime') - self.assertEquals(w.name, 'datenaiss') - self.assertDictEquals(w.attrs, {'accesskey': 'd', 'maxlength': 16, 'size': 16}) - req = self.request() - req.data['formvalues'] = {'datenaiss:X': '2000/01/01'} - entity = self.etype_instance('Personne', req) - entity.eid = 'X' - self.assertEquals(w.required(entity), False) - self.assertEquals(w.render(entity), '') - self.assertEquals(w.edit_render(entity), - u'\n' - '' - '\n' % (NOW.year, NOW.month)) - - - - def test_float_widget(self): - w = self.get_widget('Personne', 'salary', 'Float') - self.assertEquals(w.name, 'salary') - format = self.vreg.property_value('ui.float-format') - self.assertEquals(w.render_example(self.request()), format % 1.23) - self.assertDictEquals(w.attrs, {'accesskey': 's', 'maxlength': 15, 'size': 5}) - entity = self.etype_instance('Personne') - entity.eid = 'X' - self.assertEquals(w.required(entity), False) - self.assertEquals(w.render(entity), '') - self.assertEquals(w.edit_render(entity), - u'\n' - '') - - - def test_float_widget_previous_value(self): - w = self.get_widget('Personne', 'salary', 'Float') - self.assertEquals(w.name, 'salary') - format = self.vreg.property_value('ui.float-format') - self.assertEquals(w.render_example(self.request()), format % 1.23) - self.assertDictEquals(w.attrs, {'accesskey': 's', 'maxlength': 15, 'size': 5}) - req = self.request() - req.data['formvalues'] = {'salary:X': 7.89} - entity = self.etype_instance('Personne', req) - entity.eid = 'X' - self.assertEquals(w.required(entity), False) - self.assertEquals(w.render(entity), '') - self.assertEquals(w.edit_render(entity), - u'\n' - '') - - - def test_bool_widget(self): - w = self.get_widget('Personne', 'test', 'Boolean') - self.assertEquals(w.name, 'test') - self.assertEquals(w.render_example(self.request()), '') - self.assertDictEquals(w.attrs, {'accesskey': 't'}) - entity = self.etype_instance('Personne') - entity.eid = 'X' - self.assertEquals(w.required(entity), False) - self.assertEquals(w.render(entity), '') - self.assertEquals(w.edit_render(entity), - u''' - -yes
-no
''') - - def test_bool_widget_previous_value(self): - w = self.get_widget('Personne', 'test', 'Boolean') - self.assertEquals(w.name, 'test') - self.assertEquals(w.render_example(self.request()), '') - self.assertDictEquals(w.attrs, {'accesskey': 't'}) - req = self.request() - req.data['formvalues'] = {'test:X': 'checked'} - entity = self.etype_instance('Personne', req) - entity.eid = 'X' - self.assertEquals(w.required(entity), False) - self.assertEquals(w.render(entity), '') - self.assertEquals(w.edit_render(entity), - u''' - -yes
-no
''') - - - def test_password_widget(self): - w = self.get_widget('CWUser', 'upassword', 'Password') - self.assertEquals(w.name, 'upassword') - self.assertEquals(w.render_example(self.request()), '') - self.assertDictEquals(w.attrs, {'accesskey': 'u'}) - entity = self.etype_instance('CWUser') - entity.eid = 'X' - self.assertEquals(w.required(entity), True) - self.assertEquals(w.render(entity), '') - self.assertEquals(w.edit_render(entity), - u'\n' - '
\n' - ' (confirm password)') - - def test_autocompletion_widget(self): - entity = self.etype_instance('Personne') - entity.widgets['nom'] = 'AutoCompletionWidget' - entity.autocomplete_initfuncs = {'nom' : 'getnames'} - try: - w = self.get_widget(entity, 'nom', 'String') - self.failUnless(isinstance(w, AutoCompletionWidget)) - self.assertEquals(w.name, 'nom') - self.assertEquals(w.render_example(self.request()), '') - self.assertDictEquals(w.attrs, {'accesskey': 'n', 'maxlength': 64, 'size': 40}) - entity.eid = 'X' - self.assertEquals(w.required(entity), True) - self.assertEquals(w.render(entity), '') - - self.assertTextEquals(w.edit_render(entity), - u'\n' - u'') - - finally: - del entity.widgets['nom'] - - - def test_autocompletion_widget_previous_value(self): - req = self.request() - req.data['formvalues'] = {'nom:X': 'a name'} - entity = self.etype_instance('Personne', req) - entity.widgets['nom'] = 'AutoCompletionWidget' - entity.autocomplete_initfuncs = {'nom' : 'getnames'} - try: - w = self.get_widget(entity, 'nom', 'String') - self.failUnless(isinstance(w, AutoCompletionWidget)) - self.assertEquals(w.name, 'nom') - self.assertEquals(w.render_example(self.request()), '') - self.assertDictEquals(w.attrs, {'accesskey': 'n', 'maxlength': 64, 'size': 40}) - entity.eid = 'X' - self.assertEquals(w.required(entity), True) - self.assertEquals(w.render(entity), '') - self.assertTextEquals(w.edit_render(entity), - u'\n' - u'') - - finally: - del entity.widgets['nom'] - - - def test_nonregr_float_widget_with_none(self): - w = self.get_widget('Personne', 'salary', 'Float') - self.assertEquals(w.name, 'salary') - format = self.vreg.property_value('ui.float-format') - self.assertEquals(w.render_example(self.request()), format % 1.23) - self.assertDictEquals(w.attrs, {'accesskey': 's', 'maxlength': 15, 'size': 5}) - req = self.request() - entity = self.etype_instance('Personne', req) - entity.eid = 'X' - entity.salary = None - self.assertEquals(w.required(entity), False) - self.assertEquals(w.render(entity), '') - self.assertEquals(w.edit_render(entity), - u'\n' - '') - - - def test_custom_widget_for_non_final_relation(self): - entity = self.etype_instance('Personne', self.request()) - entity.widgets['travaille'] = 'AutoCompletionWidget' - entity.autocomplete_initfuncs = {'nom' : 'getnames'} - w = self.get_widget(entity, 'travaille', 'Societe') - self.failUnless(isinstance(w, AutoCompletionWidget)) - - -if __name__ == '__main__': - unittest_main()