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): |
|
12 |
AEF.rwidgets.set_rtag(AutoCompletionWidget, 'login', 'subject', 'EUser') |
|
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) |
|
17 |
AEF.rwidgets.del_rtag('login', 'subject', 'EUser') |
|
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 |
|
24 |
e = self.etype_instance('EUser') |
|
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 |
]) |
|
51 |
# owned_by is defined both as subject and object relations on EUser |
|
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): |
|
66 |
self.failUnless(AEF.rinlined.etype_rtag('EUser', 'use_email', 'subject')) |
|
67 |
self.failIf(AEF.rinlined.etype_rtag('EUser', '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): |
|
108 |
rset = self.execute('EUser X LIMIT 1') |
|
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): |
|
119 |
rset = self.execute('EGroup X') |
|
120 |
self.view('deleteconf', rset, template=None).source |
|
121 |
|
|
122 |
def test_automatic_edition_formview(self): |
|
123 |
rset = self.execute('EUser X') |
|
124 |
self.view('edition', rset, row=0, template=None).source |
|
125 |
|
|
126 |
def test_automatic_edition_formview(self): |
|
127 |
rset = self.execute('EUser X') |
|
128 |
self.view('copy', rset, row=0, template=None).source |
|
129 |
|
|
130 |
def test_automatic_creation_formview(self): |
|
131 |
self.view('creation', None, etype='EUser', template=None).source |
|
132 |
|
|
133 |
def test_automatic_muledit_formview(self): |
|
134 |
rset = self.execute('EUser X') |
|
135 |
self.view('muledit', rset, template=None).source |
|
136 |
|
|
137 |
def test_automatic_reledit_formview(self): |
|
138 |
rset = self.execute('EUser X') |
|
139 |
self.view('reledit', rset, row=0, rtype='login', template=None).source |
|
140 |
|
|
141 |
def test_automatic_inline_edit_formview(self): |
|
142 |
geid = self.execute('EGroup X LIMIT 1')[0][0] |
|
143 |
rset = self.execute('EUser X LIMIT 1') |
|
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): |
|
147 |
geid = self.execute('EGroup X LIMIT 1')[0][0] |
|
148 |
self.view('inline-creation', None, etype='EUser', rtype='in_group', peid=geid, template=None).source |
|
149 |
|
|
150 |
|
1287
|
151 |
if __name__ == '__main__': |
|
152 |
unittest_main() |