cubicweb/hooks/test/unittest_hooks.py
author Jérémy Bobbio <jeremy.bobbio@irq7.fr>
Wed, 19 Jun 2019 15:44:17 +0200
changeset 12655 5b0ce10a7046
parent 12567 26744ad37953
permissions -rw-r--r--
[crypto] Use Cryptodome namespace instead of Crypto PyCryptodome comes in two flavors: “an almost drop-in replacement for the old PyCrypto library” and “a library independent of the old PyCrypto”. The former uses the Crypto namespace, and is shipped as `pycryptodome` while the latter uses Cryptodome instead and lies in the `pycryptodomex` package. Given the reason to switch to PyCryptodome is that PyCrypto in unmaintained, its probably better to avoid any mistake and mandate the specific usage of the Cryptodome namespace by requiring `pycryptodomex` instead of `pycryptodome`. A more present reason is that Debian buster will only provide a package with the separate namespace flavor. The current Recommends is not working with the current code. Although it's important to note that the package name will probably have to be changed to `python3-pycryptodomex` once https://bugs.debian.org/886291 is solved.
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 -*-
11366
80dec361a5d0 [hooks/integrity] kill CheckUniqueHook
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
     2
# copyright 2003-2016 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
11034
75d752e6daf7 [server] improve TZDatetime support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11033
diff changeset
    27
from pytz import utc
11366
80dec361a5d0 [hooks/integrity] kill CheckUniqueHook
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
    28
80dec361a5d0 [hooks/integrity] kill CheckUniqueHook
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
    29
from cubicweb import ValidationError
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
    30
from cubicweb.devtools.testlib import CubicWebTC
12104
3ae16f70add4 [server] don't catch exception from postcommit_event() if we are in test mode
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11367
diff changeset
    31
from cubicweb.server.hook import Operation
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    32
10724
aa3eedba866c [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10336
diff changeset
    33
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
    34
class CoreHooksTC(CubicWebTC):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    35
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
    def test_inlined(self):
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    37
        with self.admin_access.repo_cnx() as cnx:
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    38
            self.assertEqual(self.repo.schema['sender'].inlined, True)
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    39
            cnx.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"')
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    40
            cnx.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, '
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    41
                        'X content "this is a test"')
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    42
            eeid = cnx.execute('INSERT Email X: X messageid "<1234>", X subject "test", '
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    43
                               'X sender Y, X recipients Y, X parts P '
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    44
                               'WHERE Y is EmailAddress, P is EmailPart')[0][0]
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    45
            cnx.execute('SET X sender Y WHERE X is Email, Y is EmailAddress')
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    46
            rset = cnx.execute('Any S WHERE X sender S, X eid %s' % eeid)
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    47
            self.assertEqual(len(rset), 1)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    48
9361
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    49
    def test_symmetric(self):
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    50
        with self.admin_access.repo_cnx() as cnx:
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    51
            u1 = self.create_user(cnx, u'1')
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    52
            u2 = self.create_user(cnx, u'2')
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    53
            u3 = self.create_user(cnx, u'3')
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    54
            ga = cnx.create_entity('CWGroup', name=u'A')
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    55
            gb = cnx.create_entity('CWGroup', name=u'B')
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    56
            u1.cw_set(friend=u2)
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    57
            u2.cw_set(friend=u3)
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    58
            ga.cw_set(friend=gb)
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    59
            ga.cw_set(friend=u1)
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    60
            cnx.commit()
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    61
            for l1, l2 in ((u'1', u'2'),
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    62
                           (u'2', u'3')):
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    63
                self.assertTrue(cnx.execute('Any U1,U2 WHERE U1 friend U2, U1 login %(l1)s, U2 login %(l2)s',
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    64
                                            {'l1': l1, 'l2': l2}))
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    65
                self.assertTrue(cnx.execute('Any U1,U2 WHERE U2 friend U1, U1 login %(l1)s, U2 login %(l2)s',
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    66
                                            {'l1': l1, 'l2': l2}))
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    67
            self.assertTrue(cnx.execute('Any GA,GB WHERE GA friend GB, GA name "A", GB name "B"'))
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    68
            self.assertTrue(cnx.execute('Any GA,GB WHERE GB friend GA, GA name "A", GB name "B"'))
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    69
            self.assertTrue(cnx.execute('Any GA,U1 WHERE GA friend U1, GA name "A", U1 login "1"'))
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    70
            self.assertTrue(cnx.execute('Any GA,U1 WHERE U1 friend GA, GA name "A", U1 login "1"'))
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    71
            self.assertFalse(cnx.execute('Any GA,U WHERE GA friend U, GA name "A", U login "2"'))
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    72
            for l1, l2 in ((u'1', u'3'),
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    73
                           (u'3', u'1')):
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    74
                self.assertFalse(cnx.execute('Any U1,U2 WHERE U1 friend U2, U1 login %(l1)s, U2 login %(l2)s',
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    75
                                             {'l1': l1, 'l2': l2}))
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    76
                self.assertFalse(cnx.execute('Any U1,U2 WHERE U2 friend U1, U1 login %(l1)s, U2 login %(l2)s',
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    77
                                             {'l1': l1, 'l2': l2}))
