# HG changeset patch # User Sylvain Thénault # Date 1244207215 -7200 # Node ID 0a0cbccafcb530c839191cd066c60273e1d45a29 # Parent e4d24e4d74e6b190b04b59e15b675fb1da5ab344 test broken, deprecated module; kill diff -r e4d24e4d74e6 -r 0a0cbccafcb5 web/test/unittest_views_baseforms.py --- a/web/test/unittest_views_baseforms.py Fri Jun 05 10:26:35 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,250 +0,0 @@ -"""cubicweb.web.views.baseforms 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 StringIO import StringIO -from datetime import date -import re - - -from logilab.common.testlib import unittest_main -from logilab.common.decorators import clear_cache -from cubicweb.devtools.apptest import EnvBasedTC -from cubicweb.entities import AnyEntity -from cubicweb.web import widgets - -orig_now = widgets.datetime.now - -def setup_module(options): - def _today(): - return date(0000, 1, 1) - widgets.datetime.now = _today - -def teardown_module(options, results): - widgets.datetime.now = orig_now - - -def cleanup_text(text): - return re.sub('\d\d:\d\d', 'hh:mm', re.sub('\d+/\d\d/\d\d', 'YYYY/MM/DD', '\n'.join(l.strip() for l in text.splitlines() if l.strip()))) - - - -class EditionFormTC(EnvBasedTC): - - def setup_database(self): - self.create_user('joe') - - def _build_creation_form(self, etype): - req = self.request() - req.next_tabindex() - req.next_tabindex() - req.del_page_data() - req.form['etype'] = etype - view = self.vreg.select_view('creation', req, None) - entity = self.vreg.etype_class(etype)(req, None, None) - buffer = StringIO() - view.w = buffer.write - view.edit_form(entity, {}) - return buffer.getvalue() - - def _test_view_for(self, etype, expected): - self.assertTextEquals(expected, cleanup_text(self._build_creation_form(etype))) - - def test_base(self): - self._test_view_for('CWGroup', '''\ -
-
egroup (creation)
-
validating...
-
main informations
-
- - - - - - - - - - - -
- - -
-
-
-
- - - - -
- - - - -
-
''') - - def test_with_inline_view(self): - activated = self.execute('Any X WHERE X is State, X name "activated"')[0][0] - self._test_view_for('CWUser', '''
-
euser (creation)
-
validating...
-
main informations
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
 unique identifier used to connect to the application -
- -
- (confirm password) -
-
- - -
-
- - -
-
- - -
 groups grant permissions to the user -
- - -
 account state -
- -
-
- - - - -
- - - - -
-
''' % {'activated' : activated}) - - def test_redirection_after_creation(self): - req = self.request() - req.form['etype'] = 'CWUser' - view = self.vreg.select_view('creation', req, None) - self.assertEquals(view.redirect_url(), 'http://testing.fr/cubicweb/euser') - req.form['__redirectrql'] = 'Any X WHERE X eid 3012' - req.form['__redirectvid'] = 'avid' - self.assertEquals(view.redirect_url(), 'http://testing.fr/cubicweb/view?rql=Any%20X%20WHERE%20X%20eid%203012&vid=avid') - - - def test_need_multipart(self): - req = self.request() - class Salesterm(AnyEntity): - id = 'Salesterm' - __rtags__ = {'described_by_test' : 'inlineview'} - vreg = self.vreg - vreg.register_vobject_class(Salesterm) - req.form['etype'] = 'Salesterm' - entity = vreg.etype_class('Salesterm')(req, None, None) - view = vreg.select_view('creation', req, None) - self.failUnless(view.need_multipart(entity)) - - - - def test_nonregr_check_add_permission_on_relation(self): - from cubes.blog.entities import BlogEntry - class BlogEntryPlus(BlogEntry): - __rtags__ = {'checked_by': 'primary'} - self.vreg.register_vobject_class(BlogEntryPlus) - clear_cache(self.vreg, 'etype_class') - # an admin should be able to edit the checked_by relation - html = self._build_creation_form('BlogEntry') - self.failUnless('name="edits-checked_by:A"' in html) - # a regular user should not be able to see the relation - self.login('joe') - html = self._build_creation_form('BlogEntry') - self.failIf('name="edits-checked_by:A"' in html) - -from cubicweb.devtools.testlib import WebTest -from cubicweb.devtools.htmlparser import DTDValidator - -class CopyWebTest(WebTest): - - def setup_database(self): - p = self.create_user("Doe") - # do not try to skip 'primary_email' for this test - e = self.add_entity('EmailAddress', address=u'doe@doe.com') - self.execute('SET P use_email E, P primary_email E WHERE P eid %(p)s, E eid %(e)s', - {'p' : p.eid, 'e' : e.eid}) - - - def test_cloned_elements_in_copy_form(self): - rset = self.execute('CWUser P WHERE P login "Doe"') - output = self.view('copy', rset) - clones = [attrs for _, attrs in output.input_tags - if attrs.get('name', '').startswith('__cloned_eid')] - # the only cloned entity should be the original person - self.assertEquals(len(clones), 1) - attrs = clones[0] - self.assertEquals(attrs['name'], '__cloned_eid:A') - self.assertEquals(int(attrs['value']), rset[0][0]) - - -if __name__ == '__main__': - unittest_main()