4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
7 """ |
7 """ |
8 from logilab.common.testlib import unittest_main |
8 from logilab.common.testlib import unittest_main |
9 from cubicweb.devtools.apptest import EnvBasedTC |
9 from cubicweb.devtools.testlib import CubicWebTC |
10 from cubicweb.devtools.testlib import WebTest |
|
11 from cubicweb.web.views.autoform import AutomaticEntityForm as AEF |
10 from cubicweb.web.views.autoform import AutomaticEntityForm as AEF |
12 from cubicweb.web.formwidgets import AutoCompletionWidget |
11 from cubicweb.web.formwidgets import AutoCompletionWidget |
13 def rbc(entity, category): |
12 def rbc(entity, category): |
14 return [(rschema.type, x) for rschema, tschemas, x in AEF.erelations_by_category(entity, category)] |
13 return [(rschema.type, x) for rschema, tschemas, x in AEF.erelations_by_category(entity, category)] |
15 |
14 |
16 class AutomaticEntityFormTC(EnvBasedTC): |
15 class AutomaticEntityFormTC(CubicWebTC): |
17 |
16 |
18 def test_custom_widget(self): |
17 def test_custom_widget(self): |
19 AEF.rfields_kwargs.tag_subject_of(('CWUser', 'login', '*'), |
18 AEF.rfields_kwargs.tag_subject_of(('CWUser', 'login', '*'), |
20 {'widget': AutoCompletionWidget(autocomplete_initfunc='get_logins')}) |
19 {'widget': AutoCompletionWidget(autocomplete_initfunc='get_logins')}) |
21 form = self.vreg['forms'].select('edition', self.request(), |
20 form = self.vreg['forms'].select('edition', self.request(), |
27 |
26 |
28 def test_cwuser_relations_by_category(self): |
27 def test_cwuser_relations_by_category(self): |
29 #for (rtype, role, stype, otype), tag in AEF.rcategories._tagdefs.items(): |
28 #for (rtype, role, stype, otype), tag in AEF.rcategories._tagdefs.items(): |
30 # if rtype == 'tags': |
29 # if rtype == 'tags': |
31 # print rtype, role, stype, otype, ':', tag |
30 # print rtype, role, stype, otype, ':', tag |
32 e = self.etype_instance('CWUser') |
31 e = self.vreg['etypes'].etype_class('CWUser')(self.request()) |
33 # see custom configuration in views.cwuser |
32 # see custom configuration in views.cwuser |
34 self.assertEquals(rbc(e, 'primary'), |
33 self.assertEquals(rbc(e, 'primary'), |
35 [('login', 'subject'), |
34 [('login', 'subject'), |
36 ('upassword', 'subject'), |
35 ('upassword', 'subject'), |
37 ('in_group', 'subject'), |
36 ('in_group', 'subject'), |
74 def test_inlined_view(self): |
73 def test_inlined_view(self): |
75 self.failUnless(AEF.rinlined.etype_get('CWUser', 'use_email', 'subject')) |
74 self.failUnless(AEF.rinlined.etype_get('CWUser', 'use_email', 'subject')) |
76 self.failIf(AEF.rinlined.etype_get('CWUser', 'primary_email', 'subject')) |
75 self.failIf(AEF.rinlined.etype_get('CWUser', 'primary_email', 'subject')) |
77 |
76 |
78 def test_personne_relations_by_category(self): |
77 def test_personne_relations_by_category(self): |
79 e = self.etype_instance('Personne') |
78 e = self.vreg['etypes'].etype_class('Personne')(self.request()) |
80 self.assertListEquals(rbc(e, 'primary'), |
79 self.assertListEquals(rbc(e, 'primary'), |
81 [('nom', 'subject'), |
80 [('nom', 'subject'), |
82 ('eid', 'subject') |
81 ('eid', 'subject') |
83 ]) |
82 ]) |
84 self.assertListEquals(rbc(e, 'secondary'), |
83 self.assertListEquals(rbc(e, 'secondary'), |
122 self.vreg['forms'].select('edition', rset.req, |
121 self.vreg['forms'].select('edition', rset.req, |
123 entity=rset.get_entity(0, 0)) |
122 entity=rset.get_entity(0, 0)) |
124 self.failIf(any(f for f in form.fields if f is None)) |
123 self.failIf(any(f for f in form.fields if f is None)) |
125 |
124 |
126 |
125 |
127 class FormViewsTC(WebTest): |
126 class FormViewsTC(CubicWebTC): |
128 def test_delete_conf_formview(self): |
127 def test_delete_conf_formview(self): |
129 rset = self.execute('CWGroup X') |
128 rset = self.execute('CWGroup X') |
130 self.view('deleteconf', rset, template=None).source |
129 self.view('deleteconf', rset, template=None).source |
131 |
130 |
132 def test_automatic_edition_formview(self): |
131 def test_automatic_edition_formview(self): |