9361
0542a85fe667 symmetric relations: replace bogus rql2sql translation by a hook
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    78
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
    def test_html_tidy_hook(self):
9853
4ddae5c156f6 [hookstests/base] use connections instead of web requests
Julien Cristau <julien.cristau@logilab.fr>
parents: 9852
diff changeset
    80
        with self.admin_access.client_cnx() as cnx:
4ddae5c156f6 [hookstests/base] use connections instead of web requests
Julien Cristau <julien.cristau@logilab.fr>
parents: 9852
diff changeset
    81
            entity = cnx.create_entity('Workflow', name=u'wf1',
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    82
                                       description_format=u'text/html',
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    83
                                       description=u'yo')
10085
dc315002a2d4 [hookstests] change got/expected order
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9935
diff changeset
    84
            self.assertEqual(u'yo', entity.description)
9853
4ddae5c156f6 [hookstests/base] use connections instead of web requests
Julien Cristau <julien.cristau@logilab.fr>
parents: 9852
diff changeset
    85
            entity = cnx.create_entity('Workflow', name=u'wf2',
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    86
                                       description_format=u'text/html',
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    87
                                       description=u'<b>yo')
10085
dc315002a2d4 [hookstests] change got/expected order
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9935
diff changeset
    88
            self.assertEqual(u'<b>yo</b>', entity.description)
9853
4ddae5c156f6 [hookstests/base] use connections instead of web requests
Julien Cristau <julien.cristau@logilab.fr>
parents: 9852
diff changeset
    89
            entity = cnx.create_entity('Workflow', name=u'wf3',
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    90
                                       description_format=u'text/html',
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    91
                                       description=u'<b>yo</b>')
10085
dc315002a2d4 [hookstests] change got/expected order
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9935
diff changeset
    92
            self.assertEqual(u'<b>yo</b>', entity.description)
9853
4ddae5c156f6 [hookstests/base] use connections instead of web requests
Julien Cristau <julien.cristau@logilab.fr>
parents: 9852
diff changeset
    93
            entity = cnx.create_entity('Workflow', name=u'wf4',
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    94
                                       description_format=u'text/html',
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    95
                                       description=u'<b>R&D</b>')
10085
dc315002a2d4 [hookstests] change got/expected order
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9935
diff changeset
    96
            self.assertEqual(u'<b>R&amp;D</b>', entity.description, )
9853
4ddae5c156f6 [hookstests/base] use connections instead of web requests
Julien Cristau <julien.cristau@logilab.fr>
parents: 9852
diff changeset
    97
            entity = cnx.create_entity('Workflow', name=u'wf5',
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    98
                                       description_format=u'text/html',
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
    99
                                       description=u"<div>c&apos;est <b>l'ét&eacute;")
10085
dc315002a2d4 [hookstests] change got/expected order
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9935
diff changeset
   100
            self.assertEqual(u"<div>c'est <b>l'été</b></div>", entity.description)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
    def test_nonregr_html_tidy_hook_no_update(self):
9853
4ddae5c156f6 [hookstests/base] use connections instead of web requests
Julien Cristau <julien.cristau@logilab.fr>
parents: 9852
diff changeset
   103
        with self.admin_access.client_cnx() as cnx:
