test/unittest_entity.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 23 Feb 2010 20:22:40 +0100
branchstable
changeset 4672 0288f8e5460c
parent 4630 528dee042927
child 4681 5f72584ab1d7
permissions -rw-r--r--
fix tests
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1905
diff changeset
     2
"""unit tests for cubicweb.web.views.entities module
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1905
diff changeset
     3
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1905
diff changeset
     4
:organization: Logilab
4212
ab6573088b4a update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3826
diff changeset
     5
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1905
diff changeset
     6
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1905
diff changeset
     7
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1905
diff changeset
     8
"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     9
1016
26387b836099 use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents: 821
diff changeset
    10
from datetime import datetime
821
78cc1682c3a4 fix test on systems that don't have simpleTAL installed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 748
diff changeset
    11
3241
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
    12
from cubicweb import Binary, Unauthorized
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    13
from cubicweb.devtools.testlib import CubicWebTC
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4015
diff changeset
    14
from cubicweb.mttransforms import HAS_TAL
3241
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
    15
from cubicweb.entities import fetch_config
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    16
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    17
class EntityTC(CubicWebTC):
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    18
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
    def test_boolean_value(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    20
        e = self.vreg['etypes'].etype_class('CWUser')(self.request())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
        self.failUnless(e)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
    def test_yams_inheritance(self):
748
eec752381926 unittest_entity ok
sylvain.thenault@logilab.fr
parents: 744
diff changeset
    24
        from entities import Note
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    25
        e = self.vreg['etypes'].etype_class('SubNote')(self.request())
748
eec752381926 unittest_entity ok
sylvain.thenault@logilab.fr
parents: 744
diff changeset
    26
        self.assertIsInstance(e, Note)
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    27
        e2 = self.vreg['etypes'].etype_class('SubNote')(self.request())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
        self.assertIs(e.__class__, e2.__class__)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
    def test_has_eid(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    31
        e = self.vreg['etypes'].etype_class('CWUser')(self.request())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
        self.assertEquals(e.eid, None)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
        self.assertEquals(e.has_eid(), False)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
        e.eid = 'X'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
        self.assertEquals(e.has_eid(), False)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
        e.eid = 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
        self.assertEquals(e.has_eid(), True)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
        e.eid = 2
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
        self.assertEquals(e.has_eid(), True)
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    40
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
    def test_copy(self):
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
    42
        req = self.request()
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
    43
        req.create_entity('Tag', name=u'x')
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
    44
        p = req.create_entity('Personne', nom=u'toto')
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
    45
        oe = req.create_entity('Note', type=u'x')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
        self.execute('SET T ecrit_par U WHERE T eid %(t)s, U eid %(u)s',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
                     {'t': oe.eid, 'u': p.eid}, ('t','u'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
        self.execute('SET TAG tags X WHERE X eid %(x)s', {'x': oe.eid}, 'x')
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
    49
        e = req.create_entity('Note', type=u'z')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
        e.copy_relations(oe.eid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
        self.assertEquals(len(e.ecrit_par), 1)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
        self.assertEquals(e.ecrit_par[0].eid, p.eid)
2635
c94df21f7ab2 F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2208
diff changeset
    53
        self.assertEquals(len(e.reverse_tags), 1)
c94df21f7ab2 F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2208
diff changeset
    54
        # check meta-relations are not copied, set on commit
c94df21f7ab2 F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2208
diff changeset
    55
        self.assertEquals(len(e.created_by), 0)
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    56
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
    def test_copy_with_nonmeta_composite_inlined(self):
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
    58
        req = self.request()
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
    59
        p = req.create_entity('Personne', nom=u'toto')
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
    60
        oe = req.create_entity('Note', type=u'x')
3877
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3826
diff changeset
    61
        self.schema['ecrit_par'].rdef('Note', 'Personne').composite = 'subject'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
        self.execute('SET T ecrit_par U WHERE T eid %(t)s, U eid %(u)s',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
                     {'t': oe.eid, 'u': p.eid}, ('t','u'))
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
    64
        e = req.create_entity('Note', type=u'z')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
        e.copy_relations(oe.eid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
        self.failIf(e.ecrit_par)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
        self.failUnless(oe.ecrit_par)
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    68
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
    def test_copy_with_composite(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
        user = self.user()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
        adeleid = self.execute('INSERT EmailAddress X: X address "toto@logilab.org", U use_email X WHERE U login "admin"')[0][0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    72
        e = self.entity('Any X WHERE X eid %(x)s', {'x':user.eid}, 'x')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
        self.assertEquals(e.use_email[0].address, "toto@logilab.org")
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
        self.assertEquals(e.use_email[0].eid, adeleid)
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    75
        usereid = self.execute('INSERT CWUser X: X login "toto", X upassword "toto", X in_group G '
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    76
                               'WHERE G name "users"')[0][0]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    77
        e = self.entity('Any X WHERE X eid %(x)s', {'x':usereid}, 'x')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
        e.copy_relations(user.eid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
        self.failIf(e.use_email)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
        self.failIf(e.primary_email)
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    81
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
    def test_copy_with_non_initial_state(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
        user = self.user()
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    84
        user = self.execute('INSERT CWUser X: X login "toto", X upassword %(pwd)s, X in_group G WHERE G name "users"',
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    85
                           {'pwd': 'toto'}).get_entity(0, 0)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
        self.commit()
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    87
        user.fire_transition('deactivate')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
        self.commit()
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    89
        eid2 = self.execute('INSERT CWUser X: X login "tutu", X upassword %(pwd)s', {'pwd': 'toto'})[0][0]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    90
        e = self.entity('Any X WHERE X eid %(x)s', {'x': eid2}, 'x')
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    91
        e.copy_relations(user.eid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
        e.clear_related_cache('in_state', 'subject')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
        self.assertEquals(e.state, 'activated')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
    def test_related_cache_both(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
        user = self.entity('Any X WHERE X eid %(x)s', {'x':self.user().eid}, 'x')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
        adeleid = self.execute('INSERT EmailAddress X: X address "toto@logilab.org", U use_email X WHERE U login "admin"')[0][0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
        self.commit()
2835
04034421b072 [hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2773
diff changeset
   100
        self.assertEquals(user._related_cache, {})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
        email = user.primary_email[0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
        self.assertEquals(sorted(user._related_cache), ['primary_email_subject'])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
        self.assertEquals(email._related_cache.keys(), ['primary_email_object'])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
        groups = user.in_group
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
        self.assertEquals(sorted(user._related_cache), ['in_group_subject', 'primary_email_subject'])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
        for group in groups:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
            self.failIf('in_group_subject' in group._related_cache, group._related_cache.keys())
413
a7366dd3c33c fix bug in entity.related_rql(): fetch_attr list / fetchorder weren't computed correctly
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
   108
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
    def test_related_limit(self):
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   110
        req = self.request()
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   111
        p = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
        for tag in u'abcd':
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   113
            req.create_entity('Tag', name=tag)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
        self.execute('SET X tags Y WHERE X is Tag, Y is Personne')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
        self.assertEquals(len(p.related('tags', 'object', limit=2)), 2)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
        self.assertEquals(len(p.related('tags', 'object')), 4)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   118
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
    def test_fetch_rql(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
        user = self.user()
2650
18aec79ec3a3 R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2635
diff changeset
   121
        Personne = self.vreg['etypes'].etype_class('Personne')
18aec79ec3a3 R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2635
diff changeset
   122
        Societe = self.vreg['etypes'].etype_class('Societe')
18aec79ec3a3 R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2635
diff changeset
   123
        Note = self.vreg['etypes'].etype_class('Note')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
        peschema = Personne.e_schema
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
        seschema = Societe.e_schema
3877
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3826
diff changeset
   126
        peschema.subjrels['travaille'].rdef(peschema, seschema).cardinality = '1*'
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3826
diff changeset
   127
        peschema.subjrels['connait'].rdef(peschema, peschema).cardinality = '11'
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3826
diff changeset
   128
        peschema.subjrels['evaluee'].rdef(peschema, Note.e_schema).cardinality = '1*'
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3826
diff changeset
   129
        seschema.subjrels['evaluee'].rdef(seschema, Note.e_schema).cardinality = '1*'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
        # testing basic fetch_attrs attribute
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
        self.assertEquals(Personne.fetch_rql(user),
3135
996c1ec7376c test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2930
diff changeset
   132
                          'Any X,AA,AB,AC ORDERBY AA ASC '
996c1ec7376c test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2930
diff changeset
   133
                          'WHERE X is Personne, X nom AA, X prenom AB, X modification_date AC')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
        pfetch_attrs = Personne.fetch_attrs
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
        sfetch_attrs = Societe.fetch_attrs
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   137
            # testing unknown attributes
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
            Personne.fetch_attrs = ('bloug', 'beep')
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   139
            self.assertEquals(Personne.fetch_rql(user), 'Any X WHERE X is Personne')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   140
            # testing one non final relation
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
            Personne.fetch_attrs = ('nom', 'prenom', 'travaille')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
            self.assertEquals(Personne.fetch_rql(user),
3135
996c1ec7376c test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2930
diff changeset
   143
                              'Any X,AA,AB,AC,AD ORDERBY AA ASC '
996c1ec7376c test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2930
diff changeset
   144
                              'WHERE X is Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
            # testing two non final relations
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   146
            Personne.fetch_attrs = ('nom', 'prenom', 'travaille', 'evaluee')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
            self.assertEquals(Personne.fetch_rql(user),
3135
996c1ec7376c test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2930
diff changeset
   148
                              'Any X,AA,AB,AC,AD,AE,AF ORDERBY AA ASC,AF DESC '
996c1ec7376c test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2930
diff changeset
   149
                              'WHERE X is Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD, '
996c1ec7376c test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2930
diff changeset
   150
                              'X evaluee AE?, AE modification_date AF')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   151
            # testing one non final relation with recursion
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   152
            Personne.fetch_attrs = ('nom', 'prenom', 'travaille')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
            Societe.fetch_attrs = ('nom', 'evaluee')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
            self.assertEquals(Personne.fetch_rql(user),
3135
996c1ec7376c test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2930
diff changeset
   155
                              'Any X,AA,AB,AC,AD,AE,AF ORDERBY AA ASC,AF DESC '
996c1ec7376c test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2930
diff changeset
   156
                              'WHERE X is Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD, '
996c1ec7376c test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2930
diff changeset
   157
                              'AC evaluee AE?, AE modification_date AF'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   158
                              )
4467
0e73d299730a fix long-waiting symetric typo: should be spelled symmetric. Add auto database migration on schema deserialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4460
diff changeset
   159
            # testing symmetric relation
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   160
            Personne.fetch_attrs = ('nom', 'connait')
2930
d7c23b2c7538 some test fixes, more in the 3.5 branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   161
            self.assertEquals(Personne.fetch_rql(user), 'Any X,AA,AB ORDERBY AA ASC '
d7c23b2c7538 some test fixes, more in the 3.5 branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   162
                              'WHERE X is Personne, X nom AA, X connait AB?')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   163
            # testing optional relation
3877
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3826
diff changeset
   164
            peschema.subjrels['travaille'].rdef(peschema, seschema).cardinality = '?*'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   165
            Personne.fetch_attrs = ('nom', 'prenom', 'travaille')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   166
            Societe.fetch_attrs = ('nom',)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   167
            self.assertEquals(Personne.fetch_rql(user),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
                              'Any X,AA,AB,AC,AD ORDERBY AA ASC WHERE X is Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
            # testing relation with cardinality > 1
3877
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3826
diff changeset
   170
            peschema.subjrels['travaille'].rdef(peschema, seschema).cardinality = '**'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   171
            self.assertEquals(Personne.fetch_rql(user),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   172
                              'Any X,AA,AB ORDERBY AA ASC WHERE X is Personne, X nom AA, X prenom AB')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
            # XXX test unauthorized attribute
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
        finally:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   175
            Personne.fetch_attrs = pfetch_attrs
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   176
            Societe.fetch_attrs = sfetch_attrs
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   177
4630
528dee042927 fix #694445: related entity generates weird RQL which in turn generates weird SQL which fails on SQL Server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4467
diff changeset
   178
    def test_related_rql_base(self):
2650
18aec79ec3a3 R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2635
diff changeset
   179
        Personne = self.vreg['etypes'].etype_class('Personne')
18aec79ec3a3 R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2635
diff changeset
   180
        Note = self.vreg['etypes'].etype_class('Note')
3135
996c1ec7376c test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2930
diff changeset
   181
        self.failUnless(issubclass(self.vreg['etypes'].etype_class('SubNote'), Note))
744
4da6e0f4df2a test upgrade
sylvain.thenault@logilab.fr
parents: 720
diff changeset
   182
        Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', 'type'))
4da6e0f4df2a test upgrade
sylvain.thenault@logilab.fr
parents: 720
diff changeset
   183
        Note.fetch_attrs, Note.fetch_order = fetch_config(('type',))
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   184
        p = self.request().create_entity('Personne', nom=u'pouet')
3135
996c1ec7376c test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2930
diff changeset
   185
        self.assertEquals(p.related_rql('evaluee'),
744
4da6e0f4df2a test upgrade
sylvain.thenault@logilab.fr
parents: 720
diff changeset
   186
                          'Any X,AA,AB ORDERBY AA ASC WHERE E eid %(x)s, E evaluee X, '
4da6e0f4df2a test upgrade
sylvain.thenault@logilab.fr
parents: 720
diff changeset
   187
                          'X type AA, X modification_date AB')
4da6e0f4df2a test upgrade
sylvain.thenault@logilab.fr
parents: 720
diff changeset
   188
        Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', ))
4da6e0f4df2a test upgrade
sylvain.thenault@logilab.fr
parents: 720
diff changeset
   189
        # XXX
3135
996c1ec7376c test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2930
diff changeset
   190
        self.assertEquals(p.related_rql('evaluee'),
4672
0288f8e5460c fix tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4630
diff changeset
   191
                          'Any X,AA ORDERBY AA DESC '
0288f8e5460c fix tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4630
diff changeset
   192
                          'WHERE E eid %(x)s, E evaluee X, '
3672
554a588ffaea [entity] make related_rql honors its targettypes argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3670
diff changeset
   193
                          'X modification_date AA')
554a588ffaea [entity] make related_rql honors its targettypes argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3670
diff changeset
   194
554a588ffaea [entity] make related_rql honors its targettypes argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3670
diff changeset
   195
        tag = self.vreg['etypes'].etype_class('Tag')(self.request())
554a588ffaea [entity] make related_rql honors its targettypes argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3670
diff changeset
   196
        self.assertEquals(tag.related_rql('tags', 'subject'),
4672
0288f8e5460c fix tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4630
diff changeset
   197
                          'Any X,AA ORDERBY AA DESC '
0288f8e5460c fix tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4630
diff changeset
   198
                          'WHERE E eid %(x)s, E tags X, '
3672
554a588ffaea [entity] make related_rql honors its targettypes argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3670
diff changeset
   199
                          'X modification_date AA')
554a588ffaea [entity] make related_rql honors its targettypes argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3670
diff changeset
   200
        self.assertEquals(tag.related_rql('tags', 'subject', ('Personne',)),
554a588ffaea [entity] make related_rql honors its targettypes argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3670
diff changeset
   201
                          'Any X,AA,AB ORDERBY AA ASC '
3771
234b003f0fe0 test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3769
diff changeset
   202
                          'WHERE E eid %(x)s, E tags X, X is IN (Personne), X nom AA, '
3672
554a588ffaea [entity] make related_rql honors its targettypes argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3670
diff changeset
   203
                          'X modification_date AB')
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   204
4630
528dee042927 fix #694445: related entity generates weird RQL which in turn generates weird SQL which fails on SQL Server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4467
diff changeset
   205
    def test_related_rql_ambigous_cant_use_fetch_order(self):
528dee042927 fix #694445: related entity generates weird RQL which in turn generates weird SQL which fails on SQL Server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4467
diff changeset
   206
        tag = self.vreg['etypes'].etype_class('Tag')(self.request())
528dee042927 fix #694445: related entity generates weird RQL which in turn generates weird SQL which fails on SQL Server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4467
diff changeset
   207
        for ttype in self.schema['tags'].objects():
528dee042927 fix #694445: related entity generates weird RQL which in turn generates weird SQL which fails on SQL Server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4467
diff changeset
   208
            self.vreg['etypes'].etype_class(ttype).fetch_attrs = ('modification_date',)
528dee042927 fix #694445: related entity generates weird RQL which in turn generates weird SQL which fails on SQL Server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4467
diff changeset
   209
        self.assertEquals(tag.related_rql('tags', 'subject'),
528dee042927 fix #694445: related entity generates weird RQL which in turn generates weird SQL which fails on SQL Server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4467
diff changeset
   210
                          'Any X,AA ORDERBY AA DESC '
528dee042927 fix #694445: related entity generates weird RQL which in turn generates weird SQL which fails on SQL Server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4467
diff changeset
   211
                          'WHERE E eid %(x)s, E tags X, X modification_date AA')
528dee042927 fix #694445: related entity generates weird RQL which in turn generates weird SQL which fails on SQL Server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4467
diff changeset
   212
3241
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   213
    def test_unrelated_rql_security_1(self):
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   214
        user = self.request().user
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   215
        rql = user.unrelated_rql('use_email', 'EmailAddress', 'subject')[0]
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   216
        self.assertEquals(rql, 'Any O,AA,AB,AC ORDERBY AC DESC '
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   217
                          'WHERE NOT S use_email O, S eid %(x)s, O is EmailAddress, O address AA, O alias AB, O modification_date AC')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   218
        self.create_user('toto')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   219
        self.login('toto')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   220
        user = self.request().user
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   221
        rql = user.unrelated_rql('use_email', 'EmailAddress', 'subject')[0]
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   222
        self.assertEquals(rql, 'Any O,AA,AB,AC ORDERBY AC DESC '
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   223
                          'WHERE NOT S use_email O, S eid %(x)s, O is EmailAddress, O address AA, O alias AB, O modification_date AC')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   224
        user = self.execute('Any X WHERE X login "admin"').get_entity(0, 0)
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   225
        self.assertRaises(Unauthorized, user.unrelated_rql, 'use_email', 'EmailAddress', 'subject')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   226
        self.login('anon')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   227
        user = self.request().user
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   228
        self.assertRaises(Unauthorized, user.unrelated_rql, 'use_email', 'EmailAddress', 'subject')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   229
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   230
    def test_unrelated_rql_security_2(self):
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   231
        email = self.execute('INSERT EmailAddress X: X address "hop"').get_entity(0, 0)
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   232
        rql = email.unrelated_rql('use_email', 'CWUser', 'object')[0]
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   233
        self.assertEquals(rql, 'Any S,AA,AB,AC,AD ORDERBY AA ASC '
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   234
                          'WHERE NOT S use_email O, O eid %(x)s, S is CWUser, S login AA, S firstname AB, S surname AC, S modification_date AD')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   235
        #rql = email.unrelated_rql('use_email', 'Person', 'object')[0]
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   236
        #self.assertEquals(rql, '')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   237
        self.login('anon')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   238
        email = self.execute('Any X WHERE X eid %(x)s', {'x': email.eid}, 'x').get_entity(0, 0)
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   239
        rql = email.unrelated_rql('use_email', 'CWUser', 'object')[0]
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   240
        self.assertEquals(rql, 'Any S,AA,AB,AC,AD ORDERBY AA '
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   241
                          'WHERE NOT S use_email O, O eid %(x)s, S is CWUser, S login AA, S firstname AB, S surname AC, S modification_date AD, '
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   242
                          'A eid %(B)s, EXISTS(S identity A, NOT A in_group C, C name "guests", C is CWGroup)')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   243
        #rql = email.unrelated_rql('use_email', 'Person', 'object')[0]
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   244
        #self.assertEquals(rql, '')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   245
3826
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3771
diff changeset
   246
    def test_unrelated_rql_security_nonexistant(self):
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3771
diff changeset
   247
        self.login('anon')
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3771
diff changeset
   248
        email = self.vreg['etypes'].etype_class('EmailAddress')(self.request())
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3771
diff changeset
   249
        rql = email.unrelated_rql('use_email', 'CWUser', 'object')[0]
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3771
diff changeset
   250
        self.assertEquals(rql, 'Any S,AA,AB,AC,AD ORDERBY AA '
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3771
diff changeset
   251
                          'WHERE S is CWUser, S login AA, S firstname AB, S surname AC, S modification_date AD, '
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3771
diff changeset
   252
                          'A eid %(B)s, EXISTS(S identity A, NOT A in_group C, C name "guests", C is CWGroup)')
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3771
diff changeset
   253
3241
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   254
    def test_unrelated_base(self):
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   255
        req = self.request()
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   256
        p = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien')
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   257
        e = req.create_entity('Tag', name=u'x')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   258
        related = [r.eid for r in e.tags]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   259
        self.failUnlessEqual(related, [])
1341
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 1284
diff changeset
   260
        unrelated = [r[0] for r in e.unrelated('tags', 'Personne', 'subject')]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   261
        self.failUnless(p.eid in unrelated)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   262
        self.execute('SET X tags Y WHERE X is Tag, Y is Personne')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   263
        e = self.entity('Any X WHERE X is Tag')
1341
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 1284
diff changeset
   264
        unrelated = [r[0] for r in e.unrelated('tags', 'Personne', 'subject')]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   265
        self.failIf(p.eid in unrelated)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   266
3241
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   267
    def test_unrelated_limit(self):
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   268
        req = self.request()
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   269
        e = req.create_entity('Tag', name=u'x')
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   270
        req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien')
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   271
        req.create_entity('Personne', nom=u'thenault', prenom=u'sylvain')
1341
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 1284
diff changeset
   272
        self.assertEquals(len(e.unrelated('tags', 'Personne', 'subject', limit=1)),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   273
                          1)
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   274
3241
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   275
    def test_unrelated_security(self):
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   276
        email = self.execute('INSERT EmailAddress X: X address "hop"').get_entity(0, 0)
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   277
        rset = email.unrelated('use_email', 'CWUser', 'object')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   278
        self.assertEquals([x.login for x in rset.entities()], [u'admin', u'anon'])
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   279
        user = self.request().user
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   280
        rset = user.unrelated('use_email', 'EmailAddress', 'subject')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   281
        self.assertEquals([x.address for x in rset.entities()], [u'hop'])
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   282
        self.create_user('toto')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   283
        self.login('toto')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   284
        email = self.execute('Any X WHERE X eid %(x)s', {'x': email.eid}, 'x').get_entity(0, 0)
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   285
        rset = email.unrelated('use_email', 'CWUser', 'object')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   286
        self.assertEquals([x.login for x in rset.entities()], ['toto'])
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   287
        user = self.request().user
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   288
        rset = user.unrelated('use_email', 'EmailAddress', 'subject')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   289
        self.assertEquals([x.address for x in rset.entities()], ['hop'])
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   290
        user = self.execute('Any X WHERE X login "admin"').get_entity(0, 0)
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   291
        rset = user.unrelated('use_email', 'EmailAddress', 'subject')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   292
        self.assertEquals([x.address for x in rset.entities()], [])
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   293
        self.login('anon')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   294
        email = self.execute('Any X WHERE X eid %(x)s', {'x': email.eid}, 'x').get_entity(0, 0)
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   295
        rset = email.unrelated('use_email', 'CWUser', 'object')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   296
        self.assertEquals([x.login for x in rset.entities()], [])
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   297
        user = self.request().user
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   298
        rset = user.unrelated('use_email', 'EmailAddress', 'subject')
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   299
        self.assertEquals([x.address for x in rset.entities()], [])
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   300
1a6f7a0e7dbd unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3136
diff changeset
   301
    def test_unrelated_new_entity(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   302
        e = self.vreg['etypes'].etype_class('CWUser')(self.request())
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
   303
        unrelated = [r[0] for r in e.unrelated('in_group', 'CWGroup', 'subject')]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   304
        # should be default groups but owners, i.e. managers, users, guests
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   305
        self.assertEquals(len(unrelated), 3)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   306
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   307
    def test_printable_value_string(self):
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   308
        e = self.request().create_entity('Card', title=u'rest test', content=u'du :eid:`1:*ReST*`',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   309
                            content_format=u'text/rest')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   310
        self.assertEquals(e.printable_value('content'),
2635
c94df21f7ab2 F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2208
diff changeset
   311
                          '<p>du <a class="reference" href="http://testing.fr/cubicweb/cwgroup/guests">*ReST*</a></p>\n')
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
   312
        e['content'] = 'du <em>html</em> <ref rql="CWUser X">users</ref>'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   313
        e['content_format'] = 'text/html'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   314
        self.assertEquals(e.printable_value('content'),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
   315
                          'du <em>html</em> <a href="http://testing.fr/cubicweb/view?rql=CWUser%20X">users</a>')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   316
        e['content'] = 'du *texte*'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   317
        e['content_format'] = 'text/plain'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   318
        self.assertEquals(e.printable_value('content'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   319
                          '<p>\ndu *texte*\n</p>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   320
        e['title'] = 'zou'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   321
        e['content'] = '''\
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   322
a title
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   323
=======
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   324
du :eid:`1:*ReST*`'''
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   325
        e['content_format'] = 'text/rest'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   326
        self.assertEquals(e.printable_value('content', format='text/plain'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   327
                          e['content'])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   328
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   329
        e['content'] = u'<b>yo (zou éà ;)</b>'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   330
        e['content_format'] = 'text/html'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   331
        self.assertEquals(e.printable_value('content', format='text/plain').strip(),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   332
                          u'**yo (zou éà ;)**')
821
78cc1682c3a4 fix test on systems that don't have simpleTAL installed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 748
diff changeset
   333
        if HAS_TAL:
78cc1682c3a4 fix test on systems that don't have simpleTAL installed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 748
diff changeset
   334
            e['content'] = '<h1 tal:content="self/title">titre</h1>'
78cc1682c3a4 fix test on systems that don't have simpleTAL installed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 748
diff changeset
   335
            e['content_format'] = 'text/cubicweb-page-template'
78cc1682c3a4 fix test on systems that don't have simpleTAL installed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 748
diff changeset
   336
            self.assertEquals(e.printable_value('content'),
78cc1682c3a4 fix test on systems that don't have simpleTAL installed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 748
diff changeset
   337
                              '<h1>zou</h1>')
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   338
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   339
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   340
    def test_printable_value_bytes(self):
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   341
        req = self.request()
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   342
        e = req.create_entity('File', data=Binary('lambda x: 1'), data_format=u'text/x-python',
3587
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3352
diff changeset
   343
                            data_encoding=u'ascii', data_name=u'toto.py')
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4015
diff changeset
   344
        from cubicweb import mttransforms
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   345
        if mttransforms.HAS_PYGMENTS_TRANSFORMS:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   346
            self.assertEquals(e.printable_value('data'),
3587
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3352
diff changeset
   347
                              '''<div class="highlight"><pre><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mi">1</span>
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   348
</pre></div>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   349
''')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   350
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   351
            self.assertEquals(e.printable_value('data'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   352
                              '''<pre class="python">
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   353
<span style="color: #C00000;">lambda</span> <span style="color: #000000;">x</span><span style="color: #0000C0;">:</span> <span style="color: #0080C0;">1</span>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   354
</pre>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   355
''')
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   356
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   357
        e = req.create_entity('File', data=Binary('*héhéhé*'), data_format=u'text/rest',
3587
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3352
diff changeset
   358
                            data_encoding=u'utf-8', data_name=u'toto.txt')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   359
        self.assertEquals(e.printable_value('data'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   360
                          u'<p><em>héhéhé</em></p>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   361
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   362
    def test_printable_value_bad_html(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   363
        """make sure we don't crash if we try to render invalid XHTML strings"""
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   364
        req = self.request()
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   365
        e = req.create_entity('Card', title=u'bad html', content=u'<div>R&D<br>',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   366
                            content_format=u'text/html')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   367
        tidy = lambda x: x.replace('\n', '')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   368
        self.assertEquals(tidy(e.printable_value('content')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   369
                          '<div>R&amp;D<br/></div>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   370
        e['content'] = u'yo !! R&D <div> pas fermé'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   371
        self.assertEquals(tidy(e.printable_value('content')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   372
                          u'yo !! R&amp;D <div> pas fermé</div>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   373
        e['content'] = u'R&D'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   374
        self.assertEquals(tidy(e.printable_value('content')), u'R&amp;D')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   375
        e['content'] = u'R&D;'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   376
        self.assertEquals(tidy(e.printable_value('content')), u'R&amp;D;')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   377
        e['content'] = u'yo !! R&amp;D <div> pas fermé'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   378
        self.assertEquals(tidy(e.printable_value('content')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   379
                          u'yo !! R&amp;D <div> pas fermé</div>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   380
        e['content'] = u'été <div> été'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   381
        self.assertEquals(tidy(e.printable_value('content')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   382
                          u'été <div> été</div>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   383
        e['content'] = u'C&apos;est un exemple s&eacute;rieux'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   384
        self.assertEquals(tidy(e.printable_value('content')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   385
                          u"C'est un exemple sérieux")
3587
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3352
diff changeset
   386
        # make sure valid xhtml is left untouched
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3352
diff changeset
   387
        e['content'] = u'<div>R&amp;D<br/></div>'
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3352
diff changeset
   388
        self.assertEquals(e.printable_value('content'), e['content'])
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3352
diff changeset
   389
        e['content'] = u'<div>été</div>'
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3352
diff changeset
   390
        self.assertEquals(e.printable_value('content'), e['content'])
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3352
diff changeset
   391
        e['content'] = u'été'
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3352
diff changeset
   392
        self.assertEquals(e.printable_value('content'), e['content'])
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3352
diff changeset
   393
        e['content'] = u'hop\r\nhop\nhip\rmomo'
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3352
diff changeset
   394
        self.assertEquals(e.printable_value('content'), u'hop\nhop\nhip\nmomo')
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3352
diff changeset
   395
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3352
diff changeset
   396
    def test_printable_value_bad_html_ms(self):
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3352
diff changeset
   397
        self.skip('fix soup2xhtml to handle this test')
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   398
        req = self.request()
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   399
        e = req.create_entity('Card', title=u'bad html', content=u'<div>R&D<br>',
3587
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3352
diff changeset
   400
                            content_format=u'text/html')
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3352
diff changeset
   401
        tidy = lambda x: x.replace('\n', '')
3352
83aabc5e3de3 a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3241
diff changeset
   402
        e['content'] = u'<div x:foo="bar">ms orifice produces weird html</div>'
83aabc5e3de3 a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3241
diff changeset
   403
        self.assertEquals(tidy(e.printable_value('content')),
83aabc5e3de3 a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3241
diff changeset
   404
                          u'<div>ms orifice produces weird html</div>')
83aabc5e3de3 a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3241
diff changeset
   405
        import tidy as tidymod # apt-get install python-tidy
83aabc5e3de3 a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3241
diff changeset
   406
        tidy = lambda x: str(tidymod.parseString(x.encode('utf-8'),
83aabc5e3de3 a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3241
diff changeset
   407
                                                 **{'drop_proprietary_attributes': True,
83aabc5e3de3 a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3241
diff changeset
   408
                                                    'output_xhtml': True,
83aabc5e3de3 a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3241
diff changeset
   409
                                                    'show_body_only' : True,
83aabc5e3de3 a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3241
diff changeset
   410
                                                    'quote-nbsp' : False,
83aabc5e3de3 a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3241
diff changeset
   411
                                                    'char_encoding' : 'utf8'})).decode('utf-8').strip()
83aabc5e3de3 a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3241
diff changeset
   412
        self.assertEquals(tidy(e.printable_value('content')),
83aabc5e3de3 a case for tidy : for your consideration
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3241
diff changeset
   413
                          u'<div>ms orifice produces weird html</div>')
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   414
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   415
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   416
    def test_fulltextindex(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   417
        e = self.vreg['etypes'].etype_class('File')(self.request())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   418
        e['description'] = 'du <em>html</em>'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   419
        e['description_format'] = 'text/html'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   420
        e['data'] = Binary('some <em>data</em>')
3587
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3352
diff changeset
   421
        e['data_name'] = 'an html file'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   422
        e['data_format'] = 'text/html'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   423
        e['data_encoding'] = 'ascii'
4015
4f8235204dda some cw 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890
diff changeset
   424
        e._cw.transaction_data = {} # XXX req should be a session
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   425
        self.assertEquals(set(e.get_words()),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   426
                          set(['an', 'html', 'file', 'du', 'html', 'some', 'data']))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   427
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   428
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   429
    def test_nonregr_relation_cache(self):
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   430
        req = self.request()
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   431
        p1 = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien')
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   432
        p2 = req.create_entity('Personne', nom=u'toto')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   433
        self.execute('SET X evaluee Y WHERE X nom "di mascio", Y nom "toto"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   434
        self.assertEquals(p1.evaluee[0].nom, "toto")
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   435
        self.failUnless(not p1.reverse_evaluee)
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   436
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   437
    def test_complete_relation(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   438
        session = self.session
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   439
        eid = session.unsafe_execute(
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   440
            'INSERT TrInfo X: X comment "zou", X wf_info_for U, X from_state S1, X to_state S2 '
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   441
            'WHERE U login "admin", S1 name "activated", S2 name "deactivated"')[0][0]
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   442
        trinfo = self.entity('Any X WHERE X eid %(x)s', {'x': eid}, 'x')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   443
        trinfo.complete()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   444
        self.failUnless(isinstance(trinfo['creation_date'], datetime))
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   445
        self.failUnless(trinfo.relation_cached('from_state', 'subject'))
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   446
        self.failUnless(trinfo.relation_cached('to_state', 'subject'))
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   447
        self.failUnless(trinfo.relation_cached('wf_info_for', 'subject'))
3587
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3352
diff changeset
   448
        self.assertEquals(trinfo.by_transition, ())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   449
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   450
    def test_request_cache(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   451
        req = self.request()
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
   452
        user = self.entity('CWUser X WHERE X login "admin"', req=req)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   453
        state = user.in_state[0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   454
        samestate = self.entity('State X WHERE X name "activated"', req=req)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   455
        self.failUnless(state is samestate)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   456
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   457
    def test_rest_path(self):
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   458
        req = self.request()
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   459
        note = req.create_entity('Note', type=u'z')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   460
        self.assertEquals(note.rest_path(), 'note/%s' % note.eid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   461
        # unique attr
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   462
        tag = req.create_entity('Tag', name=u'x')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   463
        self.assertEquals(tag.rest_path(), 'tag/x')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   464
        # test explicit rest_attr
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   465
        person = req.create_entity('Personne', prenom=u'john', nom=u'doe')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   466
        self.assertEquals(person.rest_path(), 'personne/doe')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   467
        # ambiguity test
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   468
        person2 = req.create_entity('Personne', prenom=u'remi', nom=u'doe')
4460
5c22869079b9 clear rest_path __unique cache in clear_all_caches, fix related test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   469
        person.clear_all_caches()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   470
        self.assertEquals(person.rest_path(), 'personne/eid/%s' % person.eid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   471
        self.assertEquals(person2.rest_path(), 'personne/eid/%s' % person2.eid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   472
        # unique attr with None value (wikiid in this case)
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   473
        card1 = req.create_entity('Card', title=u'hop')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   474
        self.assertEquals(card1.rest_path(), 'card/eid/%s' % card1.eid)
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   475
        card2 = req.create_entity('Card', title=u'pod', wikiid=u'zob/i')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   476
        self.assertEquals(card2.rest_path(), 'card/zob%2Fi')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   477
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   478
    def test_set_attributes(self):
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   479
        req = self.request()
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   480
        person = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   481
        self.assertEquals(person.prenom, u'adrien')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   482
        self.assertEquals(person.nom, u'di mascio')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   483
        person.set_attributes(prenom=u'sylvain', nom=u'thénault')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   484
        person = self.entity('Personne P') # XXX retreival needed ?
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   485
        self.assertEquals(person.prenom, u'sylvain')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   486
        self.assertEquals(person.nom, u'thénault')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   487
1905
9c96dd7cc624 [tests] fix test after absolute_url got changed for external entities
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1640
diff changeset
   488
    def test_metainformation_and_external_absolute_url(self):
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   489
        req = self.request()
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   490
        note = req.create_entity('Note', type=u'z')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   491
        metainf = note.metainformation()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   492
        self.assertEquals(metainf, {'source': {'adapter': 'native', 'uri': 'system'}, 'type': u'Note', 'extid': None})
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   493
        self.assertEquals(note.absolute_url(), 'http://testing.fr/cubicweb/note/%s' % note.eid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   494
        metainf['source'] = metainf['source'].copy()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   495
        metainf['source']['base-url']  = 'http://cubicweb2.com/'
1905
9c96dd7cc624 [tests] fix test after absolute_url got changed for external entities
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1640
diff changeset
   496
        metainf['extid']  = 1234
9c96dd7cc624 [tests] fix test after absolute_url got changed for external entities
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1640
diff changeset
   497
        self.assertEquals(note.absolute_url(), 'http://cubicweb2.com/note/1234')
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   498
2125
19861294506f https://www.logilab.net/cwo/ticket/343724
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   499
    def test_absolute_url_empty_field(self):
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   500
        req = self.request()
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   501
        card = req.create_entity('Card', wikiid=u'', title=u'test')
2125
19861294506f https://www.logilab.net/cwo/ticket/343724
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   502
        self.assertEquals(card.absolute_url(),
19861294506f https://www.logilab.net/cwo/ticket/343724
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   503
                          'http://testing.fr/cubicweb/card/eid/%s' % card.eid)
19861294506f https://www.logilab.net/cwo/ticket/343724
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   504
3669
4eb33ee29c84 nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
   505
    def test_create_entity(self):
4031
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   506
        req = self.request()
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   507
        p1 = req.create_entity('Personne', nom=u'fayolle', prenom=u'alexandre')
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   508
        p2 = req.create_entity('Personne', nom=u'campeas', prenom=u'aurelien')
56f4d4f7f86f test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   509
        note = req.create_entity('Note', type=u'z')
3669
4eb33ee29c84 nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
   510
        req = self.request()
4eb33ee29c84 nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
   511
        p = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien',
3670
b7ec030a5e10 allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3669
diff changeset
   512
                              connait=p1, evaluee=[p1, p2],
3669
4eb33ee29c84 nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
   513
                              reverse_ecrit_par=note)
4eb33ee29c84 nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
   514
        self.assertEquals(p.nom, 'di mascio')
4eb33ee29c84 nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
   515
        self.assertEquals([c.nom for c in p.connait], ['fayolle'])
3670
b7ec030a5e10 allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3669
diff changeset
   516
        self.assertEquals(sorted([c.nom for c in p.evaluee]), ['campeas', 'fayolle'])
3669
4eb33ee29c84 nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
   517
        self.assertEquals([c.type for c in p.reverse_ecrit_par], ['z'])
4eb33ee29c84 nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
   518
4eb33ee29c84 nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
   519
3670
b7ec030a5e10 allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3669
diff changeset
   520
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   521
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   522
    from logilab.common.testlib import unittest_main
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   523
    unittest_main()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   524