web/test/unittest_views_editforms.py
author sylvain.thenault@logilab.fr
Wed, 08 Apr 2009 14:11:34 +0200
branchtls-sprint
changeset 1300 62d2b890a980
parent 1298 ca02a2b5e9be
child 1359 bef6891393d7
permissions -rw-r--r--
move tests where they belong
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
     1
from logilab.common.testlib import unittest_main
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
     2
from cubicweb.devtools.apptest import EnvBasedTC
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
     3
from cubicweb.devtools.testlib import WebTest
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
     4
from cubicweb.web.views.editforms import AutomaticEntityForm as AEF
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
     5
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
     6
def rbc(entity, category):
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
     7
    return [(rschema.type, x) for rschema, tschemas, x in AEF.erelations_by_category(entity, category)]
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
     8
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
     9
class AutomaticEntityFormTC(EnvBasedTC):
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    10
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    11
    def test_euser_relations_by_category(self):
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    12
        #for (rtype, role, stype, otype), tag in AEF.rcategories._tagdefs.items():
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    13
        #    if rtype == 'tags':
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    14
        #        print rtype, role, stype, otype, ':', tag
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    15
        e = self.etype_instance('EUser')
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    16
        # see custom configuration in views.euser
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    17
        self.assertEquals(rbc(e, 'primary'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    18
                          [('login', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    19
                           ('upassword', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    20
                           ('in_group', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    21
                           ('in_state', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    22
                           ('eid', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    23
                           ])
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    24
        self.assertListEquals(rbc(e, 'secondary'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    25
                              [('firstname', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    26
                               ('surname', 'subject')
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    27
                               ])
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    28
        self.assertListEquals(rbc(e, 'metadata'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    29
                              [('last_login_time', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    30
                               ('created_by', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    31
                               ('creation_date', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    32
                               ('modification_date', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    33
                               ('owned_by', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    34
                               ('bookmarked_by', 'object'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    35
                               ])        
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    36
        self.assertListEquals(rbc(e, 'generic'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    37
                              [('primary_email', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    38
                               ('use_email', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    39
                               ('connait', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    40
                               ('checked_by', 'object'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    41
                               ])
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    42
        # owned_by is defined both as subject and object relations on EUser
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    43
        self.assertListEquals(rbc(e, 'generated'),
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
    44
                              [('has_text', 'subject'),
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
    45
                               ('identity', 'subject'),
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
    46
                               ('is', 'subject'),
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    47
                               ('is_instance_of', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    48
                               ('tags', 'object'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    49
                               ('for_user', 'object'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    50
                               ('created_by', 'object'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    51
                               ('wf_info_for', 'object'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    52
                               ('owned_by', 'object'),
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
    53
                               ('identity', 'object'),
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    54
                               ])
1298
ca02a2b5e9be test inlined rtags
sylvain.thenault@logilab.fr
parents: 1287
diff changeset
    55
ca02a2b5e9be test inlined rtags
sylvain.thenault@logilab.fr
parents: 1287
diff changeset
    56
    def test_inlined_view(self):
ca02a2b5e9be test inlined rtags
sylvain.thenault@logilab.fr
parents: 1287
diff changeset
    57
        self.failUnless(AEF.rinlined.etype_rtag('EUser', 'use_email', 'subject'))
ca02a2b5e9be test inlined rtags
sylvain.thenault@logilab.fr
parents: 1287
diff changeset
    58
        self.failIf(AEF.rinlined.etype_rtag('EUser', 'primary_email', 'subject'))
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
    59
        
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    60
    def test_personne_relations_by_category(self):
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    61
        e = self.etype_instance('Personne')
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    62
        self.assertListEquals(rbc(e, 'primary'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    63
                              [('nom', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    64
                               ('eid', 'subject')
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    65
                               ])
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    66
        self.assertListEquals(rbc(e, 'secondary'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    67
                              [('prenom', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    68
                               ('sexe', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    69
                               ('promo', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    70
                               ('titre', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    71
                               ('ass', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    72
                               ('web', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    73
                               ('tel', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    74
                               ('fax', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    75
                               ('datenaiss', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    76
                               ('test', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    77
                               ('description', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    78
                               ('salary', 'subject')
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    79
                               ])
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    80
        self.assertListEquals(rbc(e, 'metadata'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    81
                              [('created_by', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    82
                               ('creation_date', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    83
                               ('modification_date', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    84
                               ('owned_by', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    85
                               ])        
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    86
        self.assertListEquals(rbc(e, 'generic'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    87
                              [('travaille', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    88
                               ('connait', 'object')
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    89
                               ])
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    90
        self.assertListEquals(rbc(e, 'generated'),
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
    91
                              [('has_text', 'subject'),
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
    92
                               ('identity', 'subject'),
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
    93
                               ('is', 'subject'),
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    94
                               ('is_instance_of', 'subject'),
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
    95
                               ('identity', 'object'),
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    96
                               ])
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
    97
        
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
    98
    def test_edition_form(self):
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
    99
        rset = self.execute('EUser X LIMIT 1')
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   100
        form = self.vreg.select_object('forms', 'edition', rset.req, rset,
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   101
                                       row=0, col=0)
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   102
        # should be also selectable by specifying entity
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   103
        self.vreg.select_object('forms', 'edition', self.request(), None,
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   104
                                entity=rset.get_entity(0, 0))
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   105
        self.failIf(any(f for f in form.fields if f is None))
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   106
        
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   107
        
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   108
class FormViewsTC(WebTest):
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   109
    def test_delete_conf_formview(self):
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   110
        rset = self.execute('EGroup X')
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   111
        self.view('deleteconf', rset, template=None).source
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   112
        
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   113
    def test_automatic_edition_formview(self):
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   114
        rset = self.execute('EUser X')
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   115
        self.view('edition', rset, row=0, template=None).source
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   116
        
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   117
    def test_automatic_edition_formview(self):
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   118
        rset = self.execute('EUser X')
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   119
        self.view('copy', rset, row=0, template=None).source
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   120
        
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   121
    def test_automatic_creation_formview(self):
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   122
        self.view('creation', None, etype='EUser', template=None).source
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   123
        
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   124
    def test_automatic_muledit_formview(self):
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   125
        rset = self.execute('EUser X')
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   126
        self.view('muledit', rset, template=None).source
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   127
        
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   128
    def test_automatic_reledit_formview(self):
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   129
        rset = self.execute('EUser X')
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   130
        self.view('reledit', rset, row=0, rtype='login', template=None).source
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   131
        
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   132
    def test_automatic_inline_edit_formview(self):
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   133
        geid = self.execute('EGroup X LIMIT 1')[0][0]
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   134
        rset = self.execute('EUser X LIMIT 1')
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   135
        self.view('inline-edition', rset, row=0, rtype='in_group', peid=geid, template=None).source
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   136
                              
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   137
    def test_automatic_inline_creation_formview(self):
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   138
        geid = self.execute('EGroup X LIMIT 1')[0][0]
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   139
        self.view('inline-creation', None, etype='EUser', rtype='in_group', peid=geid, template=None).source
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   140
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   141
        
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
   142
if __name__ == '__main__':
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
   143
    unittest_main()