author | sylvain.thenault@logilab.fr |
Thu, 23 Apr 2009 16:08:40 +0200 | |
branch | tls-sprint |
changeset 1447 | a1ca676294f0 |
parent 1398 | 5fe84a5f7035 |
child 1533 | bcd4bfff658b |
permissions | -rw-r--r-- |
1287 | 1 |
from logilab.common.testlib import unittest_main |
2 |
from cubicweb.devtools.apptest import EnvBasedTC |
|
1300 | 3 |
from cubicweb.devtools.testlib import WebTest |
1287 | 4 |
from cubicweb.web.views.editforms import AutomaticEntityForm as AEF |
1359 | 5 |
from cubicweb.web.formwidgets import AutoCompletionWidget |
1287 | 6 |
def rbc(entity, category): |
7 |
return [(rschema.type, x) for rschema, tschemas, x in AEF.erelations_by_category(entity, category)] |
|
8 |
||
9 |
class AutomaticEntityFormTC(EnvBasedTC): |
|
10 |
||
1359 | 11 |
def test_custom_widget(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
12 |
AEF.rwidgets.set_rtag(AutoCompletionWidget, 'login', 'subject', 'CWUser') |
1359 | 13 |
form = self.vreg.select_object('forms', 'edition', self.request(), None, |
14 |
entity=self.user()) |
|
15 |
field = form.field_by_name('login') |
|
16 |
self.assertIsInstance(field.widget, AutoCompletionWidget) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
17 |
AEF.rwidgets.del_rtag('login', 'subject', 'CWUser') |
1359 | 18 |
|
19 |
||
1287 | 20 |
def test_euser_relations_by_category(self): |
21 |
#for (rtype, role, stype, otype), tag in AEF.rcategories._tagdefs.items(): |
|
22 |
# if rtype == 'tags': |
|
23 |
# print rtype, role, stype, otype, ':', tag |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
24 |
e = self.etype_instance('CWUser') |
1287 | 25 |
# see custom configuration in views.euser |
26 |
self.assertEquals(rbc(e, 'primary'), |
|
27 |
[('login', 'subject'), |
|
28 |
('upassword', 'subject'), |
|
29 |
('in_group', 'subject'), |
|
30 |
('in_state', 'subject'), |
|
31 |
('eid', 'subject'), |
|
32 |
]) |
|
33 |
self.assertListEquals(rbc(e, 'secondary'), |
|
34 |
[('firstname', 'subject'), |
|
35 |
('surname', 'subject') |
|
36 |
]) |
|
37 |
self.assertListEquals(rbc(e, 'metadata'), |
|
38 |
[('last_login_time', 'subject'), |
|
39 |
('created_by', 'subject'), |
|
40 |
('creation_date', 'subject'), |
|
41 |
('modification_date', 'subject'), |
|
42 |
('owned_by', 'subject'), |
|
43 |
('bookmarked_by', 'object'), |
|
44 |
]) |
|
45 |
self.assertListEquals(rbc(e, 'generic'), |
|
46 |
[('primary_email', 'subject'), |
|
47 |
('use_email', 'subject'), |
|
48 |
('connait', 'subject'), |
|
49 |
('checked_by', 'object'), |
|
50 |
]) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
51 |
# owned_by is defined both as subject and object relations on CWUser |
1287 | 52 |
self.assertListEquals(rbc(e, 'generated'), |
1300 | 53 |
[('has_text', 'subject'), |
54 |
('identity', 'subject'), |
|
55 |
('is', 'subject'), |
|
1287 | 56 |
('is_instance_of', 'subject'), |
57 |
('tags', 'object'), |
|
58 |
('for_user', 'object'), |
|
59 |
('created_by', 'object'), |
|
60 |
('wf_info_for', 'object'), |
|
61 |
('owned_by', 'object'), |
|
1300 | 62 |
('identity', 'object'), |
1287 | 63 |
]) |
1298 | 64 |
|
65 |
def test_inlined_view(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
66 |
self.failUnless(AEF.rinlined.etype_rtag('CWUser', 'use_email', 'subject')) |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
67 |
self.failIf(AEF.rinlined.etype_rtag('CWUser', 'primary_email', 'subject')) |
1300 | 68 |
|
1287 | 69 |
def test_personne_relations_by_category(self): |
70 |
e = self.etype_instance('Personne') |
|
71 |
self.assertListEquals(rbc(e, 'primary'), |
|
72 |
[('nom', 'subject'), |
|
73 |
('eid', 'subject') |
|
74 |
]) |
|
75 |
self.assertListEquals(rbc(e, 'secondary'), |
|
76 |
[('prenom', 'subject'), |
|
77 |
('sexe', 'subject'), |
|
78 |
('promo', 'subject'), |
|
79 |
('titre', 'subject'), |
|
80 |
('ass', 'subject'), |
|
81 |
('web', 'subject'), |
|
82 |
('tel', 'subject'), |
|
83 |
('fax', 'subject'), |
|
84 |
('datenaiss', 'subject'), |
|
85 |
('test', 'subject'), |
|
86 |
('description', 'subject'), |
|
87 |
('salary', 'subject') |
|
88 |
]) |
|
89 |
self.assertListEquals(rbc(e, 'metadata'), |
|
90 |
[('created_by', 'subject'), |
|
91 |
('creation_date', 'subject'), |
|
92 |
('modification_date', 'subject'), |
|
93 |
('owned_by', 'subject'), |
|
94 |
]) |
|
95 |
self.assertListEquals(rbc(e, 'generic'), |
|
96 |
[('travaille', 'subject'), |
|
97 |
('connait', 'object') |
|
98 |
]) |
|
99 |
self.assertListEquals(rbc(e, 'generated'), |
|
1300 | 100 |
[('has_text', 'subject'), |
101 |
('identity', 'subject'), |
|
102 |
('is', 'subject'), |
|
1287 | 103 |
('is_instance_of', 'subject'), |
1300 | 104 |
('identity', 'object'), |
1287 | 105 |
]) |
1300 | 106 |
|
107 |
def test_edition_form(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
108 |
rset = self.execute('CWUser X LIMIT 1') |
1300 | 109 |
form = self.vreg.select_object('forms', 'edition', rset.req, rset, |
110 |
row=0, col=0) |
|
111 |
# should be also selectable by specifying entity |
|
112 |
self.vreg.select_object('forms', 'edition', self.request(), None, |
|
113 |
entity=rset.get_entity(0, 0)) |
|
114 |
self.failIf(any(f for f in form.fields if f is None)) |
|
115 |
||
116 |
||
117 |
class FormViewsTC(WebTest): |
|
118 |
def test_delete_conf_formview(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
119 |
rset = self.execute('CWGroup X') |
1300 | 120 |
self.view('deleteconf', rset, template=None).source |
121 |
||
122 |
def test_automatic_edition_formview(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
123 |
rset = self.execute('CWUser X') |
1300 | 124 |
self.view('edition', rset, row=0, template=None).source |
125 |
||
126 |
def test_automatic_edition_formview(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
127 |
rset = self.execute('CWUser X') |
1300 | 128 |
self.view('copy', rset, row=0, template=None).source |
129 |
||
130 |
def test_automatic_creation_formview(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
131 |
self.view('creation', None, etype='CWUser', template=None).source |
1300 | 132 |
|
133 |
def test_automatic_muledit_formview(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
134 |
rset = self.execute('CWUser X') |
1300 | 135 |
self.view('muledit', rset, template=None).source |
136 |
||
137 |
def test_automatic_reledit_formview(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
138 |
rset = self.execute('CWUser X') |
1300 | 139 |
self.view('reledit', rset, row=0, rtype='login', template=None).source |
140 |
||
141 |
def test_automatic_inline_edit_formview(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
142 |
geid = self.execute('CWGroup X LIMIT 1')[0][0] |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
143 |
rset = self.execute('CWUser X LIMIT 1') |
1300 | 144 |
self.view('inline-edition', rset, row=0, rtype='in_group', peid=geid, template=None).source |
145 |
||
146 |
def test_automatic_inline_creation_formview(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
147 |
geid = self.execute('CWGroup X LIMIT 1')[0][0] |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1359
diff
changeset
|
148 |
self.view('inline-creation', None, etype='CWUser', rtype='in_group', peid=geid, template=None).source |
1300 | 149 |
|
150 |
||
1287 | 151 |
if __name__ == '__main__': |
152 |
unittest_main() |