hooks/test/unittest_hooks.py
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Fri, 30 May 2014 17:57:55 +0200
changeset 9799 5362310d46da
parent 9361 0542a85fe667
child 9852 4c1969c173fa
permissions -rw-r--r--
[tests/session] remove unused import
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 -*-
9361
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
     2
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5030
diff changeset
     3
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5030
diff changeset
     4
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5030
diff changeset
     5
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5030
diff changeset
     6
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5030
diff changeset
     7
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5030
diff changeset
     8
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5030
diff changeset
     9
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5030
diff changeset
    10
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5030
diff changeset
    11
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    12
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5030
diff changeset
    13
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5030
diff changeset
    14
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5030
diff changeset
    15
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5030
diff changeset
    16
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5030
diff changeset
    17
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5030
diff changeset
    18
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
"""functional tests for core hooks
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
6957
ffda12be2e9f [repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6798
diff changeset
    21
Note:
ffda12be2e9f [repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6798
diff changeset
    22
  syncschema.py hooks are mostly tested in server/test/unittest_migrations.py
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
2454
3648b718a0d3 add simple tests for standard metadata hooks
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2453
diff changeset
    25
from datetime import datetime
3648b718a0d3 add simple tests for standard metadata hooks
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2453
diff changeset
    26
4689
4eb1f4490538 [test] skipping versions checking during test is enough, no need for monkey patch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4667
diff changeset
    27
from cubicweb import ValidationError, AuthenticationError, BadConnectionId
4eb1f4490538 [test] skipping versions checking during test is enough, no need for monkey patch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4667
diff changeset
    28
from cubicweb.devtools.testlib import CubicWebTC
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    29
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
    30
class CoreHooksTC(CubicWebTC):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    31
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
    def test_inlined(self):
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
    33
        self.assertEqual(self.repo.schema['sender'].inlined, True)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
        self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
        self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
        eeid = self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P '
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
                            'WHERE Y is EmailAddress, P is EmailPart')[0][0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
        self.execute('SET X sender Y WHERE X is Email, Y is EmailAddress')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
        rset = self.execute('Any S WHERE X sender S, X eid %s' % eeid)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
    40
        self.assertEqual(len(rset), 1)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    41
9361
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    42
    def test_symmetric(self):
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    43
        req = self.request()
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    44
        u1 = self.create_user(req, u'1')
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    45
        u2 = self.create_user(req, u'2')
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    46
        u3 = self.create_user(req, u'3')
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    47
        ga = req.create_entity('CWGroup', name=u'A')
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    48
        gb = req.create_entity('CWGroup', name=u'B')
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    49
        u1.cw_set(friend=u2)
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    50
        u2.cw_set(friend=u3)
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    51
        ga.cw_set(friend=gb)
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    52
        ga.cw_set(friend=u1)
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    53
        self.commit()
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    54
        req = self.request()
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    55
        for l1, l2 in ((u'1', u'2'),
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    56
                       (u'2', u'3')):
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    57
            self.assertTrue(req.execute('Any U1,U2 WHERE U1 friend U2, U1 login %(l1)s, U2 login %(l2)s',
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    58
                                        {'l1': l1, 'l2': l2}))
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    59
            self.assertTrue(req.execute('Any U1,U2 WHERE U2 friend U1, U1 login %(l1)s, U2 login %(l2)s',
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    60
                                        {'l1': l1, 'l2': l2}))
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    61
        self.assertTrue(req.execute('Any GA,GB WHERE GA friend GB, GA name "A", GB name "B"'))
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    62
        self.assertTrue(req.execute('Any GA,GB WHERE GB friend GA, GA name "A", GB name "B"'))
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    63
        self.assertTrue(req.execute('Any GA,U1 WHERE GA friend U1, GA name "A", U1 login "1"'))
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    64
        self.assertTrue(req.execute('Any GA,U1 WHERE U1 friend GA, GA name "A", U1 login "1"'))
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    65
        self.assertFalse(req.execute('Any GA,U WHERE GA friend U, GA name "A", U login "2"'))
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    66
        for l1, l2 in ((u'1', u'3'),
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    67
                       (u'3', u'1')):
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    68
            self.assertFalse(req.execute('Any U1,U2 WHERE U1 friend U2, U1 login %(l1)s, U2 login %(l2)s',
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    69
                                         {'l1': l1, 'l2': l2}))
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    70
            self.assertFalse(req.execute('Any U1,U2 WHERE U2 friend U1, U1 login %(l1)s, U2 login %(l2)s',
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    71
                                         {'l1': l1, 'l2': l2}))
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    72
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
    def test_html_tidy_hook(self):
4055
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
    74
        req = self.request()
7245
2f72b958ae22 small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7244
diff changeset
    75
        entity = req.create_entity('Workflow', name=u'wf1',
2f72b958ae22 small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7244
diff changeset
    76
                                   description_format=u'text/html',
2f72b958ae22 small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7244
diff changeset
    77
                                   description=u'yo')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
    78
        self.assertEqual(entity.description, u'yo')
7245
2f72b958ae22 small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7244
diff changeset
    79
        entity = req.create_entity('Workflow', name=u'wf2',
2f72b958ae22 small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7244
diff changeset
    80
                                   description_format=u'text/html',
2f72b958ae22 small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7244
diff changeset
    81
                                   description=u'<b>yo')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
    82
        self.assertEqual(entity.description, u'<b>yo</b>')
7245
2f72b958ae22 small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7244
diff changeset
    83
        entity = req.create_entity('Workflow', name=u'wf3',
2f72b958ae22 small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7244
diff changeset
    84
                                   description_format=u'text/html',
2f72b958ae22 small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7244
diff changeset
    85
                                   description=u'<b>yo</b>')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
    86
        self.assertEqual(entity.description, u'<b>yo</b>')
7245
2f72b958ae22 small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7244
diff changeset
    87
        entity = req.create_entity('Workflow', name=u'wf4',
2f72b958ae22 small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7244
diff changeset
    88
                                   description_format=u'text/html',
2f72b958ae22 small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7244
diff changeset
    89
                                   description=u'<b>R&D</b>')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
    90
        self.assertEqual(entity.description, u'<b>R&amp;D</b>')
7245
2f72b958ae22 small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7244
diff changeset
    91
        entity = req.create_entity('Workflow', name=u'wf5',
2f72b958ae22 small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7244
diff changeset
    92
                                   description_format=u'text/html',
2f72b958ae22 small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7244
diff changeset
    93
                                   description=u"<div>c&apos;est <b>l'ét&eacute;")
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
    94
        self.assertEqual(entity.description, u"<div>c'est <b>l'été</b></div>")
0
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_nonregr_html_tidy_hook_no_update(self):
7245
2f72b958ae22 small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7244
diff changeset
    97
        entity = self.request().create_entity('Workflow', name=u'wf1',
2f72b958ae22 small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7244
diff changeset
    98
                                              description_format=u'text/html',
2f72b958ae22 small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7244
diff changeset
    99
                                              description=u'yo')
8483
4ba11607d84a [entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7791
diff changeset
   100
        entity.cw_set(name=u'wf2')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
   101
        self.assertEqual(entity.description, u'yo')
8483
4ba11607d84a [entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7791
diff changeset
   102
        entity.cw_set(description=u'R&D<p>yo')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
   103
        self.assertEqual(entity.description, u'R&amp;D<p>yo</p>')
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   104
2921
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   105
    def test_metadata_cwuri(self):
4055
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
   106
        entity = self.request().create_entity('Workflow', name=u'wf1')
6965
343c79c3f04a [test] update cwuri test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6798
diff changeset
   107
        self.assertEqual(entity.cwuri, self.repo.config['base-url'] + str(entity.eid))
2921
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   108
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   109
    def test_metadata_creation_modification_date(self):
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   110
        _now = datetime.now()
4055
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
   111
        entity = self.request().create_entity('Workflow', name=u'wf1')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
   112
        self.assertEqual((entity.creation_date - _now).seconds, 0)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
   113
        self.assertEqual((entity.modification_date - _now).seconds, 0)
2921
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   114
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   115
    def test_metadata_created_by(self):
4055
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
   116
        entity = self.request().create_entity('Bookmark', title=u'wf1', path=u'/view')
2921
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   117
        self.commit() # fire operations
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
   118
        self.assertEqual(len(entity.created_by), 1) # make sure we have only one creator
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
   119
        self.assertEqual(entity.created_by[0].eid, self.session.user.eid)
2921
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   120
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   121
    def test_metadata_owned_by(self):
4055
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
   122
        entity = self.request().create_entity('Bookmark', title=u'wf1', path=u'/view')
2921
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   123
        self.commit() # fire operations
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
   124
        self.assertEqual(len(entity.owned_by), 1) # make sure we have only one owner
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
   125
        self.assertEqual(entity.owned_by[0].eid, self.session.user.eid)
2921
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   126
4051
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   127
    def test_user_login_stripped(self):
7244
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7192
diff changeset
   128
        req = self.request()
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7192
diff changeset
   129
        u = self.create_user(req, '  joe  ')
4051
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   130
        tname = self.execute('Any L WHERE E login L, E eid %(e)s',
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   131
                             {'e': u.eid})[0][0]
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
   132
        self.assertEqual(tname, 'joe')
4051
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   133
        self.execute('SET X login " jijoe " WHERE X eid %(x)s', {'x': u.eid})
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   134
        tname = self.execute('Any L WHERE E login L, E eid %(e)s',
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   135
                             {'e': u.eid})[0][0]
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
   136
        self.assertEqual(tname, 'jijoe')
4051
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   137
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   140
class UserGroupHooksTC(CubicWebTC):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   141
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
    def test_user_synchronization(self):
7244
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7192
diff changeset
   143
        req = self.request()
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7192
diff changeset
   144
        self.create_user(req, 'toto', password='hop', commit=False)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
        self.assertRaises(AuthenticationError,
4067
c49fba955a9c password should now be named
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4055
diff changeset
   146
                          self.repo.connect, u'toto', password='hop')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
        self.commit()
4067
c49fba955a9c password should now be named
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4055
diff changeset
   148
        cnxid = self.repo.connect(u'toto', password='hop')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7245
diff changeset
   149
        self.assertNotEqual(cnxid, self.session.id)
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   150
        self.execute('DELETE CWUser X WHERE X login "toto"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   151
        self.repo.execute(cnxid, 'State X')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   152
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
        self.assertRaises(BadConnectionId,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
                          self.repo.execute, cnxid, 'State X')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
    def test_user_group_synchronization(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   157
        user = self.session.user
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
   158
        self.assertEqual(user.groups, set(('managers',)))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   159
        self.execute('SET X in_group G WHERE X eid %s, G name "guests"' % user.eid)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
   160
        self.assertEqual(user.groups, set(('managers',)))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   161
        self.commit()
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
   162
        self.assertEqual(user.groups, set(('managers', 'guests')))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   163
        self.execute('DELETE X in_group G WHERE X eid %s, G name "guests"' % user.eid)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
   164
        self.assertEqual(user.groups, set(('managers', 'guests')))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   165
        self.commit()
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
   166
        self.assertEqual(user.groups, set(('managers',)))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   167
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
    def test_user_composite_owner(self):
7244
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7192
diff changeset
   169
        req = self.request()
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7192
diff changeset
   170
        ueid = self.create_user(req, 'toto').eid
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   171
        # composite of euser should be owned by the euser regardless of who created it
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   172
        self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", U use_email X '
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
                     'WHERE U login "toto"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
        self.commit()
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5895
diff changeset
   175
        self.assertEqual(self.execute('Any A WHERE X owned_by U, U use_email X,'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   176
                                       'U login "toto", X address A')[0][0],
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   177
                          'toto@logilab.fr')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   179
    def test_no_created_by_on_deleted_entity(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   180
        eid = self.execute('INSERT EmailAddress X: X address "toto@logilab.fr"')[0][0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   181
        self.execute('DELETE EmailAddress X WHERE X eid %s' % eid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   182
        self.commit()
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7245
diff changeset
   183
        self.assertFalse(self.execute('Any X WHERE X created_by Y, X eid >= %(x)s', {'x': eid}))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   184
2746
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2608
diff changeset
   185
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   186
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   187
class SchemaHooksTC(CubicWebTC):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   188
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   189
    def test_duplicate_etype_error(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   190
        # check we can't add a CWEType or CWRType entity if it already exists one
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   191
        # with the same name
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   192
        self.assertRaises(ValidationError,
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   193
                          self.execute, 'INSERT CWEType X: X name "CWUser"')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   194
        self.assertRaises(ValidationError,
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   195
                          self.execute, 'INSERT CWRType X: X name "in_group"')
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   196
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   197
    def test_validation_unique_constraint(self):
8594
001159e2e4f3 [validation api] properly use yams 0.36 validation error api and update message catalog. Follows bbe0d6985e59
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8556
diff changeset
   198
        with self.assertRaises(ValidationError) as cm:
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   199
            self.execute('INSERT CWUser X: X login "admin"')
8594
001159e2e4f3 [validation api] properly use yams 0.36 validation error api and update message catalog. Follows bbe0d6985e59
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8556
diff changeset
   200
        ex = cm.exception
001159e2e4f3 [validation api] properly use yams 0.36 validation error api and update message catalog. Follows bbe0d6985e59
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8556
diff changeset
   201
        ex.translate(unicode)
001159e2e4f3 [validation api] properly use yams 0.36 validation error api and update message catalog. Follows bbe0d6985e59
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8556
diff changeset
   202
        self.assertIsInstance(ex.entity, int)
001159e2e4f3 [validation api] properly use yams 0.36 validation error api and update message catalog. Follows bbe0d6985e59
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8556
diff changeset
   203
        self.assertEqual(ex.errors, {'login-subject': 'the value "admin" is already used, use another one'})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   204
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   205
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   206
if __name__ == '__main__':
6957
ffda12be2e9f [repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6798
diff changeset
   207
    from logilab.common.testlib import unittest_main
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   208
    unittest_main()