4ddae5c156f6 [hookstests/base] use connections instead of web requests
Julien Cristau <julien.cristau@logilab.fr>
parents: 9852
diff changeset
   104
            entity = cnx.create_entity('Workflow', name=u'wf1',
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   105
                                       description_format=u'text/html',
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   106
                                       description=u'yo')
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   107
            entity.cw_set(name=u'wf2')
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   108
            self.assertEqual(entity.description, u'yo')
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   109
            entity.cw_set(description=u'R&D<p>yo')
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   110
            self.assertEqual(entity.description, u'R&amp;D<p>yo</p>')
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   111
2921
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   112
    def test_metadata_cwuri(self):
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   113
        with self.admin_access.repo_cnx() as cnx:
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   114
            entity = cnx.create_entity('Workflow', name=u'wf1')
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   115
            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
   116
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   117
    def test_metadata_creation_modification_date(self):
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   118
        with self.admin_access.repo_cnx() as cnx:
11034
75d752e6daf7 [server] improve TZDatetime support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11033
diff changeset
   119
            _now = datetime.now(utc)
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   120
            entity = cnx.create_entity('Workflow', name=u'wf1')
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   121
            self.assertEqual((entity.creation_date - _now).seconds, 0)
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   122
            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
   123
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   124
    def test_metadata_created_by(self):
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   125
        with self.admin_access.repo_cnx() as cnx:
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   126
            entity = cnx.create_entity('Bookmark', title=u'wf1', path=u'/view')
11367
5379c5dbc2c5 [test/hooks] pep8 and unittest.main instead in unittest_hooks.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11366
diff changeset
   127
            cnx.commit()  # fire operations
5379c5dbc2c5 [test/hooks] pep8 and unittest.main instead in unittest_hooks.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11366
diff changeset
   128
            self.assertEqual(len(entity.created_by), 1)  # make sure we have only one creator
9935
d1adf549d5cb [test] silence a few more deprecation warnings in unittest_hooks
Julien Cristau <julien.cristau@logilab.fr>
parents: 9853
diff changeset
   129
            self.assertEqual(entity.created_by[0].eid, cnx.user.eid)
2921
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   130
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   131
    def test_metadata_owned_by(self):
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   132
        with self.admin_access.repo_cnx() as cnx:
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   133
            entity = cnx.create_entity('Bookmark', title=u'wf1', path=u'/view')
11367
5379c5dbc2c5 [test/hooks] pep8 and unittest.main instead in unittest_hooks.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11366
diff changeset
   134
            cnx.commit()  # fire operations
5379c5dbc2c5 [test/hooks] pep8 and unittest.main instead in unittest_hooks.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11366
diff changeset
   135
            self.assertEqual(len(entity.owned_by), 1)  # make sure we have only one owner
9935
d1adf549d5cb [test] silence a few more deprecation warnings in unittest_hooks
Julien Cristau <julien.cristau@logilab.fr>
parents: 9853
diff changeset
   136
            self.assertEqual(entity.owned_by[0].eid, cnx.user.eid)
2921
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   137
4051
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   138
    def test_user_login_stripped(self):
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   139
        with self.admin_access.repo_cnx() as cnx:
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   140
            u = self.create_user(cnx, '  joe  ')
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   141
            tname = cnx.execute('Any L WHERE E login L, E eid %(e)s',
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   142
                                {'e': u.eid})[0][0]
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   143
            self.assertEqual(tname, 'joe')
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   144
            cnx.execute('SET X login " jijoe " WHERE X eid %(x)s', {'x': u.eid})
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   145
            tname = cnx.execute('Any L WHERE E login L, E eid %(e)s',
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   146
                                {'e': u.eid})[0][0]
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   147
            self.assertEqual(tname, 'jijoe')
