1287
|
1 |
from logilab.common.testlib import unittest_main |
|
2 |
from cubicweb.devtools.apptest import EnvBasedTC |
|
3 |
from cubicweb.web.views.editforms import AutomaticEntityForm as AEF |
|
4 |
|
|
5 |
def rbc(entity, category): |
|
6 |
return [(rschema.type, x) for rschema, tschemas, x in AEF.erelations_by_category(entity, category)] |
|
7 |
|
|
8 |
class AutomaticEntityFormTC(EnvBasedTC): |
|
9 |
|
|
10 |
def test_euser_relations_by_category(self): |
|
11 |
#for (rtype, role, stype, otype), tag in AEF.rcategories._tagdefs.items(): |
|
12 |
# if rtype == 'tags': |
|
13 |
# print rtype, role, stype, otype, ':', tag |
|
14 |
e = self.etype_instance('EUser') |
|
15 |
# see custom configuration in views.euser |
|
16 |
self.assertEquals(rbc(e, 'primary'), |
|
17 |
[('login', 'subject'), |
|
18 |
('upassword', 'subject'), |
|
19 |
('in_group', 'subject'), |
|
20 |
('in_state', 'subject'), |
|
21 |
('eid', 'subject'), |
|
22 |
]) |
|
23 |
self.assertListEquals(rbc(e, 'secondary'), |
|
24 |
[('firstname', 'subject'), |
|
25 |
('surname', 'subject') |
|
26 |
]) |
|
27 |
self.assertListEquals(rbc(e, 'metadata'), |
|
28 |
[('last_login_time', 'subject'), |
|
29 |
('created_by', 'subject'), |
|
30 |
('creation_date', 'subject'), |
|
31 |
('modification_date', 'subject'), |
|
32 |
('owned_by', 'subject'), |
|
33 |
('bookmarked_by', 'object'), |
|
34 |
]) |
|
35 |
self.assertListEquals(rbc(e, 'generic'), |
|
36 |
[('primary_email', 'subject'), |
|
37 |
('use_email', 'subject'), |
|
38 |
('connait', 'subject'), |
|
39 |
('checked_by', 'object'), |
|
40 |
]) |
|
41 |
# owned_by is defined both as subject and object relations on EUser |
|
42 |
self.assertListEquals(rbc(e, 'generated'), |
|
43 |
[('is', 'subject'), |
|
44 |
('is_instance_of', 'subject'), |
|
45 |
('tags', 'object'), |
|
46 |
('for_user', 'object'), |
|
47 |
('created_by', 'object'), |
|
48 |
('wf_info_for', 'object'), |
|
49 |
('owned_by', 'object'), |
|
50 |
]) |
|
51 |
|
|
52 |
def test_personne_relations_by_category(self): |
|
53 |
e = self.etype_instance('Personne') |
|
54 |
self.assertListEquals(rbc(e, 'primary'), |
|
55 |
[('nom', 'subject'), |
|
56 |
('eid', 'subject') |
|
57 |
]) |
|
58 |
self.assertListEquals(rbc(e, 'secondary'), |
|
59 |
[('prenom', 'subject'), |
|
60 |
('sexe', 'subject'), |
|
61 |
('promo', 'subject'), |
|
62 |
('titre', 'subject'), |
|
63 |
('ass', 'subject'), |
|
64 |
('web', 'subject'), |
|
65 |
('tel', 'subject'), |
|
66 |
('fax', 'subject'), |
|
67 |
('datenaiss', 'subject'), |
|
68 |
('test', 'subject'), |
|
69 |
('description', 'subject'), |
|
70 |
('salary', 'subject') |
|
71 |
]) |
|
72 |
self.assertListEquals(rbc(e, 'metadata'), |
|
73 |
[('created_by', 'subject'), |
|
74 |
('creation_date', 'subject'), |
|
75 |
('modification_date', 'subject'), |
|
76 |
('owned_by', 'subject'), |
|
77 |
]) |
|
78 |
self.assertListEquals(rbc(e, 'generic'), |
|
79 |
[('travaille', 'subject'), |
|
80 |
('connait', 'object') |
|
81 |
]) |
|
82 |
self.assertListEquals(rbc(e, 'generated'), |
|
83 |
[('is', 'subject'), |
|
84 |
('is_instance_of', 'subject'), |
|
85 |
]) |
|
86 |
if __name__ == '__main__': |
|
87 |
unittest_main() |