unittest_views_editforms.py 6.99 KB
Newer Older
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
1
2
from logilab.common.testlib import unittest_main
from cubicweb.devtools.apptest import EnvBasedTC
3
from cubicweb.devtools.testlib import WebTest
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
4
from cubicweb.web.views.autoform import AutomaticEntityForm as AEF
5
from cubicweb.web.formwidgets import AutoCompletionWidget
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
6
7
8
9
10
def rbc(entity, category):
    return [(rschema.type, x) for rschema, tschemas, x in AEF.erelations_by_category(entity, category)]

class AutomaticEntityFormTC(EnvBasedTC):

11
    def test_custom_widget(self):
12
        AEF.rwidgets.tag_relation('!CWUser', 'login', '*', AutoCompletionWidget)
13
14
15
16
        form = self.vreg.select_object('forms', 'edition', self.request(), None,
                                       entity=self.user())
        field = form.field_by_name('login')
        self.assertIsInstance(field.widget, AutoCompletionWidget)
17
        AEF.rwidgets.del_rtag('!CWUser', 'login', '*')
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
18

19

sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
20
21
22
23
    def test_euser_relations_by_category(self):
        #for (rtype, role, stype, otype), tag in AEF.rcategories._tagdefs.items():
        #    if rtype == 'tags':
        #        print rtype, role, stype, otype, ':', tag
24
        e = self.etype_instance('CWUser')
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
        # see custom configuration in views.euser
        self.assertEquals(rbc(e, 'primary'),
                          [('login', 'subject'),
                           ('upassword', 'subject'),
                           ('in_group', 'subject'),
                           ('in_state', 'subject'),
                           ('eid', 'subject'),
                           ])
        self.assertListEquals(rbc(e, 'secondary'),
                              [('firstname', 'subject'),
                               ('surname', 'subject')
                               ])
        self.assertListEquals(rbc(e, 'metadata'),
                              [('last_login_time', 'subject'),
                               ('created_by', 'subject'),
                               ('creation_date', 'subject'),
                               ('modification_date', 'subject'),
                               ('owned_by', 'subject'),
                               ('bookmarked_by', 'object'),
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
44
                               ])
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
45
        self.assertListEquals(rbc(e, 'generic'),
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
46
                              [('connait', 'subject'),
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
47
48
                               ('checked_by', 'object'),
                               ])
49
        # owned_by is defined both as subject and object relations on CWUser
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
50
        self.assertListEquals(rbc(e, 'generated'),
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
51
52
53
                              [('primary_email', 'subject'),
                               ('use_email', 'subject'),
                               ('has_text', 'subject'),
54
55
                               ('identity', 'subject'),
                               ('is', 'subject'),
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
56
57
58
59
60
61
                               ('is_instance_of', 'subject'),
                               ('tags', 'object'),
                               ('for_user', 'object'),
                               ('created_by', 'object'),
                               ('wf_info_for', 'object'),
                               ('owned_by', 'object'),
62
                               ('identity', 'object'),
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
63
                               ])
64
65

    def test_inlined_view(self):
66
67
        self.failUnless(AEF.rinlined.etype_get('CWUser', 'use_email', 'subject'))
        self.failIf(AEF.rinlined.etype_get('CWUser', 'primary_email', 'subject'))
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
68

sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
    def test_personne_relations_by_category(self):
        e = self.etype_instance('Personne')
        self.assertListEquals(rbc(e, 'primary'),
                              [('nom', 'subject'),
                               ('eid', 'subject')
                               ])
        self.assertListEquals(rbc(e, 'secondary'),
                              [('prenom', 'subject'),
                               ('sexe', 'subject'),
                               ('promo', 'subject'),
                               ('titre', 'subject'),
                               ('ass', 'subject'),
                               ('web', 'subject'),
                               ('tel', 'subject'),
                               ('fax', 'subject'),
                               ('datenaiss', 'subject'),
                               ('test', 'subject'),
                               ('description', 'subject'),
                               ('salary', 'subject')
                               ])
        self.assertListEquals(rbc(e, 'metadata'),
                              [('created_by', 'subject'),
                               ('creation_date', 'subject'),
                               ('modification_date', 'subject'),
                               ('owned_by', 'subject'),
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
94
                               ])
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
95
96
97
98
99
        self.assertListEquals(rbc(e, 'generic'),
                              [('travaille', 'subject'),
                               ('connait', 'object')
                               ])
        self.assertListEquals(rbc(e, 'generated'),
100
101
102
                              [('has_text', 'subject'),
                               ('identity', 'subject'),
                               ('is', 'subject'),
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
103
                               ('is_instance_of', 'subject'),
104
                               ('identity', 'object'),
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
105
                               ])
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
106

107
    def test_edition_form(self):
108
        rset = self.execute('CWUser X LIMIT 1')
109
110
111
112
113
114
        form = self.vreg.select_object('forms', 'edition', rset.req, rset,
                                       row=0, col=0)
        # should be also selectable by specifying entity
        self.vreg.select_object('forms', 'edition', self.request(), None,
                                entity=rset.get_entity(0, 0))
        self.failIf(any(f for f in form.fields if f is None))
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
115
116


117
118
class FormViewsTC(WebTest):
    def test_delete_conf_formview(self):
119
        rset = self.execute('CWGroup X')
120
        self.view('deleteconf', rset, template=None).source
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
121

122
    def test_automatic_edition_formview(self):
123
        rset = self.execute('CWUser X')
124
        self.view('edition', rset, row=0, template=None).source
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
125

126
    def test_automatic_edition_formview(self):
127
        rset = self.execute('CWUser X')
128
        self.view('copy', rset, row=0, template=None).source
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
129

130
    def test_automatic_creation_formview(self):
131
        self.view('creation', None, etype='CWUser', template=None).source
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
132

133
    def test_automatic_muledit_formview(self):
134
        rset = self.execute('CWUser X')
135
        self.view('muledit', rset, template=None).source
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
136

137
    def test_automatic_reledit_formview(self):
138
        rset = self.execute('CWUser X')
139
        self.view('reledit', rset, row=0, rtype='login', template=None).source
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
140

141
    def test_automatic_inline_edit_formview(self):
142
143
        geid = self.execute('CWGroup X LIMIT 1')[0][0]
        rset = self.execute('CWUser X LIMIT 1')
144
        self.view('inline-edition', rset, row=0, rtype='in_group', peid=geid, template=None).source
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
145

146
    def test_automatic_inline_creation_formview(self):
147
148
        geid = self.execute('CWGroup X LIMIT 1')[0][0]
        self.view('inline-creation', None, etype='CWUser', rtype='in_group', peid=geid, template=None).source
149

sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
150

sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
151
152
if __name__ == '__main__':
    unittest_main()