--- a/web/test/unittest_form.py Thu Apr 30 09:25:33 2009 +0200
+++ b/web/test/unittest_form.py Thu Apr 30 10:32:51 2009 +0200
@@ -26,7 +26,7 @@
self.req = self.request()
self.entity = self.user(self.req)
self.renderer = FormRenderer()
-
+
def test_form_field_vocabulary_unrelated(self):
b = self.add_entity('BlogEntry', title=u'di mascii code', content=u'a best-seller')
t = self.add_entity('Tag', name=u'x')
@@ -41,7 +41,7 @@
self.failIf(b.eid in unrelated, unrelated)
unrelated = [reid for rview, reid in form2.object_relation_vocabulary('tags')]
self.failIf(t.eid in unrelated, unrelated)
-
+
def test_form_field_vocabulary_new_entity(self):
e = self.etype_instance('CWUser')
form = EntityFieldsForm(self.request(), None, entity=e)
@@ -64,18 +64,18 @@
self.assertEquals(states[0][0], u'deactivated') # list of (combobox view, state eid)
-
+
# form view tests #########################################################
-
+
def test_massmailing_formview(self):
self.execute('INSERT EmailAddress X: X address L + "@cubicweb.org", '
'U use_email X WHERE U is CWUser, U login L')
rset = self.execute('CWUser X')
self.view('massmailing', rset, template=None)
-
+
# form tests ##############################################################
-
+
def test_form_inheritance(self):
class CustomChangeStateForm(ChangeStateForm):
hello = IntField(name='youlou')
@@ -88,36 +88,37 @@
form = ChangeStateForm(self.req, redirect_path='perdu.com',
entity=self.entity)
form.form_render(state=123, trcomment=u'')
-
+
# fields tests ############################################################
def _render_entity_field(self, name, form):
form.form_build_context({})
return form.field_by_name(name).render(form, self.renderer)
-
+
def _test_richtextfield(self, expected):
class RTFForm(EntityFieldsForm):
- content = RichTextField()
- card = self.add_entity('Card', title=u"tls sprint fev 2009",
- content=u'<h1>new widgets system</h1>',
- content_format=u'text/html')
- form = RTFForm(self.req, redirect_path='perdu.com', entity=card)
- self.assertTextEquals(self._render_entity_field('content', form), expected % {'eid': card.eid})
+ description = RichTextField()
+ state = self.execute('State X WHERE X name "activated", X state_of ET, ET name "CWUser"').get_entity(0, 0)
+ form = RTFForm(self.req, redirect_path='perdu.com', entity=state)
+ # make it think it can use fck editor anyway
+ form.form_field_format = lambda x: 'text/html'
+ self.assertTextEquals(self._render_entity_field('description', form),
+ expected % {'eid': state.eid})
-
+
def test_richtextfield_1(self):
self.req.use_fckeditor = lambda: False
- self._test_richtextfield('''<select name="content_format:%(eid)s" id="content_format:%(eid)s" tabindex="0">
+ self._test_richtextfield('''<select name="description_format:%(eid)s" size="1" id="description_format:%(eid)s" tabindex="0">
<option value="text/cubicweb-page-template">text/cubicweb-page-template</option>
-<option selected="selected" value="text/html">text/html</option>
+<option value="text/html">text/html</option>
<option value="text/plain">text/plain</option>
-<option value="text/rest">text/rest</option>
-</select><textarea tabindex="1" id="content:%(eid)s" name="content:%(eid)s" onkeypress="autogrow(this)"><h1>new widgets system</h1></textarea>''')
+<option selected="selected" value="text/rest">text/rest</option>
+</select><textarea rows="5" name="description:564" onkeypress="autogrow(this)" cols="60" id="description:564" tabindex="1"/>''')
-
+
def test_richtextfield_2(self):
self.req.use_fckeditor = lambda: True
- self._test_richtextfield('''<input type="hidden" name="content_format:%(eid)s" value="text/html"/><textarea tabindex="0" cubicweb:type="wysiwyg" id="content:%(eid)s" name="content:%(eid)s" onkeypress="autogrow(this)"><h1>new widgets system</h1></textarea>''')
+ self._test_richtextfield('<input type="hidden" name="description_format:%(eid)s" value="text/rest"/><textarea rows="20" name="description:564" onkeypress="autogrow(this)" cols="80" cubicweb:type="wysiwyg" id="description:564" tabindex="0"/>')
def test_filefield(self):
@@ -135,11 +136,11 @@
<label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" type="text" name="data_encoding:%(eid)s" value="UTF-8" tabindex="2"/><br/><br/>
</div>
<br/>
-<input type="checkbox" name="data:594__detach"/>
+<input type="checkbox" name="data:%(eid)s__detach"/>
detach attached file
''' % {'eid': file.eid})
-
+
def test_editablefilefield(self):
class EFFForm(EntityFieldsForm):
data = EditableFileField(format_field=StringField(name='data_format'),
@@ -159,10 +160,10 @@
<label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" type="text" name="data_encoding:%(eid)s" value="UTF-8" tabindex="2"/><br/><br/>
</div>
<br/>
-<input type="checkbox" name="data:594__detach"/>
+<input type="checkbox" name="data:%(eid)s__detach"/>
detach attached file
<p><b>You can either submit a new file using the browse button above, or choose to remove already uploaded file by checking the "detach attached file" check-box, or edit file content online with the widget below.</b></p>
-<textarea tabindex="3" name="data:%(eid)s" onkeypress="autogrow(this)">new widgets system</textarea>''' % {'eid': file.eid})
+<textarea tabindex="3" rows="20" cols="80" name="data:%(eid)s" onkeypress="autogrow(this)">new widgets system</textarea>''' % {'eid': file.eid})
def test_passwordfield(self):
@@ -176,6 +177,6 @@
<span class="emphasis">confirm password</span>''' % {'eid': self.entity.eid})
-
+
if __name__ == '__main__':
unittest_main()
--- a/web/test/unittest_formfields.py Thu Apr 30 09:25:33 2009 +0200
+++ b/web/test/unittest_formfields.py Thu Apr 30 10:32:51 2009 +0200
@@ -2,47 +2,48 @@
from logilab.common.testlib import TestCase, unittest_main
from cubicweb.devtools import TestServerConfiguration
-from cubicweb.web.formwidgets import PasswordInput
+from cubicweb.web.formwidgets import PasswordInput, TextArea
from cubicweb.web.formfields import *
-from cubicweb.entities.lib import Card
+from cubicweb.entities.wfobjs import State
from cubicweb.entities.authobjs import CWUser
from cubes.file.entities import File
config = TestServerConfiguration('data')
config.bootstrap_cubes()
schema = config.load_schema()
-card_schema = schema['Card']
+state_schema = schema['State']
cwuser_schema = schema['CWUser']
file_schema.schema = schema['File']
class GuessFieldTC(TestCase):
- def test_card_fields(self):
- title_field = guess_field(card_schema, schema['title'])
+ def test_state_fields(self):
+ title_field = guess_field(state_schema, schema['name'])
self.assertIsInstance(title_field, StringField)
self.assertEquals(title_field.required, True)
- synopsis_field = guess_field(card_schema, schema['synopsis'])
- self.assertIsInstance(synopsis_field, TextField)
- self.assertEquals(synopsis_field.required, False)
- self.assertEquals(synopsis_field.help, 'an abstract for this card')
+# synopsis_field = guess_field(state_schema, schema['synopsis'])
+# self.assertIsInstance(synopsis_field, StringField)
+# self.assertIsInstance(synopsis_field.widget, TextArea)
+# self.assertEquals(synopsis_field.required, False)
+# self.assertEquals(synopsis_field.help, 'an abstract for this state')
- content_field = guess_field(card_schema, schema['content'])
- self.assertIsInstance(content_field, RichTextField)
- self.assertEquals(content_field.required, False)
- self.assertEquals(content_field.format_field, None)
+ description_field = guess_field(state_schema, schema['description'])
+ self.assertIsInstance(description_field, RichTextField)
+ self.assertEquals(description_field.required, False)
+ self.assertEquals(description_field.format_field, None)
- content_format_field = guess_field(card_schema, schema['content_format'])
- self.assertEquals(content_format_field, None)
+ description_format_field = guess_field(state_schema, schema['description_format'])
+ self.assertEquals(description_format_field, None)
- content_format_field = guess_field(card_schema, schema['content_format'], skip_meta_attr=False)
- self.assertEquals(content_format_field.internationalizable, True)
- self.assertEquals(content_format_field.sort, True)
- self.assertEquals(content_format_field.initial, 'text/rest')
+ description_format_field = guess_field(state_schema, schema['description_format'], skip_meta_attr=False)
+ self.assertEquals(description_format_field.internationalizable, True)
+ self.assertEquals(description_format_field.sort, True)
+ self.assertEquals(description_format_field.initial, 'text/rest')
- wikiid_field = guess_field(card_schema, schema['wikiid'])
- self.assertIsInstance(wikiid_field, StringField)
- self.assertEquals(wikiid_field.required, False)
+# wikiid_field = guess_field(state_schema, schema['wikiid'])
+# self.assertIsInstance(wikiid_field, StringField)
+# self.assertEquals(wikiid_field.required, False)
def test_euser_fields(self):
--- a/web/test/unittest_viewselector.py Thu Apr 30 09:25:33 2009 +0200
+++ b/web/test/unittest_viewselector.py Thu Apr 30 10:32:51 2009 +0200
@@ -12,8 +12,8 @@
traced_selection)
from cubicweb.web import NoSelectableObject
from cubicweb.web.action import Action
-from cubicweb.web.views import (baseviews, tableview, baseforms, calendar,
- management, embedding, actions, startup,
+from cubicweb.web.views import (baseviews, tableview, baseforms, calendar,
+ management, embedding, actions, startup,
euser, schemaentities, xbel, vcard, owl,
treeview, idownloadable, wdoc, debug, eproperties)
@@ -22,7 +22,7 @@
('logout', actions.LogoutAction)]
SITEACTIONS = [('siteconfig', actions.SiteConfigurationAction),
('manage', actions.ManageAction),
- ('schema', actions.ViewSchemaAction)]
+ ('schema', actions.ViewSchemaAction)]
class ViewSelectorTC(EnvBasedTC):
@@ -30,7 +30,6 @@
def setup_database(self):
self.add_entity('BlogEntry', title=u"une news !", content=u"cubicweb c'est beau")
self.add_entity('Bookmark', title=u"un signet !", path=u"view?vid=index")
- self.add_entity('Card', title=u'mandatory', content=u"DoC !")
self.add_entity('EmailAddress', address=u"devel@logilab.fr", alias=u'devel')
self.add_entity('Tag', name=u'x')
@@ -59,8 +58,8 @@
print 'no more', [v for v in expected if not v in content.keys()]
print 'missing', [v for v in content.keys() if not v in expected]
raise
-
-
+
+
def test_possible_views_none_rset(self):
req = self.request()
self.assertListEqual(self.pviews(req, None),
@@ -73,12 +72,12 @@
('owl', owl.OWLView),
('schema', startup.SchemaView),
('systemepropertiesform', eproperties.SystemEPropertiesForm)])
-
+
def test_possible_views_noresult(self):
rset, req = self.env.get_rset_and_req('Any X WHERE X eid 999999')
self.assertListEqual(self.pviews(req, rset),
[])
-
+
def test_possible_views_one_egroup(self):
rset, req = self.env.get_rset_and_req('CWGroup X WHERE X name "managers"')
self.assertListEqual(self.pviews(req, rset),
@@ -100,7 +99,7 @@
('xbel', xbel.XbelView),
('xml', baseviews.XmlView),
])
-
+
def test_possible_views_multiple_egroups(self):
rset, req = self.env.get_rset_and_req('CWGroup X')
self.assertListEqual(self.pviews(req, rset),
@@ -122,7 +121,7 @@
('xbel', xbel.XbelView),
('xml', baseviews.XmlView),
])
-
+
def test_possible_views_multiple_different_types(self):
rset, req = self.env.get_rset_and_req('Any X')
self.assertListEqual(self.pviews(req, rset),
@@ -144,7 +143,7 @@
('xbel', xbel.XbelView),
('xml', baseviews.XmlView),
])
-
+
def test_possible_views_any_rset(self):
rset, req = self.env.get_rset_and_req('Any N, X WHERE X in_group Y, Y name N')
self.assertListEqual(self.pviews(req, rset),
@@ -177,13 +176,13 @@
('xbel', xbel.XbelView),
('xml', baseviews.XmlView),
])
-
+
def test_possible_actions_none_rset(self):
req = self.request()
self.assertDictEqual(self.pactions(req, None),
{'useractions': USERACTIONS,
'siteactions': SITEACTIONS,
-
+
})
def test_possible_actions_no_entity(self):
rset, req = self.env.get_rset_and_req('Any X WHERE X eid 999999')
@@ -191,7 +190,7 @@
{'useractions': USERACTIONS,
'siteactions': SITEACTIONS,
})
-
+
def test_possible_actions_same_type_entities(self):
rset, req = self.env.get_rset_and_req('CWGroup X')
self.assertDictEqual(self.pactions(req, rset),
@@ -201,7 +200,7 @@
'moreactions': [('delete', actions.DeleteAction),
('addentity', actions.AddNewAction)],
})
-
+
def test_possible_actions_different_types_entities(self):
rset, req = self.env.get_rset_and_req('Any X')
self.assertDictEqual(self.pactions(req, rset),
@@ -209,13 +208,13 @@
'siteactions': SITEACTIONS,
'moreactions': [('delete', actions.DeleteAction)],
})
-
+
def test_possible_actions_final_entities(self):
rset, req = self.env.get_rset_and_req('Any N, X WHERE X in_group Y, Y name N')
self.assertDictEqual(self.pactions(req, rset),
{'useractions': USERACTIONS,
'siteactions': SITEACTIONS})
-
+
def test_possible_actions_eetype_euser_entity(self):
rset, req = self.env.get_rset_and_req('CWEType X WHERE X name "CWUser"')
self.assertDictEqual(self.pactions(req, rset),
@@ -227,7 +226,7 @@
('copy', actions.CopyAction),
('managepermission', actions.ManagePermissionsAction)],
})
-
+
def test_select_creation_form(self):
rset = None
@@ -244,7 +243,7 @@
req.form['etype'] = 'CWUser'
self.assertIsInstance(self.vreg.select_view('creation', req, rset),
CWUserCreationForm)
-
+
def test_select_view(self):
# no entity
rset = None
@@ -255,7 +254,7 @@
self.vreg.select_view, 'primary', req, rset)
self.failUnlessRaises(NoSelectableObject,
self.vreg.select_view, 'table', req, rset)
-
+
# no entity
rset, req = self.env.get_rset_and_req('Any X WHERE X eid 999999')
self.failUnlessRaises(NoSelectableObject,
@@ -337,8 +336,8 @@
rset, req = self.env.get_rset_and_req('Image X WHERE X name "bim.png"')
self.assertIsInstance(self.vreg.select_view('primary', req, rset),
idownloadable.IDownloadablePrimaryView)
-
-
+
+
def test_score_entity_selector(self):
image = self.add_entity('Image', name=u'bim.png', data=Binary('bim'))
# image primary view priority
@@ -349,9 +348,9 @@
# image primary view priority
rset, req = self.env.get_rset_and_req('File X WHERE X name "bim.txt"')
self.assertRaises(NoSelectableObject, self.vreg.select_view, 'image', req, rset)
-
-
-
+
+
+
def _test_view(self, vid, rql, args):
if rql is None:
rset = None
@@ -389,35 +388,8 @@
self.assertEquals(self.vreg.property_value('boxes.possible_views_box.visible'), False)
self.assertEquals(self.vreg.property_value('boxes.possible_views_box.order'), 10)
self.assertRaises(KeyError, self.vreg.property_value, 'boxes.actions_box')
-
- def test_owners_match_user_group(self):
- """tests usage of 'owners' group with match_user_group"""
- class SomeAction(Action):
- id = 'yo'
- category = 'foo'
- __select__ = match_user_groups('owners')
- self.vreg.register_vobject_class(SomeAction)
- self.failUnless(SomeAction in self.vreg['actions']['yo'], self.vreg['actions'])
- try:
- # login as a simple user
- self.create_user('john')
- self.login('john')
- # it should not be possible to use SomeAction not owned objects
- rset, req = self.env.get_rset_and_req('Any G WHERE G is CWGroup, G name "managers"')
- self.failIf('foo' in self.pactions(req, rset))
- # insert a new card, and check that we can use SomeAction on our object
- self.execute('INSERT Card C: C title "zoubidou"')
- self.commit()
- rset, req = self.env.get_rset_and_req('Card C WHERE C title "zoubidou"')
- self.failUnless('foo' in self.pactions(req, rset))
- # make sure even managers can't use the action
- self.restore_connection()
- rset, req = self.env.get_rset_and_req('Card C WHERE C title "zoubidou"')
- self.failIf('foo' in self.pactions(req, rset))
- finally:
- del self.vreg[SomeAction.__registry__][SomeAction.id]
class CWETypeRQLAction(Action):
@@ -426,15 +398,15 @@
title = 'bla'
class RQLActionTC(ViewSelectorTC):
-
+
def setUp(self):
super(RQLActionTC, self).setUp()
self.vreg.register_vobject_class(CWETypeRQLAction)
-
+
def tearDown(self):
- super(RQLActionTC, self).tearDown()
+ super(RQLActionTC, self).tearDown()
del self.vreg._registries['actions']['testaction']
-
+
def test(self):
rset, req = self.env.get_rset_and_req('CWEType X WHERE X name "CWEType"')
self.assertDictEqual(self.pactions(req, rset),
@@ -455,7 +427,7 @@
('copy', actions.CopyAction),
('managepermission', actions.ManagePermissionsAction)],
})
-
+
if __name__ == '__main__':