4051
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   148
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   149
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   150
class UserGroupHooksTC(CubicWebTC):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   151
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   152
    def test_user_group_synchronization(self):
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   153
        with self.admin_access.repo_cnx() as cnx:
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   154
            user = cnx.user
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   155
            self.assertEqual(user.groups, set(('managers',)))
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   156
            cnx.execute('SET X in_group G WHERE X eid %s, G name "guests"' % user.eid)
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   157
            self.assertEqual(user.groups, set(('managers',)))
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   158
            cnx.commit()
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   159
            self.assertEqual(user.groups, set(('managers', 'guests')))
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   160
            cnx.execute('DELETE X in_group G WHERE X eid %s, G name "guests"' % user.eid)
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   161
            self.assertEqual(user.groups, set(('managers', 'guests')))
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   162
            cnx.commit()
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   163
            self.assertEqual(user.groups, set(('managers',)))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   164
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   165
    def test_user_composite_owner(self):
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   166
        with self.admin_access.repo_cnx() as cnx:
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   167
            self.create_user(cnx, 'toto').eid
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   168
            # composite of euser should be owned by the euser regardless of who created it
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   169
            cnx.execute('INSERT EmailAddress X: X address "toto@logilab.fr", U use_email X '
11367
5379c5dbc2c5 [test/hooks] pep8 and unittest.main instead in unittest_hooks.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11366
diff changeset
   170
                        'WHERE U login "toto"')
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   171
            cnx.commit()
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   172
            self.assertEqual(cnx.execute('Any A WHERE X owned_by U, U use_email X,'
11367
5379c5dbc2c5 [test/hooks] pep8 and unittest.main instead in unittest_hooks.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11366
diff changeset
   173
                                         'U login "toto", X address A')[0][0],
5379c5dbc2c5 [test/hooks] pep8 and unittest.main instead in unittest_hooks.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11366
diff changeset
   174
                             'toto@logilab.fr')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   175
10182
116b24efad0e [hooks] don't insert an owned_by relation for deleted entities
Julien Cristau <julien.cristau@logilab.fr>
parents: 9935
diff changeset
   176
    def test_user_composite_no_owner_on_deleted_entity(self):
116b24efad0e [hooks] don't insert an owned_by relation for deleted entities
Julien Cristau <julien.cristau@logilab.fr>
parents: 9935
diff changeset
   177
        with self.admin_access.repo_cnx() as cnx:
116b24efad0e [hooks] don't insert an owned_by relation for deleted entities
Julien Cristau <julien.cristau@logilab.fr>
parents: 9935
diff changeset
   178
            u = self.create_user(cnx, 'toto').eid
116b24efad0e [hooks] don't insert an owned_by relation for deleted entities
Julien Cristau <julien.cristau@logilab.fr>
parents: 9935
diff changeset
   179
            cnx.commit()
116b24efad0e [hooks] don't insert an owned_by relation for deleted entities
Julien Cristau <julien.cristau@logilab.fr>
parents: 9935
diff changeset
   180
            e = cnx.create_entity('EmailAddress', address=u'toto@logilab.fr', reverse_use_email=u)
116b24efad0e [hooks] don't insert an owned_by relation for deleted entities
Julien Cristau <julien.cristau@logilab.fr>
parents: 9935
diff changeset
   181
            e.cw_delete()
116b24efad0e [hooks] don't insert an owned_by relation for deleted entities
Julien Cristau <julien.cristau@logilab.fr>
parents: 9935
diff changeset
   182
            cnx.commit()
116b24efad0e [hooks] don't insert an owned_by relation for deleted entities
Julien Cristau <julien.cristau@logilab.fr>
parents: 9935
diff changeset
   183
            self.assertFalse(cnx.system_sql(
116b24efad0e [hooks] don't insert an owned_by relation for deleted entities
Julien Cristau <julien.cristau@logilab.fr>
parents: 9935
diff changeset
   184
                'SELECT * FROM owned_by_relation '
116b24efad0e [hooks] don't insert an owned_by relation for deleted entities
Julien Cristau <julien.cristau@logilab.fr>
parents: 9935
diff changeset
   185
                'WHERE eid_from NOT IN (SELECT eid FROM entities)').fetchall())
