diff -r f4d1d5d9ccbb -r 90f2f20367bc web/test/unittest_reledit.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/test/unittest_reledit.py Wed Nov 03 16:38:28 2010 +0100 @@ -0,0 +1,225 @@ +# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr +# +# This file is part of CubicWeb. +# +# CubicWeb is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 2.1 of the License, or (at your option) +# any later version. +# +# CubicWeb is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License along +# with CubicWeb. If not, see . +""" +mainly regression-preventing tests for reledit/doreledit views +""" + +from cubicweb.devtools.testlib import CubicWebTC +from cubicweb.web.uicfg import reledit_ctrl + +class ReleditMixinTC(object): + + def setup_database(self): + self.req = self.request() + self.proj = self.req.create_entity('Project', title=u'cubicweb-world-domination') + self.tick = self.req.create_entity('Ticket', title=u'write the code') + self.toto = self.req.create_entity('Personne', nom=u'Toto') + +class ClickAndEditFormTC(ReleditMixinTC, CubicWebTC): + + def test_default_config(self): + reledit = {'title': """
cubicweb-world-domination
""", + 'long_desc': """
<not specified>
""", + 'manager': """
<not specified>
""", + 'composite_card11_2ttypes': """<not specified>""", + 'concerns': """<not specified>"""} + + for rschema, ttypes, role in self.proj.e_schema.relation_definitions(includefinal=True): + if rschema not in reledit: + continue + rtype = rschema.type + self.assertMultiLineEqual(reledit[rtype] % {'eid': self.proj.eid}, self.proj.view('reledit', rtype=rtype, role=role), rtype) + + def test_default_forms(self): + doreledit = {'title': """
cubicweb-world-domination
+
+ + + + + + + + + + + + + + +
+ + + +
+ +
+ + + + + + + +
+
+
""", + + 'long_desc': """
<not specified>
+
+ + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+ +
+ +
+ +
+ + + + + + + +
+
+
""", + + 'manager': """
<not specified>
+
+ + + + + + + + + + + + + + + + +
+ + + +
+ +
+ + + + + + + +
+
+
""", + 'composite_card11_2ttypes': """<not specified>""", + 'concerns': """<not specified>""" + } + for rschema, ttypes, role in self.proj.e_schema.relation_definitions(includefinal=True): + if rschema not in doreledit: + continue + rtype = rschema.type + self.assertMultiLineEqual(doreledit[rtype] % {'eid': self.proj.eid, 'toto': self.toto.eid}, + self.proj.view('doreledit', rtype=rtype, role=role, + formid='edition' if rtype == 'long_desc' else 'base'), + rtype) + +class ClickAndEditFormUICFGTC(ReleditMixinTC, CubicWebTC): + + def setup_database(self): + super(ClickAndEditFormUICFGTC, self).setup_database() + self.tick.set_relations(concerns=self.proj) + self.proj.set_relations(manager=self.toto) + + def test_with_uicfg(self): + old_rctl = reledit_ctrl._tagdefs.copy() + reledit_ctrl.tag_attribute(('Project', 'title'), + {'novalue_label': '', 'reload': True}) + reledit_ctrl.tag_subject_of(('Project', 'long_desc', '*'), + {'reload': True, 'edit_target': 'rtype', + 'novalue_label': u'<long_desc is required>'}) + reledit_ctrl.tag_subject_of(('Project', 'manager', '*'), + {'edit_target': 'related'}) + reledit_ctrl.tag_subject_of(('Project', 'composite_card11_2ttypes', '*'), + {'edit_target': 'related'}) + reledit_ctrl.tag_object_of(('Ticket', 'concerns', 'Project'), + {'edit_target': 'rtype'}) + reledit = { + 'title': """<div id="title-subject-%(eid)s-reledit" onmouseout="jQuery('#title-subject-%(eid)s').addClass('hidden')" onmouseover="jQuery('#title-subject-%(eid)s').removeClass('hidden')" class="releditField"><div id="title-subject-%(eid)s-value" class="editableFieldValue">cubicweb-world-domination</div><div id="title-subject-%(eid)s" class="editableField hidden"><div id="title-subject-%(eid)s-update" class="editableField" onclick="cw.reledit.loadInlineEditionForm('base', %(eid)s, 'title', 'subject', 'title-subject-%(eid)s', true, '');" title="click to edit this field"><img title="click to edit this field" src="data/pen_icon.png" alt="click to edit this field"/></div></div></div>""", + 'long_desc': """<div id="long_desc-subject-%(eid)s-reledit" onmouseout="jQuery('#long_desc-subject-%(eid)s').addClass('hidden')" onmouseover="jQuery('#long_desc-subject-%(eid)s').removeClass('hidden')" class="releditField"><div id="long_desc-subject-%(eid)s-value" class="editableFieldValue"><long_desc is required></div><div id="long_desc-subject-%(eid)s" class="editableField hidden"><div id="long_desc-subject-%(eid)s-update" class="editableField" onclick="cw.reledit.loadInlineEditionForm('base', %(eid)s, 'long_desc', 'subject', 'long_desc-subject-%(eid)s', true, 'autolimited');" title="click to edit this field"><img title="click to edit this field" src="data/pen_icon.png" alt="click to edit this field"/></div></div></div>""", + 'manager': """<div id="manager-subject-%(eid)s-reledit" onmouseout="jQuery('#manager-subject-%(eid)s').addClass('hidden')" onmouseover="jQuery('#manager-subject-%(eid)s').removeClass('hidden')" class="releditField"><div id="manager-subject-%(eid)s-value" class="editableFieldValue"><a href="http://testing.fr/cubicweb/personne/%(toto)s" title="">Toto</a></div><div id="manager-subject-%(eid)s" class="editableField hidden"><div id="manager-subject-%(eid)s-update" class="editableField" onclick="cw.reledit.loadInlineEditionForm('edition', %(eid)s, 'manager', 'subject', 'manager-subject-%(eid)s', false, 'autolimited');" title="click to edit this field"><img title="click to edit this field" src="data/pen_icon.png" alt="click to edit this field"/></div><div id="manager-subject-%(eid)s-delete" class="editableField" onclick="cw.reledit.loadInlineEditionForm('deleteconf', %(eid)s, 'manager', 'subject', 'manager-subject-%(eid)s', false, 'autolimited');" title="click to delete this value"><img title="click to delete this value" src="data/cancel.png" alt="click to delete this value"/></div></div></div>""", + 'composite_card11_2ttypes': """<not specified>""", + 'concerns': """<div id="concerns-object-%(eid)s-reledit" onmouseout="jQuery('#concerns-object-%(eid)s').addClass('hidden')" onmouseover="jQuery('#concerns-object-%(eid)s').removeClass('hidden')" class="releditField"><div id="concerns-object-%(eid)s-value" class="editableFieldValue"><a href="http://testing.fr/cubicweb/ticket/%(tick)s" title="">write the code</a></div><div id="concerns-object-%(eid)s" class="editableField hidden"><div id="concerns-object-%(eid)s-update" class="editableField" onclick="cw.reledit.loadInlineEditionForm('base', %(eid)s, 'concerns', 'object', 'concerns-object-%(eid)s', false, 'autolimited');" title="click to edit this field"><img title="click to edit this field" src="data/pen_icon.png" alt="click to edit this field"/></div></div></div>""" + } + for rschema, ttypes, role in self.proj.e_schema.relation_definitions(includefinal=True): + if rschema not in reledit: + continue + rtype = rschema.type + self.assertMultiLineEqual(reledit[rtype] % {'eid': self.proj.eid, 'toto': self.toto.eid, 'tick': self.tick.eid}, + self.proj.view('reledit', rtype=rtype, role=role), + rtype) + reledit_ctrl.clear() + reledit_ctrl._tagdefs.update(old_rctl) + + +if __name__ == '__main__': + from logilab.common.testlib import unittest_main + unittest_main()