web/test/unittest_views_editforms.py
author sylvain.thenault@logilab.fr
Mon, 04 May 2009 15:49:36 +0200
branchtls-sprint
changeset 1654 57b9fd2462b8
parent 1540 996355824825
child 1721 694f6a50e138
permissions -rw-r--r--
test updates
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
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1540
diff changeset
     4
from cubicweb.web.views.autoform import AutomaticEntityForm as AEF
1359
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
     5
from cubicweb.web.formwidgets import AutoCompletionWidget
1287
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
1359
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    11
    def test_custom_widget(self):
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    12
        AEF.rwidgets.tag_relation(AutoCompletionWidget,
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    13
                                  ('CWUser', 'login', '*'), 'subject')
1359
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    14
        form = self.vreg.select_object('forms', 'edition', self.request(), None,
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    15
                                       entity=self.user())
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    16
        field = form.field_by_name('login')
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    17
        self.assertIsInstance(field.widget, AutoCompletionWidget)
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1540
diff changeset
    18
        AEF.rwidgets.del_rtag(('CWUser', 'login', '*'),'subject')
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    19
1359
bef6891393d7 backport some tests
sylvain.thenault@logilab.fr
parents: 1300
diff changeset
    20
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    21
    def test_euser_relations_by_category(self):
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    22
        #for (rtype, role, stype, otype), tag in AEF.rcategories._tagdefs.items():
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    23
        #    if rtype == 'tags':
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    24
        #        print rtype, role, stype, otype, ':', tag
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1359
diff changeset
    25
        e = self.etype_instance('CWUser')
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    26
        # see custom configuration in views.euser
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    27
        self.assertEquals(rbc(e, 'primary'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    28
                          [('login', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    29
                           ('upassword', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    30
                           ('in_group', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    31
                           ('in_state', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    32
                           ('eid', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    33
                           ])
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    34
        self.assertListEquals(rbc(e, 'secondary'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    35
                              [('firstname', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    36
                               ('surname', 'subject')
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    37
                               ])
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    38
        self.assertListEquals(rbc(e, 'metadata'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    39
                              [('last_login_time', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    40
                               ('created_by', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    41
                               ('creation_date', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    42
                               ('modification_date', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    43
                               ('owned_by', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    44
                               ('bookmarked_by', 'object'),
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    45
                               ])
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    46
        self.assertListEquals(rbc(e, 'generic'),
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1540
diff changeset
    47
                              [('connait', 'subject'),
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    48
                               ('checked_by', 'object'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    49
                               ])
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1359
diff changeset
    50
        # owned_by is defined both as subject and object relations on CWUser
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    51
        self.assertListEquals(rbc(e, 'generated'),
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1540
diff changeset
    52
                              [('primary_email', 'subject'),
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1540
diff changeset
    53
                               ('use_email', 'subject'),
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1540
diff changeset
    54
                               ('has_text', 'subject'),
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
    55
                               ('identity', 'subject'),
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
    56
                               ('is', 'subject'),
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    57
                               ('is_instance_of', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    58
                               ('tags', 'object'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    59
                               ('for_user', 'object'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    60
                               ('created_by', 'object'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    61
                               ('wf_info_for', 'object'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    62
                               ('owned_by', 'object'),
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
    63
                               ('identity', 'object'),
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    64
                               ])
1298
ca02a2b5e9be test inlined rtags
sylvain.thenault@logilab.fr
parents: 1287
diff changeset
    65
ca02a2b5e9be test inlined rtags
sylvain.thenault@logilab.fr
parents: 1287
diff changeset
    66
    def test_inlined_view(self):
1540
996355824825 more rtags api change propagation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1533
diff changeset
    67
        self.failUnless(AEF.rinlined.etype_get('CWUser', 'use_email', 'subject'))
996355824825 more rtags api change propagation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1533
diff changeset
    68
        self.failIf(AEF.rinlined.etype_get('CWUser', 'primary_email', 'subject'))
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    69
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    70
    def test_personne_relations_by_category(self):
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    71
        e = self.etype_instance('Personne')
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    72
        self.assertListEquals(rbc(e, 'primary'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    73
                              [('nom', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    74
                               ('eid', 'subject')
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    75
                               ])
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    76
        self.assertListEquals(rbc(e, 'secondary'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    77
                              [('prenom', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    78
                               ('sexe', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    79
                               ('promo', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    80
                               ('titre', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    81
                               ('ass', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    82
                               ('web', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    83
                               ('tel', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    84
                               ('fax', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    85
                               ('datenaiss', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    86
                               ('test', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    87
                               ('description', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    88
                               ('salary', 'subject')
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, 'metadata'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    91
                              [('created_by', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    92
                               ('creation_date', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    93
                               ('modification_date', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    94
                               ('owned_by', 'subject'),
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    95
                               ])
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    96
        self.assertListEquals(rbc(e, 'generic'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    97
                              [('travaille', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    98
                               ('connait', 'object')
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    99
                               ])
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
   100
        self.assertListEquals(rbc(e, 'generated'),
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   101
                              [('has_text', 'subject'),
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   102
                               ('identity', 'subject'),
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   103
                               ('is', 'subject'),
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
   104
                               ('is_instance_of', 'subject'),
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   105
                               ('identity', 'object'),
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
   106
                               ])
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   107
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   108
    def test_edition_form(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1359
diff changeset
   109
        rset = self.execute('CWUser X LIMIT 1')
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   110
        form = self.vreg.select_object('forms', 'edition', rset.req, rset,
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   111
                                       row=0, col=0)
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   112
        # should be also selectable by specifying entity
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   113
        self.vreg.select_object('forms', 'edition', self.request(), None,
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   114
                                entity=rset.get_entity(0, 0))
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   115
        self.failIf(any(f for f in form.fields if f is None))
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   116
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   117
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   118
class FormViewsTC(WebTest):
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   119
    def test_delete_conf_formview(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1359
diff changeset
   120
        rset = self.execute('CWGroup X')
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   121
        self.view('deleteconf', rset, template=None).source
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   122
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   123
    def test_automatic_edition_formview(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1359
diff changeset
   124
        rset = self.execute('CWUser X')
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   125
        self.view('edition', rset, row=0, template=None).source
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   126
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   127
    def test_automatic_edition_formview(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1359
diff changeset
   128
        rset = self.execute('CWUser X')
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   129
        self.view('copy', rset, row=0, template=None).source
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   130
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   131
    def test_automatic_creation_formview(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1359
diff changeset
   132
        self.view('creation', None, etype='CWUser', template=None).source
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   133
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   134
    def test_automatic_muledit_formview(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1359
diff changeset
   135
        rset = self.execute('CWUser X')
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   136
        self.view('muledit', rset, template=None).source
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   137
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   138
    def test_automatic_reledit_formview(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1359
diff changeset
   139
        rset = self.execute('CWUser X')
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   140
        self.view('reledit', rset, row=0, rtype='login', template=None).source
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   141
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   142
    def test_automatic_inline_edit_formview(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1359
diff changeset
   143
        geid = self.execute('CWGroup X LIMIT 1')[0][0]
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1359
diff changeset
   144
        rset = self.execute('CWUser X LIMIT 1')
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   145
        self.view('inline-edition', rset, row=0, rtype='in_group', peid=geid, template=None).source
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   146
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   147
    def test_automatic_inline_creation_formview(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1359
diff changeset
   148
        geid = self.execute('CWGroup X LIMIT 1')[0][0]
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1359
diff changeset
   149
        self.view('inline-creation', None, etype='CWUser', rtype='in_group', peid=geid, template=None).source
1300
62d2b890a980 move tests where they belong
sylvain.thenault@logilab.fr
parents: 1298
diff changeset
   150
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   151
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
   152
if __name__ == '__main__':
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
   153
    unittest_main()