116b24efad0e [hooks] don't insert an owned_by relation for deleted entities
Julien Cristau <julien.cristau@logilab.fr>
parents: 9935
diff changeset
   186
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
    def test_no_created_by_on_deleted_entity(self):
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   188
        with self.admin_access.repo_cnx() as cnx:
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   189
            eid = cnx.execute('INSERT EmailAddress X: X address "toto@logilab.fr"')[0][0]
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   190
            cnx.execute('DELETE EmailAddress X WHERE X eid %s' % eid)
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   191
            cnx.commit()
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   192
            self.assertFalse(cnx.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
   193
2746
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2608
diff changeset
   194
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   195
class SchemaHooksTC(CubicWebTC):
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_duplicate_etype_error(self):
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   198
        with self.admin_access.repo_cnx() as cnx:
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   199
            # check we can't add a CWEType or CWRType entity if it already exists one
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   200
            # with the same name
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   201
            self.assertRaises(ValidationError,
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   202
                              cnx.execute, 'INSERT CWEType X: X name "CWUser"')
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   203
            cnx.rollback()
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   204
            self.assertRaises(ValidationError,
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   205
                              cnx.execute, 'INSERT CWRType X: X name "in_group"')
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   206
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   207
    def test_validation_unique_constraint(self):
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   208
        with self.admin_access.repo_cnx() as cnx:
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   209
            with self.assertRaises(ValidationError) as cm:
11367
5379c5dbc2c5 [test/hooks] pep8 and unittest.main instead in unittest_hooks.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11366
diff changeset
   210
                cnx.execute('INSERT CWUser X: X login "admin", X upassword "admin"')
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   211
            ex = cm.exception
12567
26744ad37953 Drop python2 support
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12104
diff changeset
   212
            ex.translate(str)
9852
4c1969c173fa [hookstests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9361
diff changeset
   213
            self.assertIsInstance(ex.entity, int)
11366
80dec361a5d0 [hooks/integrity] kill CheckUniqueHook
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
   214
            self.assertEqual(ex.errors,
80dec361a5d0 [hooks/integrity] kill CheckUniqueHook
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
   215
                             {'': u'some relations violate a unicity constraint',
80dec361a5d0 [hooks/integrity] kill CheckUniqueHook
Julien Cristau <julien.cristau@logilab.fr>
parents: 11057
diff changeset
   216
                              'login': u'login is part of violated unicity constraint'})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   217
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   218
12104
3ae16f70add4 [server] don't catch exception from postcommit_event() if we are in test mode
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11367
diff changeset
   219
class OperationTC(CubicWebTC):
3ae16f70add4 [server] don't catch exception from postcommit_event() if we are in test mode
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11367
diff changeset
   220
3ae16f70add4 [server] don't catch exception from postcommit_event() if we are in test mode
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11367
diff changeset
   221
    def test_bad_postcommit_event(self):
3ae16f70add4 [server] don't catch exception from postcommit_event() if we are in test mode
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11367
diff changeset
   222
3ae16f70add4 [server] don't catch exception from postcommit_event() if we are in test mode
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11367
diff changeset
   223
        class BadOp(Operation):
3ae16f70add4 [server] don't catch exception from postcommit_event() if we are in test mode
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11367
diff changeset
   224
            def postcommit_event(self):
3ae16f70add4 [server] don't catch exception from postcommit_event() if we are in test mode
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11367
diff changeset
   225
                raise RuntimeError('this is bad')
3ae16f70add4 [server] don't catch exception from postcommit_event() if we are in test mode
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11367
diff changeset
   226
3ae16f70add4 [server] don't catch exception from postcommit_event() if we are in test mode
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11367
diff changeset
   227
        with self.admin_access.cnx() as cnx:
3ae16f70add4 [server] don't catch exception from postcommit_event() if we are in test mode
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11367
diff changeset
   228
            BadOp(cnx)
3ae16f70add4 [server] don't catch exception from postcommit_event() if we are in test mode
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11367
diff changeset
   229
            with self.assertRaises(RuntimeError) as cm:
3ae16f70add4 [server] don't catch exception from postcommit_event() if we are in test mode
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11367
diff changeset
   230
                cnx.commit()
3ae16f70add4 [server] don't catch exception from postcommit_event() if we are in test mode
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11367
diff changeset
   231
            self.assertEqual(str(cm.exception), 'this is bad')
3ae16f70add4 [server] don't catch exception from postcommit_event() if we are in test mode
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11367
diff changeset
   232
3ae16f70add4 [server] don't catch exception from postcommit_event() if we are in test mode
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11367
diff changeset
   233
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   234
if __name__ == '__main__':
11367
5379c5dbc2c5 [test/hooks] pep8 and unittest.main instead in unittest_hooks.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11366
diff changeset
   235
    import unittest
5379c5dbc2c5 [test/hooks] pep8 and unittest.main instead in unittest_hooks.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11366
diff changeset
   236
    unittest.main()