7 """ |
7 """ |
8 from logilab.common.testlib import unittest_main, mock_object |
8 from logilab.common.testlib import unittest_main, mock_object |
9 from logilab.common.compat import any |
9 from logilab.common.compat import any |
10 |
10 |
11 from cubicweb.devtools.testlib import CubicWebTC |
11 from cubicweb.devtools.testlib import CubicWebTC |
12 from cubicweb.web.views.autoform import AutomaticEntityForm as AEF |
12 from cubicweb.web import uicfg |
13 from cubicweb.web.formwidgets import AutoCompletionWidget |
13 from cubicweb.web.formwidgets import AutoCompletionWidget |
14 |
14 |
15 def rbc(entity, category): |
15 AFFK = uicfg.autoform_field_kwargs |
16 return [(rschema.type, x) for rschema, tschemas, x in AEF.erelations_by_category(entity, category)] |
16 AFS = uicfg.autoform_section |
|
17 |
|
18 def rbc(entity, formtype, section): |
|
19 return [(rschema.type, x) for rschema, tschemas, x in AFS.relations_by_section(entity, formtype, section)] |
17 |
20 |
18 class AutomaticEntityFormTC(CubicWebTC): |
21 class AutomaticEntityFormTC(CubicWebTC): |
19 |
22 |
20 def test_custom_widget(self): |
23 def test_custom_widget(self): |
21 AEF.rfields_kwargs.tag_subject_of(('CWUser', 'login', '*'), |
24 AFFK.tag_subject_of(('CWUser', 'login', '*'), |
22 {'widget': AutoCompletionWidget(autocomplete_initfunc='get_logins')}) |
25 {'widget': AutoCompletionWidget(autocomplete_initfunc='get_logins')}) |
23 form = self.vreg['forms'].select('edition', self.request(), |
26 form = self.vreg['forms'].select('edition', self.request(), |
24 entity=self.user()) |
27 entity=self.user()) |
25 field = form.field_by_name('login') |
28 field = form.field_by_name('login') |
26 self.assertIsInstance(field.widget, AutoCompletionWidget) |
29 self.assertIsInstance(field.widget, AutoCompletionWidget) |
27 AEF.rfields_kwargs.del_rtag('CWUser', 'login', '*', 'subject') |
30 AFFK.del_rtag('CWUser', 'login', '*', 'subject') |
28 |
31 |
29 |
32 |
30 def test_cwuser_relations_by_category(self): |
33 def test_cwuser_relations_by_category(self): |
31 #for (rtype, role, stype, otype), tag in AEF.rcategories._tagdefs.items(): |
34 #for (rtype, role, stype, otype), tag in AEF.rcategories._tagdefs.items(): |
32 # if rtype == 'tags': |
35 # if rtype == 'tags': |
33 # print rtype, role, stype, otype, ':', tag |
36 # print rtype, role, stype, otype, ':', tag |
34 e = self.vreg['etypes'].etype_class('CWUser')(self.request()) |
37 e = self.vreg['etypes'].etype_class('CWUser')(self.request()) |
35 # see custom configuration in views.cwuser |
38 # see custom configuration in views.cwuser |
36 self.assertEquals(rbc(e, 'primary'), |
39 self.assertEquals(rbc(e, 'main', 'attributes'), |
37 [('login', 'subject'), |
40 [('login', 'subject'), |
38 ('upassword', 'subject'), |
41 ('upassword', 'subject'), |
|
42 ('firstname', 'subject'), |
|
43 ('surname', 'subject'), |
39 ('in_group', 'subject'), |
44 ('in_group', 'subject'), |
40 ('eid', 'subject'), |
45 ('eid', 'subject'), |
41 ]) |
46 ]) |
42 self.assertListEquals(rbc(e, 'secondary'), |
47 self.assertListEquals(rbc(e, 'muledit', 'attributes'), |
43 [('firstname', 'subject'), |
48 [('login', 'subject'), |
44 ('surname', 'subject') |
49 ('upassword', 'subject'), |
|
50 ('in_group', 'subject'), |
|
51 ('eid', 'subject'), |
45 ]) |
52 ]) |
46 self.assertListEquals(rbc(e, 'metadata'), |
53 self.assertListEquals(rbc(e, 'main', 'metadata'), |
47 [('last_login_time', 'subject'), |
54 [('last_login_time', 'subject'), |
48 ('modification_date', 'subject'), |
55 ('modification_date', 'subject'), |
49 ('created_by', 'subject'), |
56 ('created_by', 'subject'), |
50 ('creation_date', 'subject'), |
57 ('creation_date', 'subject'), |
51 ('cwuri', 'subject'), |
58 ('cwuri', 'subject'), |
52 ('owned_by', 'subject'), |
59 ('owned_by', 'subject'), |
53 ('bookmarked_by', 'object'), |
60 ('bookmarked_by', 'object'), |
54 ]) |
61 ]) |
55 self.assertListEquals(rbc(e, 'generic'), |
62 self.assertListEquals(rbc(e, 'main', 'relations'), |
56 [('primary_email', 'subject'), |
63 [('primary_email', 'subject'), |
57 ('custom_workflow', 'subject'), |
64 ('custom_workflow', 'subject'), |
58 ('connait', 'subject'), |
65 ('connait', 'subject'), |
59 ('checked_by', 'object'), |
66 ('checked_by', 'object'), |
60 ]) |
67 ]) |
|
68 self.assertListEquals(rbc(e, 'main', 'inlined'), |
|
69 [('use_email', 'subject'), |
|
70 ]) |
61 # owned_by is defined both as subject and object relations on CWUser |
71 # owned_by is defined both as subject and object relations on CWUser |
62 self.assertListEquals(rbc(e, 'generated'), |
72 self.assertListEquals(rbc(e, 'main', 'hidden'), |
63 [('use_email', 'subject'), |
73 [('in_state', 'subject'), |
64 ('in_state', 'subject'), |
|
65 ('is', 'subject'), |
74 ('is', 'subject'), |
66 ('is_instance_of', 'subject'), |
75 ('is_instance_of', 'subject'), |
67 ('has_text', 'subject'), |
76 ('has_text', 'subject'), |
68 ('identity', 'subject'), |
77 ('identity', 'subject'), |
69 ('tags', 'object'), |
78 ('tags', 'object'), |
73 ('owned_by', 'object'), |
82 ('owned_by', 'object'), |
74 ('identity', 'object'), |
83 ('identity', 'object'), |
75 ]) |
84 ]) |
76 |
85 |
77 def test_inlined_view(self): |
86 def test_inlined_view(self): |
78 self.failUnless(AEF.rinlined.etype_get('CWUser', 'use_email', 'subject')) |
87 self.failUnless('main_inlined' in AFS.etype_get('CWUser', 'use_email', 'subject', 'EmailAddress')) |
79 self.failIf(AEF.rinlined.etype_get('CWUser', 'primary_email', 'subject')) |
88 self.failIf('main_inlined' in AFS.etype_get('CWUser', 'primary_email', 'subject', 'EmailAddress')) |
|
89 self.failUnless('main_relations' in AFS.etype_get('CWUser', 'primary_email', 'subject', 'EmailAddress')) |
80 |
90 |
81 def test_personne_relations_by_category(self): |
91 def test_personne_relations_by_category(self): |
82 e = self.vreg['etypes'].etype_class('Personne')(self.request()) |
92 e = self.vreg['etypes'].etype_class('Personne')(self.request()) |
83 self.assertListEquals(rbc(e, 'primary'), |
93 self.assertListEquals(rbc(e, 'main', 'attributes'), |
84 [('nom', 'subject'), |
94 [('nom', 'subject'), |
85 ('eid', 'subject') |
95 ('prenom', 'subject'), |
86 ]) |
|
87 self.assertListEquals(rbc(e, 'secondary'), |
|
88 [('prenom', 'subject'), |
|
89 ('sexe', 'subject'), |
96 ('sexe', 'subject'), |
90 ('promo', 'subject'), |
97 ('promo', 'subject'), |
91 ('titre', 'subject'), |
98 ('titre', 'subject'), |
92 ('ass', 'subject'), |
99 ('ass', 'subject'), |
93 ('web', 'subject'), |
100 ('web', 'subject'), |
94 ('tel', 'subject'), |
101 ('tel', 'subject'), |
95 ('fax', 'subject'), |
102 ('fax', 'subject'), |
96 ('datenaiss', 'subject'), |
103 ('datenaiss', 'subject'), |
97 ('test', 'subject'), |
104 ('test', 'subject'), |
98 ('description', 'subject'), |
105 ('description', 'subject'), |
99 ('salary', 'subject') |
106 ('salary', 'subject'), |
|
107 ('eid', 'subject') |
100 ]) |
108 ]) |
101 self.assertListEquals(rbc(e, 'metadata'), |
109 self.assertListEquals(rbc(e, 'muledit', 'attributes'), |
|
110 [('nom', 'subject'), |
|
111 ('eid', 'subject') |
|
112 ]) |
|
113 self.assertListEquals(rbc(e, 'main', 'metadata'), |
102 [('creation_date', 'subject'), |
114 [('creation_date', 'subject'), |
103 ('cwuri', 'subject'), |
115 ('cwuri', 'subject'), |
104 ('modification_date', 'subject'), |
116 ('modification_date', 'subject'), |
105 ('created_by', 'subject'), |
117 ('created_by', 'subject'), |
106 ('owned_by', 'subject'), |
118 ('owned_by', 'subject'), |
107 ]) |
119 ]) |
108 self.assertListEquals(rbc(e, 'generic'), |
120 self.assertListEquals(rbc(e, 'main', 'relations'), |
109 [('travaille', 'subject'), |
121 [('travaille', 'subject'), |
110 ('connait', 'object') |
122 ('connait', 'object') |
111 ]) |
123 ]) |
112 self.assertListEquals(rbc(e, 'generated'), |
124 self.assertListEquals(rbc(e, 'main', 'hidden'), |
113 [('is', 'subject'), |
125 [('is', 'subject'), |
114 ('has_text', 'subject'), |
126 ('has_text', 'subject'), |
115 ('identity', 'subject'), |
127 ('identity', 'subject'), |
116 ('is_instance_of', 'subject'), |
128 ('is_instance_of', 'subject'), |
117 ('identity', 'object'), |
129 ('identity', 'object'), |