# HG changeset patch
# User sylvain.thenault@logilab.fr
# Date 1239797250 -7200
# Node ID bef6891393d773700e05db5ddf331640eb12df30
# Parent a7438eb2420ca9cc47680fcce745131a33c5aea3
backport some tests
diff -r a7438eb2420c -r bef6891393d7 web/formwidgets.py
--- a/web/formwidgets.py Wed Apr 15 14:07:10 2009 +0200
+++ b/web/formwidgets.py Wed Apr 15 14:07:30 2009 +0200
@@ -342,7 +342,7 @@
'''
-
+
# buttons ######################################################################
class Button(Input):
diff -r a7438eb2420c -r bef6891393d7 web/test/unittest_form.py
--- a/web/test/unittest_form.py Wed Apr 15 14:07:10 2009 +0200
+++ b/web/test/unittest_form.py Wed Apr 15 14:07:30 2009 +0200
@@ -1,7 +1,7 @@
from logilab.common.testlib import unittest_main, mock_object
from cubicweb import Binary
from cubicweb.devtools.testlib import WebTest
-from cubicweb.web.form import EntityFieldsForm, FormRenderer
+from cubicweb.web.form import EntityFieldsForm, FieldsForm, FormRenderer
from cubicweb.web.formfields import (IntField, StringField, RichTextField,
DateTimeField, DateTimePicker,
FileField, EditableFileField)
@@ -9,6 +9,16 @@
from cubicweb.web.views.workflow import ChangeStateForm
+class FieldsFormTC(WebTest):
+
+ def test_form_field_format(self):
+ form = FieldsForm(self.request(), None)
+ self.assertEquals(form.form_field_format(None), 'text/html')
+ self.execute('INSERT EProperty X: X pkey "ui.default-text-format", X value "text/rest", X for_user U WHERE U login "admin"')
+ self.commit()
+ self.assertEquals(form.form_field_format(None), 'text/rest')
+
+
class EntityFieldsFormTC(WebTest):
def setUp(self):
@@ -39,6 +49,21 @@
# should be default groups but owners, i.e. managers, users, guests
self.assertEquals(unrelated, [u'guests', u'managers', u'users'])
+ def test_subject_in_state_vocabulary(self):
+ # on a new entity
+ e = self.etype_instance('EUser')
+ form = EntityFieldsForm(self.request(), None, entity=e)
+ states = list(form.subject_in_state_vocabulary('in_state'))
+ self.assertEquals(len(states), 1)
+ self.assertEquals(states[0][0], u'activated') # list of (combobox view, state eid)
+ # on an existant entity
+ e = self.user()
+ form = EntityFieldsForm(self.request(), None, entity=e)
+ states = list(form.subject_in_state_vocabulary('in_state'))
+ self.assertEquals(len(states), 1)
+ self.assertEquals(states[0][0], u'deactivated') # list of (combobox view, state eid)
+
+
# form view tests #########################################################
diff -r a7438eb2420c -r bef6891393d7 web/test/unittest_views_editforms.py
--- a/web/test/unittest_views_editforms.py Wed Apr 15 14:07:10 2009 +0200
+++ b/web/test/unittest_views_editforms.py Wed Apr 15 14:07:30 2009 +0200
@@ -2,12 +2,21 @@
from cubicweb.devtools.apptest import EnvBasedTC
from cubicweb.devtools.testlib import WebTest
from cubicweb.web.views.editforms import AutomaticEntityForm as AEF
-
+from cubicweb.web.formwidgets import AutoCompletionWidget
def rbc(entity, category):
return [(rschema.type, x) for rschema, tschemas, x in AEF.erelations_by_category(entity, category)]
class AutomaticEntityFormTC(EnvBasedTC):
+ def test_custom_widget(self):
+ AEF.rwidgets.set_rtag(AutoCompletionWidget, 'login', 'subject', 'EUser')
+ form = self.vreg.select_object('forms', 'edition', self.request(), None,
+ entity=self.user())
+ field = form.field_by_name('login')
+ self.assertIsInstance(field.widget, AutoCompletionWidget)
+ AEF.rwidgets.del_rtag('login', 'subject', 'EUser')
+
+
def test_euser_relations_by_category(self):
#for (rtype, role, stype, otype), tag in AEF.rcategories._tagdefs.items():
# if rtype == 'tags':