unittest_views_editforms.py 7.4 KB
Newer Older
1
2
3
4
5
6
7
"""

:organization: Logilab
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
"""
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
8
9
from logilab.common.testlib import unittest_main
from cubicweb.devtools.apptest import EnvBasedTC
10
from cubicweb.devtools.testlib import WebTest
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
11
from cubicweb.web.views.autoform import AutomaticEntityForm as AEF
12
from cubicweb.web.formwidgets import AutoCompletionWidget
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
13
14
15
16
17
def rbc(entity, category):
    return [(rschema.type, x) for rschema, tschemas, x in AEF.erelations_by_category(entity, category)]

class AutomaticEntityFormTC(EnvBasedTC):

18
    def test_custom_widget(self):
19
        AEF.rfields_kwargs.tag_subject_of(('CWUser', 'login', '*'),
Sylvain Thénault's avatar
Sylvain Thénault committed
20
                                          {'widget': AutoCompletionWidget(autocomplete_initfunc='get_logins')})
21
22
        form = self.vreg.select('forms', 'edition', self.request(),
                                entity=self.user())
23
24
        field = form.field_by_name('login')
        self.assertIsInstance(field.widget, AutoCompletionWidget)
25
        AEF.rfields_kwargs.del_rtag('CWUser', 'login', '*', 'subject')
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
26

27

28
    def test_cwuser_relations_by_category(self):
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
29
30
31
        #for (rtype, role, stype, otype), tag in AEF.rcategories._tagdefs.items():
        #    if rtype == 'tags':
        #        print rtype, role, stype, otype, ':', tag
32
        e = self.etype_instance('CWUser')
33
        # see custom configuration in views.cwuser
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
        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'),
49
                               ('cwuri', 'subject'),
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
50
51
52
                               ('modification_date', 'subject'),
                               ('owned_by', 'subject'),
                               ('bookmarked_by', 'object'),
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
53
                               ])
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
54
        self.assertListEquals(rbc(e, 'generic'),
55
56
                              [('primary_email', 'subject'),
                               ('connait', 'subject'),
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
57
58
                               ('checked_by', 'object'),
                               ])
59
        # owned_by is defined both as subject and object relations on CWUser
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
60
        self.assertListEquals(rbc(e, 'generated'),
61
                              [('use_email', 'subject'),
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
62
                               ('has_text', 'subject'),
63
64
                               ('identity', 'subject'),
                               ('is', 'subject'),
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
65
66
67
68
69
70
                               ('is_instance_of', 'subject'),
                               ('tags', 'object'),
                               ('for_user', 'object'),
                               ('created_by', 'object'),
                               ('wf_info_for', 'object'),
                               ('owned_by', 'object'),
71
                               ('identity', 'object'),
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
72
                               ])
73
74

    def test_inlined_view(self):
75
76
        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
77

sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
    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'),
101
                               ('cwuri', 'subject'),
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
102
103
                               ('modification_date', 'subject'),
                               ('owned_by', 'subject'),
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
104
                               ])
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
105
106
107
108
109
        self.assertListEquals(rbc(e, 'generic'),
                              [('travaille', 'subject'),
                               ('connait', 'object')
                               ])
        self.assertListEquals(rbc(e, 'generated'),
110
111
112
                              [('has_text', 'subject'),
                               ('identity', 'subject'),
                               ('is', 'subject'),
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
113
                               ('is_instance_of', 'subject'),
114
                               ('identity', 'object'),
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
115
                               ])
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
116

117
    def test_edition_form(self):
118
        rset = self.execute('CWUser X LIMIT 1')
119
120
        form = self.vreg.select('forms', 'edition', rset.req, rset=rset,
                                row=0, col=0)
121
        # should be also selectable by specifying entity
122
123
        self.vreg.select('forms', 'edition', rset.req,
                         entity=rset.get_entity(0, 0))
124
        self.failIf(any(f for f in form.fields if f is None))
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
125
126


127
128
class FormViewsTC(WebTest):
    def test_delete_conf_formview(self):
129
        rset = self.execute('CWGroup X')
130
        self.view('deleteconf', rset, template=None).source
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
131

132
    def test_automatic_edition_formview(self):
133
        rset = self.execute('CWUser X')
134
        self.view('edition', rset, row=0, template=None).source
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
135

136
    def test_automatic_edition_formview(self):
137
        rset = self.execute('CWUser X')
138
        self.view('copy', rset, row=0, template=None).source
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
139

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

143
    def test_automatic_muledit_formview(self):
144
        rset = self.execute('CWUser X')
145
        self.view('muledit', rset, template=None).source
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
146

147
    def test_automatic_reledit_formview(self):
148
        rset = self.execute('CWUser X')
149
        self.view('reledit', rset, row=0, rtype='login', template=None).source
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
150

151
    def test_automatic_inline_edit_formview(self):
152
153
        geid = self.execute('CWGroup X LIMIT 1')[0][0]
        rset = self.execute('CWUser X LIMIT 1')
154
        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
155

156
    def test_automatic_inline_creation_formview(self):
157
158
        geid = self.execute('CWGroup X LIMIT 1')[0][0]
        self.view('inline-creation', None, etype='CWUser', rtype='in_group', peid=geid, template=None).source
159

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

sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
161
162
if __name__ == '__main__':
    unittest_main()
163