web/test/unittest_views_editforms.py
author sylvain.thenault@logilab.fr
Wed, 08 Apr 2009 11:33:57 +0200
branchtls-sprint
changeset 1287 984e249764d1
child 1298 ca02a2b5e9be
permissions -rw-r--r--
test rcategories
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
                               ])
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    51
                              
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    52
    def test_personne_relations_by_category(self):
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    53
        e = self.etype_instance('Personne')
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    54
        self.assertListEquals(rbc(e, 'primary'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    55
                              [('nom', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    56
                               ('eid', 'subject')
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    57
                               ])
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    58
        self.assertListEquals(rbc(e, 'secondary'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    59
                              [('prenom', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    60
                               ('sexe', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    61
                               ('promo', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    62
                               ('titre', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    63
                               ('ass', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    64
                               ('web', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    65
                               ('tel', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    66
                               ('fax', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    67
                               ('datenaiss', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    68
                               ('test', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    69
                               ('description', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    70
                               ('salary', 'subject')
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    71
                               ])
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    72
        self.assertListEquals(rbc(e, 'metadata'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    73
                              [('created_by', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    74
                               ('creation_date', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    75
                               ('modification_date', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    76
                               ('owned_by', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    77
                               ])        
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    78
        self.assertListEquals(rbc(e, 'generic'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    79
                              [('travaille', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    80
                               ('connait', 'object')
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, 'generated'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    83
                              [('is', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    84
                               ('is_instance_of', 'subject'),
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    85
                               ])
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    86
if __name__ == '__main__':
984e249764d1 test rcategories
sylvain.thenault@logilab.fr
parents:
diff changeset
    87
    unittest_main()