web/test/unittest_views_editforms.py
author sylvain.thenault@logilab.fr
Wed, 08 Apr 2009 13:20:05 +0200
branchtls-sprint
changeset 1298 ca02a2b5e9be
parent 1287 984e249764d1
child 1300 62d2b890a980
permissions -rw-r--r--
test inlined rtags
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
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
     3
from cubicweb.web.views.editforms import AutomaticEntityForm as AEF
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
     4
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
     5
def rbc(entity, category):
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
     6
    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
     7
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
     8
class AutomaticEntityFormTC(EnvBasedTC):
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
     9
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    10
    def test_euser_relations_by_category(self):
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    11
        #for (rtype, role, stype, otype), tag in AEF.rcategories._tagdefs.items():
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    12
        #    if rtype == 'tags':
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    13
        #        print rtype, role, stype, otype, ':', tag
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    14
        e = self.etype_instance('EUser')
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    15
        # see custom configuration in views.euser
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    16
        self.assertEquals(rbc(e, 'primary'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    17
                          [('login', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    18
                           ('upassword', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    19
                           ('in_group', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    20
                           ('in_state', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    21
                           ('eid', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    22
                           ])
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    23
        self.assertListEquals(rbc(e, 'secondary'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    24
                              [('firstname', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    25
                               ('surname', 'subject')
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    26
                               ])
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    27
        self.assertListEquals(rbc(e, 'metadata'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    28
                              [('last_login_time', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    29
                               ('created_by', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    30
                               ('creation_date', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    31
                               ('modification_date', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    32
                               ('owned_by', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    33
                               ('bookmarked_by', 'object'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    34
                               ])        
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    35
        self.assertListEquals(rbc(e, 'generic'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    36
                              [('primary_email', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    37
                               ('use_email', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    38
                               ('connait', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    39
                               ('checked_by', 'object'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    40
                               ])
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    41
        # owned_by is defined both as subject and object relations on EUser
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    42
        self.assertListEquals(rbc(e, 'generated'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    43
                              [('is', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    44
                               ('is_instance_of', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    45
                               ('tags', 'object'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    46
                               ('for_user', 'object'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    47
                               ('created_by', 'object'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    48
                               ('wf_info_for', 'object'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    49
                               ('owned_by', 'object'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    50
                               ])
1298
ca02a2b5e9be test inlined rtags
sylvain.thenault@logilab.fr
parents: 1287
diff changeset
    51
ca02a2b5e9be test inlined rtags
sylvain.thenault@logilab.fr
parents: 1287
diff changeset
    52
    def test_inlined_view(self):
ca02a2b5e9be test inlined rtags
sylvain.thenault@logilab.fr
parents: 1287
diff changeset
    53
        self.failUnless(AEF.rinlined.etype_rtag('EUser', 'use_email', 'subject'))
ca02a2b5e9be test inlined rtags
sylvain.thenault@logilab.fr
parents: 1287
diff changeset
    54
        self.failIf(AEF.rinlined.etype_rtag('EUser', 'primary_email', 'subject'))
ca02a2b5e9be test inlined rtags
sylvain.thenault@logilab.fr
parents: 1287
diff changeset
    55
                        
1287
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    56
    def test_personne_relations_by_category(self):
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    57
        e = self.etype_instance('Personne')
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    58
        self.assertListEquals(rbc(e, 'primary'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    59
                              [('nom', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    60
                               ('eid', 'subject')
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    61
                               ])
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    62
        self.assertListEquals(rbc(e, 'secondary'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    63
                              [('prenom', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    64
                               ('sexe', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    65
                               ('promo', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    66
                               ('titre', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    67
                               ('ass', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    68
                               ('web', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    69
                               ('tel', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    70
                               ('fax', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    71
                               ('datenaiss', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    72
                               ('test', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    73
                               ('description', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    74
                               ('salary', '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, 'metadata'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    77
                              [('created_by', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    78
                               ('creation_date', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    79
                               ('modification_date', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    80
                               ('owned_by', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    81
                               ])        
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    82
        self.assertListEquals(rbc(e, 'generic'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    83
                              [('travaille', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    84
                               ('connait', 'object')
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, 'generated'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    87
                              [('is', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    88
                               ('is_instance_of', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    89
                               ])
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    90
if __name__ == '__main__':
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    91
    unittest_main()