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 |
|
5 |
|
|
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 |
|
|
11 |
def test_euser_relations_by_category(self): |
|
12 |
#for (rtype, role, stype, otype), tag in AEF.rcategories._tagdefs.items(): |
|
13 |
# if rtype == 'tags': |
|
14 |
# print rtype, role, stype, otype, ':', tag |
|
15 |
e = self.etype_instance('EUser') |
|
16 |
# see custom configuration in views.euser |
|
17 |
self.assertEquals(rbc(e, 'primary'), |
|
18 |
[('login', 'subject'), |
|
19 |
('upassword', 'subject'), |
|
20 |
('in_group', 'subject'), |
|
21 |
('in_state', 'subject'), |
|
22 |
('eid', 'subject'), |
|
23 |
]) |
|
24 |
self.assertListEquals(rbc(e, 'secondary'), |
|
25 |
[('firstname', 'subject'), |
|
26 |
('surname', 'subject') |
|
27 |
]) |
|
28 |
self.assertListEquals(rbc(e, 'metadata'), |
|
29 |
[('last_login_time', 'subject'), |
|
30 |
('created_by', 'subject'), |
|
31 |
('creation_date', 'subject'), |
|
32 |
('modification_date', 'subject'), |
|
33 |
('owned_by', 'subject'), |
|
34 |
('bookmarked_by', 'object'), |
|
35 |
]) |
|
36 |
self.assertListEquals(rbc(e, 'generic'), |
|
37 |
[('primary_email', 'subject'), |
|
38 |
('use_email', 'subject'), |
|
39 |
('connait', 'subject'), |
|
40 |
('checked_by', 'object'), |
|
41 |
]) |
|
42 |
# owned_by is defined both as subject and object relations on EUser |
|
43 |
self.assertListEquals(rbc(e, 'generated'), |
1300
|
44 |
[('has_text', 'subject'), |
|
45 |
('identity', 'subject'), |
|
46 |
('is', 'subject'), |
1287
|
47 |
('is_instance_of', 'subject'), |
|
48 |
('tags', 'object'), |
|
49 |
('for_user', 'object'), |
|
50 |
('created_by', 'object'), |
|
51 |
('wf_info_for', 'object'), |
|
52 |
('owned_by', 'object'), |
1300
|
53 |
('identity', 'object'), |
1287
|
54 |
]) |
1298
|
55 |
|
|
56 |
def test_inlined_view(self): |
|
57 |
self.failUnless(AEF.rinlined.etype_rtag('EUser', 'use_email', 'subject')) |
|
58 |
self.failIf(AEF.rinlined.etype_rtag('EUser', 'primary_email', 'subject')) |
1300
|
59 |
|
1287
|
60 |
def test_personne_relations_by_category(self): |
|
61 |
e = self.etype_instance('Personne') |
|
62 |
self.assertListEquals(rbc(e, 'primary'), |
|
63 |
[('nom', 'subject'), |
|
64 |
('eid', 'subject') |
|
65 |
]) |
|
66 |
self.assertListEquals(rbc(e, 'secondary'), |
|
67 |
[('prenom', 'subject'), |
|
68 |
('sexe', 'subject'), |
|
69 |
('promo', 'subject'), |
|
70 |
('titre', 'subject'), |
|
71 |
('ass', 'subject'), |
|
72 |
('web', 'subject'), |
|
73 |
('tel', 'subject'), |
|
74 |
('fax', 'subject'), |
|
75 |
('datenaiss', 'subject'), |
|
76 |
('test', 'subject'), |
|
77 |
('description', 'subject'), |
|
78 |
('salary', 'subject') |
|
79 |
]) |
|
80 |
self.assertListEquals(rbc(e, 'metadata'), |
|
81 |
[('created_by', 'subject'), |
|
82 |
('creation_date', 'subject'), |
|
83 |
('modification_date', 'subject'), |
|
84 |
('owned_by', 'subject'), |
|
85 |
]) |
|
86 |
self.assertListEquals(rbc(e, 'generic'), |
|
87 |
[('travaille', 'subject'), |
|
88 |
('connait', 'object') |
|
89 |
]) |
|
90 |
self.assertListEquals(rbc(e, 'generated'), |
1300
|
91 |
[('has_text', 'subject'), |
|
92 |
('identity', 'subject'), |
|
93 |
('is', 'subject'), |
1287
|
94 |
('is_instance_of', 'subject'), |
1300
|
95 |
('identity', 'object'), |
1287
|
96 |
]) |
1300
|
97 |
|
|
98 |
def test_edition_form(self): |
|
99 |
rset = self.execute('EUser X LIMIT 1') |
|
100 |
form = self.vreg.select_object('forms', 'edition', rset.req, rset, |
|
101 |
row=0, col=0) |
|
102 |
# should be also selectable by specifying entity |
|
103 |
self.vreg.select_object('forms', 'edition', self.request(), None, |
|
104 |
entity=rset.get_entity(0, 0)) |
|
105 |
self.failIf(any(f for f in form.fields if f is None)) |
|
106 |
|
|
107 |
|
|
108 |
class FormViewsTC(WebTest): |
|
109 |
def test_delete_conf_formview(self): |
|
110 |
rset = self.execute('EGroup X') |
|
111 |
self.view('deleteconf', rset, template=None).source |
|
112 |
|
|
113 |
def test_automatic_edition_formview(self): |
|
114 |
rset = self.execute('EUser X') |
|
115 |
self.view('edition', rset, row=0, template=None).source |
|
116 |
|
|
117 |
def test_automatic_edition_formview(self): |
|
118 |
rset = self.execute('EUser X') |
|
119 |
self.view('copy', rset, row=0, template=None).source |
|
120 |
|
|
121 |
def test_automatic_creation_formview(self): |
|
122 |
self.view('creation', None, etype='EUser', template=None).source |
|
123 |
|
|
124 |
def test_automatic_muledit_formview(self): |
|
125 |
rset = self.execute('EUser X') |
|
126 |
self.view('muledit', rset, template=None).source |
|
127 |
|
|
128 |
def test_automatic_reledit_formview(self): |
|
129 |
rset = self.execute('EUser X') |
|
130 |
self.view('reledit', rset, row=0, rtype='login', template=None).source |
|
131 |
|
|
132 |
def test_automatic_inline_edit_formview(self): |
|
133 |
geid = self.execute('EGroup X LIMIT 1')[0][0] |
|
134 |
rset = self.execute('EUser X LIMIT 1') |
|
135 |
self.view('inline-edition', rset, row=0, rtype='in_group', peid=geid, template=None).source |
|
136 |
|
|
137 |
def test_automatic_inline_creation_formview(self): |
|
138 |
geid = self.execute('EGroup X LIMIT 1')[0][0] |
|
139 |
self.view('inline-creation', None, etype='EUser', rtype='in_group', peid=geid, template=None).source |
|
140 |
|
|
141 |
|
1287
|
142 |
if __name__ == '__main__': |
|
143 |
unittest_main() |