server/test/unittest_repository.py
author pierre-yves
Mon, 27 May 2013 15:48:03 +0200
changeset 8999 81a5d57d9230
parent 8947 3bbd416b09ec
child 9008 e0aa7cf8abf8
permissions -rw-r--r--
[session] upgrade session closed error from Exception to SessionClosedError Exception is far too wide and we already have a SessionClosedError anyway. Closes #2897696
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: iso-8859-1 -*-
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
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: 5213
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: 5213
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: 5213
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: 5213
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: 5213
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: 5213
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: 5213
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: 5213
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: 5213
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: 5213
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: 5213
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: 5213
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: 5213
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: 5213
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: 5213
diff changeset
    18
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
5889
014ea69e5200 [test] running transaction while session is closed are now killed, update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5582
diff changeset
    19
"""unit tests for module cubicweb.server.repository"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
import os
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
import sys
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
import threading
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
import time
7381
a10b2d90d1a3 [server test] restore logging level after test end
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
    25
import logging
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
from copy import deepcopy
1016
26387b836099 use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents: 17
diff changeset
    27
from datetime import datetime
1251
af40e615dc89 introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents: 17
diff changeset
    28
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
from logilab.common.testlib import TestCase, unittest_main
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
from yams.constraints import UniqueConstraint
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
    32
from yams import register_base_type, unregister_base_type
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
    33
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
    34
from logilab.database import get_db_helper
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    36
from cubicweb import (BadConnectionId, RepositoryError, ValidationError,
6385
9f91d09ee5fa [repo transaction] fix rollback behaviour as discussed on the mailing-list: instead of rollbacking automatically on Unauthorized/ValidationError, mark the transaction as uncommitable and disallow commiting
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6364
diff changeset
    37
                      UnknownEid, AuthenticationError, Unauthorized, QueryError)
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7795
diff changeset
    38
from cubicweb.predicates import is_instance
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
from cubicweb.schema import CubicWebSchema, RQLConstraint
8669
62213a34726e [db-api/configuration] simplify db-api and configuration so that all the connection information is in the repository url, closes #2521848
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8573
diff changeset
    40
from cubicweb.dbapi import connect, multiple_connections_unfix
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    41
from cubicweb.devtools.testlib import CubicWebTC
1251
af40e615dc89 introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents: 17
diff changeset
    42
from cubicweb.devtools.repotest import tuplify
3445
32492e9e734b update and simplify test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
    43
from cubicweb.server import repository, hook
1251
af40e615dc89 introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents: 17
diff changeset
    44
from cubicweb.server.sqlutils import SQL_PREFIX
5115
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
    45
from cubicweb.server.hook import Hook
4806
4f12f59b1a13 [fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
    46
from cubicweb.server.sources import native
8999
81a5d57d9230 [session] upgrade session closed error from Exception to SessionClosedError
pierre-yves
parents: 8947
diff changeset
    47
from cubicweb.server.session import SessionClosedError
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    50
class RepositoryTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
    """ singleton providing access to a persistent storage for entities
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
    and relation
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
    """
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    54
8820
dbffb6959564 server/source/native: fix wrong usage of .lstrip that produce garbled error messages (closes #2777641)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8572
diff changeset
    55
    def test_uniquetogether(self):
dbffb6959564 server/source/native: fix wrong usage of .lstrip that produce garbled error messages (closes #2777641)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8572
diff changeset
    56
        self.execute('INSERT Societe S: S nom "Logilab", S type "SSLL", S cp "75013"')
dbffb6959564 server/source/native: fix wrong usage of .lstrip that produce garbled error messages (closes #2777641)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8572
diff changeset
    57
        with self.assertRaises(ValidationError) as wraperr:
dbffb6959564 server/source/native: fix wrong usage of .lstrip that produce garbled error messages (closes #2777641)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8572
diff changeset
    58
            self.execute('INSERT Societe S: S nom "Logilab", S type "SSLL", S cp "75013"')
dbffb6959564 server/source/native: fix wrong usage of .lstrip that produce garbled error messages (closes #2777641)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8572
diff changeset
    59
        self.assertEqual({'nom': u'violates unique_together constraints (cp, nom, type)',
dbffb6959564 server/source/native: fix wrong usage of .lstrip that produce garbled error messages (closes #2777641)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8572
diff changeset
    60
                          'cp': u'violates unique_together constraints (cp, nom, type)',
dbffb6959564 server/source/native: fix wrong usage of .lstrip that produce garbled error messages (closes #2777641)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8572
diff changeset
    61
                          'type': u'violates unique_together constraints (cp, nom, type)'},
dbffb6959564 server/source/native: fix wrong usage of .lstrip that produce garbled error messages (closes #2777641)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8572
diff changeset
    62
                     wraperr.exception.args[1])
dbffb6959564 server/source/native: fix wrong usage of .lstrip that produce garbled error messages (closes #2777641)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8572
diff changeset
    63
6208
07b176640a8c unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6188
diff changeset
    64
    def test_unique_together(self):
07b176640a8c unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6188
diff changeset
    65
        person = self.repo.schema.eschema('Personne')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
    66
        self.assertEqual(len(person._unique_together), 1)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
    67
        self.assertItemsEqual(person._unique_together[0],
6208
07b176640a8c unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6188
diff changeset
    68
                                           ('nom', 'prenom', 'inline2'))
07b176640a8c unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6188
diff changeset
    69
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6401
diff changeset
    70
    def test_all_entities_have_owner(self):
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7723
diff changeset
    71
        self.assertFalse(self.execute('Any X WHERE NOT X owned_by U'))
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6401
diff changeset
    72
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6401
diff changeset
    73
    def test_all_entities_have_is(self):
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7723
diff changeset
    74
        self.assertFalse(self.execute('Any X WHERE NOT X is ET'))
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6401
diff changeset
    75
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6401
diff changeset
    76
    def test_all_entities_have_cw_source(self):
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7723
diff changeset
    77
        self.assertFalse(self.execute('Any X WHERE NOT X cw_source S'))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    78
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
    def test_connect(self):
7186
287f2273917f [test] drop some warnings introduced by new test dabase handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
    80
        cnxid = self.repo.connect(self.admlogin, password=self.admpassword)
287f2273917f [test] drop some warnings introduced by new test dabase handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
    81
        self.assert_(cnxid)
287f2273917f [test] drop some warnings introduced by new test dabase handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
    82
        self.repo.close(cnxid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
        self.assertRaises(AuthenticationError,
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
    84
                          self.repo.connect, self.admlogin, password='nimportnawak')
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
    85
        self.assertRaises(AuthenticationError,
8520
fcd048fa6e6d [source/native] only system source users should be authenticated by the native source (closes #2465883)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8388
diff changeset
    86
                          self.repo.connect, self.admlogin, password='')
fcd048fa6e6d [source/native] only system source users should be authenticated by the native source (closes #2465883)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8388
diff changeset
    87
        self.assertRaises(AuthenticationError,
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
    88
                          self.repo.connect, self.admlogin, password=None)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
        self.assertRaises(AuthenticationError,
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
    90
                          self.repo.connect, None, password=None)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
        self.assertRaises(AuthenticationError,
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
    92
                          self.repo.connect, self.admlogin)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
        self.assertRaises(AuthenticationError,
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
    94
                          self.repo.connect, None)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    95
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
    def test_execute(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
        repo = self.repo
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
    98
        cnxid = repo.connect(self.admlogin, password=self.admpassword)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
        repo.execute(cnxid, 'Any X')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
        repo.execute(cnxid, 'Any X where X is Personne')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
        repo.execute(cnxid, 'Any X where X is Personne, X nom ~= "to"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
        repo.execute(cnxid, 'Any X WHERE X has_text %(text)s', {'text': u'\xe7a'})
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
        repo.close(cnxid)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   104
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
    def test_login_upassword_accent(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
        repo = self.repo
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
   107
        cnxid = repo.connect(self.admlogin, password=self.admpassword)
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   108
        repo.execute(cnxid, 'INSERT CWUser X: X login %(login)s, X upassword %(passwd)s, X in_group G WHERE G name "users"',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
                     {'login': u"barnab�", 'passwd': u"h�h�h�".encode('UTF8')})
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
        repo.commit(cnxid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
        repo.close(cnxid)
7186
287f2273917f [test] drop some warnings introduced by new test dabase handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
   112
        cnxid = repo.connect(u"barnab�", password=u"h�h�h�".encode('UTF8'))
287f2273917f [test] drop some warnings introduced by new test dabase handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
   113
        self.assert_(cnxid)
287f2273917f [test] drop some warnings introduced by new test dabase handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
   114
        repo.close(cnxid)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   115
6361
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   116
    def test_rollback_on_commit_error(self):
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
   117
        cnxid = self.repo.connect(self.admlogin, password=self.admpassword)
3771
234b003f0fe0 test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2923
diff changeset
   118
        self.repo.execute(cnxid,
234b003f0fe0 test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2923
diff changeset
   119
                          'INSERT CWUser X: X login %(login)s, X upassword %(passwd)s',
234b003f0fe0 test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2923
diff changeset
   120
                          {'login': u"tutetute", 'passwd': 'tutetute'})
234b003f0fe0 test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2923
diff changeset
   121
        self.assertRaises(ValidationError, self.repo.commit, cnxid)
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7723
diff changeset
   122
        self.assertFalse(self.repo.execute(cnxid, 'CWUser X WHERE X login "tutetute"'))
7186
287f2273917f [test] drop some warnings introduced by new test dabase handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
   123
        self.repo.close(cnxid)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   124
6361
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   125
    def test_rollback_on_execute_validation_error(self):
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   126
        class ValidationErrorAfterHook(Hook):
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   127
            __regid__ = 'valerror-after-hook'
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   128
            __select__ = Hook.__select__ & is_instance('CWGroup')
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   129
            events = ('after_update_entity',)
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   130
            def __call__(self):
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   131
                raise ValidationError(self.entity.eid, {})
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   132
        with self.temporary_appobjects(ValidationErrorAfterHook):
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   133
            self.assertRaises(ValidationError,
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   134
                              self.execute, 'SET X name "toto" WHERE X is CWGroup, X name "guests"')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7723
diff changeset
   135
            self.assertTrue(self.execute('Any X WHERE X is CWGroup, X name "toto"'))
6796
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6427
diff changeset
   136
            with self.assertRaises(QueryError) as cm:
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6427
diff changeset
   137
                self.commit()
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6427
diff changeset
   138
            self.assertEqual(str(cm.exception), 'transaction must be rollbacked')
6385
9f91d09ee5fa [repo transaction] fix rollback behaviour as discussed on the mailing-list: instead of rollbacking automatically on Unauthorized/ValidationError, mark the transaction as uncommitable and disallow commiting
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6364
diff changeset
   139
            self.rollback()
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7723
diff changeset
   140
            self.assertFalse(self.execute('Any X WHERE X is CWGroup, X name "toto"'))
6361
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   141
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   142
    def test_rollback_on_execute_unauthorized(self):
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   143
        class UnauthorizedAfterHook(Hook):
6364
ad9ed9803eb6 cleanup and micro-optimization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6361
diff changeset
   144
            __regid__ = 'unauthorized-after-hook'
6361
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   145
            __select__ = Hook.__select__ & is_instance('CWGroup')
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   146
            events = ('after_update_entity',)
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   147
            def __call__(self):
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   148
                raise Unauthorized()
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   149
        with self.temporary_appobjects(UnauthorizedAfterHook):
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   150
            self.assertRaises(Unauthorized,
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   151
                              self.execute, 'SET X name "toto" WHERE X is CWGroup, X name "guests"')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7723
diff changeset
   152
            self.assertTrue(self.execute('Any X WHERE X is CWGroup, X name "toto"'))
6796
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6427
diff changeset
   153
            with self.assertRaises(QueryError) as cm:
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6427
diff changeset
   154
                self.commit()
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6427
diff changeset
   155
            self.assertEqual(str(cm.exception), 'transaction must be rollbacked')
6385
9f91d09ee5fa [repo transaction] fix rollback behaviour as discussed on the mailing-list: instead of rollbacking automatically on Unauthorized/ValidationError, mark the transaction as uncommitable and disallow commiting
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6364
diff changeset
   156
            self.rollback()
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7723
diff changeset
   157
            self.assertFalse(self.execute('Any X WHERE X is CWGroup, X name "toto"'))
6361
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   158
843684a50e48 [transaction] to avoid potential db corruption, we should rollback systematically in case of ValidationError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   159
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   160
    def test_close(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   161
        repo = self.repo
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
   162
        cnxid = repo.connect(self.admlogin, password=self.admpassword)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   163
        self.assert_(cnxid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   164
        repo.close(cnxid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   165
        self.assertRaises(BadConnectionId, repo.execute, cnxid, 'Any X')
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   166
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   167
    def test_invalid_cnxid(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
        self.assertRaises(BadConnectionId, self.repo.execute, 0, 'Any X')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
        self.assertRaises(BadConnectionId, self.repo.close, None)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   170
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   171
    def test_shared_data(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   172
        repo = self.repo
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
   173
        cnxid = repo.connect(self.admlogin, password=self.admpassword)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
        repo.set_shared_data(cnxid, 'data', 4)
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
   175
        cnxid2 = repo.connect(self.admlogin, password=self.admpassword)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   176
        self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   177
        self.assertEqual(repo.get_shared_data(cnxid2, 'data'), None)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
        repo.set_shared_data(cnxid2, 'data', 5)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   179
        self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   180
        self.assertEqual(repo.get_shared_data(cnxid2, 'data'), 5)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   181
        repo.get_shared_data(cnxid2, 'data', pop=True)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   182
        self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   183
        self.assertEqual(repo.get_shared_data(cnxid2, 'data'), None)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   184
        repo.close(cnxid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   185
        repo.close(cnxid2)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   186
        self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid, 'data')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
        self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid2, 'data')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   188
        self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid, 'data', 1)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   189
        self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid2, 'data', 1)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   190
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   191
    def test_check_session(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   192
        repo = self.repo
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
   193
        cnxid = repo.connect(self.admlogin, password=self.admpassword)
6030
a1544ca8913e [test] check_session returns an int since 6012:d56fd78006cd
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5890
diff changeset
   194
        self.assertIsInstance(repo.check_session(cnxid), float)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   195
        repo.close(cnxid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   196
        self.assertRaises(BadConnectionId, repo.check_session, cnxid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   197
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   198
    def test_transaction_base(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   199
        repo = self.repo
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
   200
        cnxid = repo.connect(self.admlogin, password=self.admpassword)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   201
        # check db state
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   202
        result = repo.execute(cnxid, 'Personne X')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   203
        self.assertEqual(result.rowcount, 0)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   204
        # rollback entity insertion
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   205
        repo.execute(cnxid, "INSERT Personne X: X nom 'bidule'")
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   206
        result = repo.execute(cnxid, 'Personne X')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   207
        self.assertEqual(result.rowcount, 1)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   208
        repo.rollback(cnxid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   209
        result = repo.execute(cnxid, 'Personne X')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   210
        self.assertEqual(result.rowcount, 0, result.rows)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   211
        # commit
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   212
        repo.execute(cnxid, "INSERT Personne X: X nom 'bidule'")
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
        repo.commit(cnxid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   214
        result = repo.execute(cnxid, 'Personne X')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   215
        self.assertEqual(result.rowcount, 1)
7186
287f2273917f [test] drop some warnings introduced by new test dabase handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
   216
        repo.close(cnxid)
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
    def test_transaction_base2(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   219
        repo = self.repo
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
   220
        cnxid = repo.connect(self.admlogin, password=self.admpassword)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   221
        # rollback relation insertion
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   222
        repo.execute(cnxid, "SET U in_group G WHERE U login 'admin', G name 'guests'")
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   223
        result = repo.execute(cnxid, "Any U WHERE U in_group G, U login 'admin', G name 'guests'")
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   224
        self.assertEqual(result.rowcount, 1)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   225
        repo.rollback(cnxid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   226
        result = repo.execute(cnxid, "Any U WHERE U in_group G, U login 'admin', G name 'guests'")
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   227
        self.assertEqual(result.rowcount, 0, result.rows)
7186
287f2273917f [test] drop some warnings introduced by new test dabase handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
   228
        repo.close(cnxid)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   229
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   230
    def test_transaction_base3(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   231
        repo = self.repo
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
   232
        cnxid = repo.connect(self.admlogin, password=self.admpassword)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   233
        # rollback state change which trigger TrInfo insertion
4835
13b0b96d7982 [repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4808
diff changeset
   234
        session = repo._get_session(cnxid)
7398
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7382
diff changeset
   235
        session.set_cnxset()
4835
13b0b96d7982 [repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4808
diff changeset
   236
        user = session.user
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5429
diff changeset
   237
        user.cw_adapt_to('IWorkflowable').fire_transition('deactivate')
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   238
        rset = repo.execute(cnxid, 'TrInfo T WHERE T wf_info_for X, X eid %(x)s', {'x': user.eid})
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   239
        self.assertEqual(len(rset), 1)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   240
        repo.rollback(cnxid)
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   241
        rset = repo.execute(cnxid, 'TrInfo T WHERE T wf_info_for X, X eid %(x)s', {'x': user.eid})
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   242
        self.assertEqual(len(rset), 0)
7186
287f2273917f [test] drop some warnings introduced by new test dabase handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
   243
        repo.close(cnxid)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   244
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   245
    def test_transaction_interleaved(self):
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   246
        self.skipTest('implement me')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   247
5889
014ea69e5200 [test] running transaction while session is closed are now killed, update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5582
diff changeset
   248
    def test_close_kill_processing_request(self):
1880
293fe4b49e28 two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   249
        repo = self.repo
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
   250
        cnxid = repo.connect(self.admlogin, password=self.admpassword)
1880
293fe4b49e28 two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   251
        repo.execute(cnxid, 'INSERT CWUser X: X login "toto", X upassword "tutu", X in_group G WHERE G name "users"')
293fe4b49e28 two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   252
        repo.commit(cnxid)
7343
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7339
diff changeset
   253
        lock = threading.Lock()
7339
dd5e49a5dcab [server test] use a lock instead of sleep to have higher green probability :/
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7238
diff changeset
   254
        lock.acquire()
1880
293fe4b49e28 two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   255
        # close has to be in the thread due to sqlite limitations
293fe4b49e28 two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   256
        def close_in_a_few_moment():
7339
dd5e49a5dcab [server test] use a lock instead of sleep to have higher green probability :/
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7238
diff changeset
   257
            lock.acquire()
1880
293fe4b49e28 two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   258
            repo.close(cnxid)
293fe4b49e28 two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   259
        t = threading.Thread(target=close_in_a_few_moment)
293fe4b49e28 two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   260
        t.start()
5889
014ea69e5200 [test] running transaction while session is closed are now killed, update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5582
diff changeset
   261
        def run_transaction():
7339
dd5e49a5dcab [server test] use a lock instead of sleep to have higher green probability :/
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7238
diff changeset
   262
            lock.release()
1880
293fe4b49e28 two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   263
            repo.execute(cnxid, 'DELETE CWUser X WHERE X login "toto"')
293fe4b49e28 two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   264
            repo.commit(cnxid)
5889
014ea69e5200 [test] running transaction while session is closed are now killed, update test accordingly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5582
diff changeset
   265
        try:
8999
81a5d57d9230 [session] upgrade session closed error from Exception to SessionClosedError
pierre-yves
parents: 8947
diff changeset
   266
            with self.assertRaises(SessionClosedError) as cm:
6796
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6427
diff changeset
   267
                run_transaction()
7666
8644c2a065f0 fix test broken by previous commit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7563
diff changeset
   268
            self.assertEqual(str(cm.exception), 'try to access connections set on a closed session %s' % cnxid)
1880
293fe4b49e28 two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   269
        finally:
293fe4b49e28 two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   270
            t.join()
293fe4b49e28 two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   271
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   272
    def test_initial_schema(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   273
        schema = self.repo.schema
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   274
        # check order of attributes is respected
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   275
        self.assertListEqual([r.type for r in schema.eschema('CWAttribute').ordered_relations()
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   276
                               if not r.type in ('eid', 'is', 'is_instance_of', 'identity',
2608
21856eda34f6 [F repo tests] tests have to be updated:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2588
diff changeset
   277
                                                 'creation_date', 'modification_date', 'cwuri',
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6401
diff changeset
   278
                                                 'owned_by', 'created_by', 'cw_source',
5582
3e133b29a1a4 [rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5429
diff changeset
   279
                                                 'update_permission', 'read_permission',
3e133b29a1a4 [rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5429
diff changeset
   280
                                                 'in_basket')],
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
   281
                              ['relation_type',
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
   282
                               'from_entity', 'to_entity',
5582
3e133b29a1a4 [rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5429
diff changeset
   283
                               'constrained_by',
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   284
                               'cardinality', 'ordernum',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   285
                               'indexed', 'fulltextindexed', 'internationalizable',
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   286
                               'defaultval', 'extra_props',
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   287
                               'description', 'description_format'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   288
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   289
        self.assertEqual(schema.eschema('CWEType').main_attribute(), 'name')
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   290
        self.assertEqual(schema.eschema('State').main_attribute(), 'name')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   291
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
   292
        constraints = schema.rschema('name').rdef('CWEType', 'String').constraints
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   293
        self.assertEqual(len(constraints), 2)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   294
        for cstr in constraints[:]:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   295
            if isinstance(cstr, UniqueConstraint):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   296
                constraints.remove(cstr)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   297
                break
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   298
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   299
            self.fail('unique constraint not found')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   300
        sizeconstraint = constraints[0]
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   301
        self.assertEqual(sizeconstraint.min, None)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   302
        self.assertEqual(sizeconstraint.max, 64)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   303
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
   304
        constraints = schema.rschema('relation_type').rdef('CWAttribute', 'CWRType').constraints
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   305
        self.assertEqual(len(constraints), 1)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   306
        cstr = constraints[0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   307
        self.assert_(isinstance(cstr, RQLConstraint))
7161
e3f69df8dac7 fix failing tests before 3.12 release
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7148
diff changeset
   308
        self.assertEqual(cstr.expression, 'O final TRUE')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   309
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   310
        ownedby = schema.rschema('owned_by')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   311
        self.assertEqual(ownedby.objects('CWEType'), ('CWUser',))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   312
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   313
    def test_pyro(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   314
        import Pyro
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   315
        Pyro.config.PYRO_MULTITHREADED = 0
1880
293fe4b49e28 two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   316
        done = []
8874
522bdba66690 [server/test] remove dependency on a pyro name server (closes #2801737)
Julien Cristau <julien.cristau@logilab.fr>
parents: 8821
diff changeset
   317
        self.repo.config.global_set_option('pyro-ns-host', 'NO_PYRONS')
522bdba66690 [server/test] remove dependency on a pyro name server (closes #2801737)
Julien Cristau <julien.cristau@logilab.fr>
parents: 8821
diff changeset
   318
        daemon = self.repo.pyro_register()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   319
        try:
8874
522bdba66690 [server/test] remove dependency on a pyro name server (closes #2801737)
Julien Cristau <julien.cristau@logilab.fr>
parents: 8821
diff changeset
   320
            uri = self.repo.pyro_uri.replace('PYRO', 'pyroloc')
522bdba66690 [server/test] remove dependency on a pyro name server (closes #2801737)
Julien Cristau <julien.cristau@logilab.fr>
parents: 8821
diff changeset
   321
            # the client part has to be in the thread due to sqlite limitations
522bdba66690 [server/test] remove dependency on a pyro name server (closes #2801737)
Julien Cristau <julien.cristau@logilab.fr>
parents: 8821
diff changeset
   322
            t = threading.Thread(target=self._pyro_client, args=(uri, done))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   323
            t.start()
1880
293fe4b49e28 two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   324
            while not done:
293fe4b49e28 two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   325
                daemon.handleRequests(1.0)
293fe4b49e28 two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   326
            t.join(1)
293fe4b49e28 two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   327
            if t.isAlive():
293fe4b49e28 two in one: #343320: Logging out while deleting a CWUser blocks the cw server / #342692: ensure transaction state when Ctrl-C or other stop signal is received
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   328
                self.fail('something went wrong, thread still alive')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   329
        finally:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   330
            repository.pyro_unregister(self.repo.config)
4766
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   331
            from logilab.common import pyro_ext
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   332
            pyro_ext._DAEMONS.clear()
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   333
5115
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   334
8874
522bdba66690 [server/test] remove dependency on a pyro name server (closes #2801737)
Julien Cristau <julien.cristau@logilab.fr>
parents: 8821
diff changeset
   335
    def _pyro_client(self, uri, done):
522bdba66690 [server/test] remove dependency on a pyro name server (closes #2801737)
Julien Cristau <julien.cristau@logilab.fr>
parents: 8821
diff changeset
   336
        cnx = connect(uri,
8669
62213a34726e [db-api/configuration] simplify db-api and configuration so that all the connection information is in the repository url, closes #2521848
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8573
diff changeset
   337
                      u'admin', password='gingkow',
5115
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   338
                      initlog=False) # don't reset logging configuration
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: 2642
diff changeset
   339
        try:
5429
5ca1f8fe8a42 [dbapi] more test and documentation of dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   340
            cnx.load_appobjects(subpath=('entities',))
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: 2642
diff changeset
   341
            # check we can get the schema
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: 2642
diff changeset
   342
            schema = cnx.get_schema()
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7723
diff changeset
   343
            self.assertTrue(cnx.vreg)
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7723
diff changeset
   344
            self.assertTrue('etypes'in cnx.vreg)
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: 2642
diff changeset
   345
            cu = cnx.cursor()
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: 2642
diff changeset
   346
            rset = cu.execute('Any U,G WHERE U in_group G')
5429
5ca1f8fe8a42 [dbapi] more test and documentation of dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   347
            user = iter(rset.entities()).next()
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7723
diff changeset
   348
            self.assertTrue(user._cw)
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7723
diff changeset
   349
            self.assertTrue(user._cw.vreg)
5429
5ca1f8fe8a42 [dbapi] more test and documentation of dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   350
            from cubicweb.entities import authobjs
5ca1f8fe8a42 [dbapi] more test and documentation of dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   351
            self.assertIsInstance(user._cw.user, authobjs.CWUser)
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: 2642
diff changeset
   352
            cnx.close()
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: 2642
diff changeset
   353
            done.append(True)
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: 2642
diff changeset
   354
        finally:
5115
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   355
            # connect monkey patch some method by default, remove them
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: 2642
diff changeset
   356
            multiple_connections_unfix()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   357
8353
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   358
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   359
    def test_zmq(self):
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   360
        try:
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   361
            import zmq
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   362
        except ImportError:
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   363
            self.skipTest("zmq in not available")
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   364
        done = []
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   365
        from cubicweb.devtools import TestServerConfiguration as ServerConfiguration
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   366
        from cubicweb.server.cwzmq import ZMQRepositoryServer
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   367
        # the client part has to be in a thread due to sqlite limitations
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   368
        t = threading.Thread(target=self._zmq_client, args=(done,))
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   369
        t.start()
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   370
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   371
        zmq_server = ZMQRepositoryServer(self.repo)
8670
f02139297beb prefix "tcp://" zmq uris with "zmqpickle" (closes #2574114)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   372
        zmq_server.connect('zmqpickle-tcp://127.0.0.1:41415')
8353
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   373
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   374
        t2 = threading.Thread(target=self._zmq_quit, args=(done, zmq_server,))
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   375
        t2.start()
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   376
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   377
        zmq_server.run()
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   378
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   379
        t2.join(1)
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   380
        t.join(1)
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   381
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   382
        if t.isAlive():
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   383
            self.fail('something went wrong, thread still alive')
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   384
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   385
    def _zmq_quit(self, done, srv):
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   386
        while not done:
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   387
            time.sleep(0.1)
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   388
        srv.quit()
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   389
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   390
    def _zmq_client(self, done):
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   391
        try:
8670
f02139297beb prefix "tcp://" zmq uris with "zmqpickle" (closes #2574114)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   392
            cnx = connect('zmqpickle-tcp://127.0.0.1:41415', u'admin', password=u'gingkow',
8388
c6c624cea870 [repo test] Avoid hangs in zmq repo unit test
Julien Cristau <julien.cristau@logilab.fr>
parents: 8353
diff changeset
   393
                          initlog=False) # don't reset logging configuration
c6c624cea870 [repo test] Avoid hangs in zmq repo unit test
Julien Cristau <julien.cristau@logilab.fr>
parents: 8353
diff changeset
   394
            try:
c6c624cea870 [repo test] Avoid hangs in zmq repo unit test
Julien Cristau <julien.cristau@logilab.fr>
parents: 8353
diff changeset
   395
                cnx.load_appobjects(subpath=('entities',))
c6c624cea870 [repo test] Avoid hangs in zmq repo unit test
Julien Cristau <julien.cristau@logilab.fr>
parents: 8353
diff changeset
   396
                # check we can get the schema
c6c624cea870 [repo test] Avoid hangs in zmq repo unit test
Julien Cristau <julien.cristau@logilab.fr>
parents: 8353
diff changeset
   397
                schema = cnx.get_schema()
c6c624cea870 [repo test] Avoid hangs in zmq repo unit test
Julien Cristau <julien.cristau@logilab.fr>
parents: 8353
diff changeset
   398
                self.assertTrue(cnx.vreg)
c6c624cea870 [repo test] Avoid hangs in zmq repo unit test
Julien Cristau <julien.cristau@logilab.fr>
parents: 8353
diff changeset
   399
                self.assertTrue('etypes'in cnx.vreg)
c6c624cea870 [repo test] Avoid hangs in zmq repo unit test
Julien Cristau <julien.cristau@logilab.fr>
parents: 8353
diff changeset
   400
                cu = cnx.cursor()
c6c624cea870 [repo test] Avoid hangs in zmq repo unit test
Julien Cristau <julien.cristau@logilab.fr>
parents: 8353
diff changeset
   401
                rset = cu.execute('Any U,G WHERE U in_group G')
c6c624cea870 [repo test] Avoid hangs in zmq repo unit test
Julien Cristau <julien.cristau@logilab.fr>
parents: 8353
diff changeset
   402
                user = iter(rset.entities()).next()
c6c624cea870 [repo test] Avoid hangs in zmq repo unit test
Julien Cristau <julien.cristau@logilab.fr>
parents: 8353
diff changeset
   403
                self.assertTrue(user._cw)
c6c624cea870 [repo test] Avoid hangs in zmq repo unit test
Julien Cristau <julien.cristau@logilab.fr>
parents: 8353
diff changeset
   404
                self.assertTrue(user._cw.vreg)
c6c624cea870 [repo test] Avoid hangs in zmq repo unit test
Julien Cristau <julien.cristau@logilab.fr>
parents: 8353
diff changeset
   405
                from cubicweb.entities import authobjs
c6c624cea870 [repo test] Avoid hangs in zmq repo unit test
Julien Cristau <julien.cristau@logilab.fr>
parents: 8353
diff changeset
   406
                self.assertIsInstance(user._cw.user, authobjs.CWUser)
c6c624cea870 [repo test] Avoid hangs in zmq repo unit test
Julien Cristau <julien.cristau@logilab.fr>
parents: 8353
diff changeset
   407
                cnx.close()
c6c624cea870 [repo test] Avoid hangs in zmq repo unit test
Julien Cristau <julien.cristau@logilab.fr>
parents: 8353
diff changeset
   408
                done.append(True)
c6c624cea870 [repo test] Avoid hangs in zmq repo unit test
Julien Cristau <julien.cristau@logilab.fr>
parents: 8353
diff changeset
   409
            finally:
c6c624cea870 [repo test] Avoid hangs in zmq repo unit test
Julien Cristau <julien.cristau@logilab.fr>
parents: 8353
diff changeset
   410
                # connect monkey patch some method by default, remove them
c6c624cea870 [repo test] Avoid hangs in zmq repo unit test
Julien Cristau <julien.cristau@logilab.fr>
parents: 8353
diff changeset
   411
                multiple_connections_unfix()
8353
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   412
        finally:
8388
c6c624cea870 [repo test] Avoid hangs in zmq repo unit test
Julien Cristau <julien.cristau@logilab.fr>
parents: 8353
diff changeset
   413
            done.append(False)
8353
c1cc2f1cd177 [zmq] add unit tests for ZMQ-based repository (server and dbapi)
David Douard <david.douard@logilab.fr>
parents: 8190
diff changeset
   414
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   415
    def test_internal_api(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   416
        repo = self.repo
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
   417
        cnxid = repo.connect(self.admlogin, password=self.admpassword)
7398
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7382
diff changeset
   418
        session = repo._get_session(cnxid, setcnxset=True)
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6401
diff changeset
   419
        self.assertEqual(repo.type_and_source_from_eid(2, session),
7543
570522300e22 [ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7539
diff changeset
   420
                         ('CWGroup', 'system', None, 'system'))
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6401
diff changeset
   421
        self.assertEqual(repo.type_from_eid(2, session), 'CWGroup')
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6401
diff changeset
   422
        self.assertEqual(repo.source_from_eid(2, session).uri, 'system')
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6401
diff changeset
   423
        self.assertEqual(repo.eid2extid(repo.system_source, 2, session), None)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   424
        class dummysource: uri = 'toto'
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6401
diff changeset
   425
        self.assertRaises(UnknownEid, repo.eid2extid, dummysource, 2, session)
7186
287f2273917f [test] drop some warnings introduced by new test dabase handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
   426
        repo.close(cnxid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   427
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   428
    def test_public_api(self):
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   429
        self.assertEqual(self.repo.get_schema(), self.repo.schema)
7563
8e129bb6b571 [tests] update repository tests with new `use_cwuri_as_url` attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7543
diff changeset
   430
        self.assertEqual(self.repo.source_defs(), {'system': {'type': 'native',
8e129bb6b571 [tests] update repository tests with new `use_cwuri_as_url` attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7543
diff changeset
   431
                                                              'uri': 'system',
8e129bb6b571 [tests] update repository tests with new `use_cwuri_as_url` attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7543
diff changeset
   432
                                                              'use-cwuri-as-url': False}
8e129bb6b571 [tests] update repository tests with new `use_cwuri_as_url` attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7543
diff changeset
   433
                                                  })
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   434
        # .properties() return a result set
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   435
        self.assertEqual(self.repo.properties().rql, 'Any K,V WHERE P is CWProperty,P pkey K, P value V, NOT P for_user U')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   436
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   437
    def test_session_api(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   438
        repo = self.repo
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
   439
        cnxid = repo.connect(self.admlogin, password=self.admpassword)
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6401
diff changeset
   440
        self.assertEqual(repo.user_info(cnxid), (6, 'admin', set([u'managers']), {}))
7543
570522300e22 [ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7539
diff changeset
   441
        self.assertEqual(repo.describe(cnxid, 2), (u'CWGroup', u'system', None, 'system'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   442
        repo.close(cnxid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   443
        self.assertRaises(BadConnectionId, repo.user_info, cnxid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   444
        self.assertRaises(BadConnectionId, repo.describe, cnxid, 1)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   445
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   446
    def test_shared_data_api(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   447
        repo = self.repo
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
   448
        cnxid = repo.connect(self.admlogin, password=self.admpassword)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   449
        self.assertEqual(repo.get_shared_data(cnxid, 'data'), None)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   450
        repo.set_shared_data(cnxid, 'data', 4)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   451
        self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   452
        repo.get_shared_data(cnxid, 'data', pop=True)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   453
        repo.get_shared_data(cnxid, 'whatever', pop=True)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   454
        self.assertEqual(repo.get_shared_data(cnxid, 'data'), None)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   455
        repo.close(cnxid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   456
        self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid, 'data', 0)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   457
        self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid, 'data')
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   458
2588
3a590ff82e99 [F schema serial] #344876: missing some 'is'/'is_instance_of' relation for newly created instances
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2200
diff changeset
   459
    def test_schema_is_relation(self):
3a590ff82e99 [F schema serial] #344876: missing some 'is'/'is_instance_of' relation for newly created instances
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2200
diff changeset
   460
        no_is_rset = self.execute('Any X WHERE NOT X is ET')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7723
diff changeset
   461
        self.assertFalse(no_is_rset, no_is_rset.description)
2588
3a590ff82e99 [F schema serial] #344876: missing some 'is'/'is_instance_of' relation for newly created instances
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2200
diff changeset
   462
2642
2d30de60a8ff cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2608
diff changeset
   463
#     def test_perfo(self):
2d30de60a8ff cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2608
diff changeset
   464
#         self.set_debug(True)
2d30de60a8ff cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2608
diff changeset
   465
#         from time import time, clock
2d30de60a8ff cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2608
diff changeset
   466
#         t, c = time(), clock()
2d30de60a8ff cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2608
diff changeset
   467
#         try:
2d30de60a8ff cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2608
diff changeset
   468
#             self.create_user('toto')
2d30de60a8ff cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2608
diff changeset
   469
#         finally:
2d30de60a8ff cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2608
diff changeset
   470
#             self.set_debug(False)
2d30de60a8ff cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2608
diff changeset
   471
#         print 'test time: %.3f (time) %.3f (cpu)' % ((time() - t), clock() - c)
2d30de60a8ff cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2608
diff changeset
   472
2923
b97a0f8dd4dc fix test schema and update some tests to work again with wf changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   473
    def test_delete_if_singlecard1(self):
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
   474
        note = self.request().create_entity('Affaire')
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
   475
        p1 = self.request().create_entity('Personne', nom=u'toto')
2923
b97a0f8dd4dc fix test schema and update some tests to work again with wf changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   476
        self.execute('SET A todo_by P WHERE A eid %(x)s, P eid %(p)s',
b97a0f8dd4dc fix test schema and update some tests to work again with wf changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   477
                     {'x': note.eid, 'p': p1.eid})
b97a0f8dd4dc fix test schema and update some tests to work again with wf changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   478
        rset = self.execute('Any P WHERE A todo_by P, A eid %(x)s',
b97a0f8dd4dc fix test schema and update some tests to work again with wf changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   479
                            {'x': note.eid})
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   480
        self.assertEqual(len(rset), 1)
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
   481
        p2 = self.request().create_entity('Personne', nom=u'tutu')
2923
b97a0f8dd4dc fix test schema and update some tests to work again with wf changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   482
        self.execute('SET A todo_by P WHERE A eid %(x)s, P eid %(p)s',
b97a0f8dd4dc fix test schema and update some tests to work again with wf changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   483
                     {'x': note.eid, 'p': p2.eid})
b97a0f8dd4dc fix test schema and update some tests to work again with wf changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   484
        rset = self.execute('Any P WHERE A todo_by P, A eid %(x)s',
b97a0f8dd4dc fix test schema and update some tests to work again with wf changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   485
                            {'x': note.eid})
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   486
        self.assertEqual(len(rset), 1)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   487
        self.assertEqual(rset.rows[0][0], p2.eid)
2923
b97a0f8dd4dc fix test schema and update some tests to work again with wf changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   488
6188
e1c9610b2360 [integrity] fix case where we can get two entities related while the cardinality is single on the object of an inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5890
diff changeset
   489
    def test_delete_if_object_inlined_singlecard(self):
e1c9610b2360 [integrity] fix case where we can get two entities related while the cardinality is single on the object of an inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5890
diff changeset
   490
        req = self.request()
e1c9610b2360 [integrity] fix case where we can get two entities related while the cardinality is single on the object of an inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5890
diff changeset
   491
        c = req.create_entity('Card', title=u'Carte')
e1c9610b2360 [integrity] fix case where we can get two entities related while the cardinality is single on the object of an inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5890
diff changeset
   492
        req.create_entity('Personne', nom=u'Vincent', fiche=c)
e1c9610b2360 [integrity] fix case where we can get two entities related while the cardinality is single on the object of an inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5890
diff changeset
   493
        req.create_entity('Personne', nom=u'Florent', fiche=c)
e1c9610b2360 [integrity] fix case where we can get two entities related while the cardinality is single on the object of an inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5890
diff changeset
   494
        self.commit()
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   495
        self.assertEqual(len(c.reverse_fiche), 1)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   496
8483
4ba11607d84a [entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8388
diff changeset
   497
    def test_cw_set_in_before_update(self):
5115
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   498
        # local hook
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   499
        class DummyBeforeHook(Hook):
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   500
            __regid__ = 'dummy-before-hook'
5877
0c7b7b76a84f [selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5717
diff changeset
   501
            __select__ = Hook.__select__ & is_instance('EmailAddress')
5115
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   502
            events = ('before_update_entity',)
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   503
            def __call__(self):
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   504
                # safety belt: avoid potential infinite recursion if the test
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   505
                #              fails (i.e. RuntimeError not raised)
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   506
                pendings = self._cw.transaction_data.setdefault('pending', set())
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   507
                if self.entity.eid not in pendings:
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   508
                    pendings.add(self.entity.eid)
8483
4ba11607d84a [entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8388
diff changeset
   509
                    self.entity.cw_set(alias=u'foo')
5115
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   510
        with self.temporary_appobjects(DummyBeforeHook):
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   511
            req = self.request()
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   512
            addr = req.create_entity('EmailAddress', address=u'a@b.fr')
8483
4ba11607d84a [entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8388
diff changeset
   513
            addr.cw_set(address=u'a@b.com')
5115
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   514
            rset = self.execute('Any A,AA WHERE X eid %(x)s, X address A, X alias AA',
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   515
                                {'x': addr.eid})
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   516
            self.assertEqual(rset.rows, [[u'a@b.com', u'foo']])
5115
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   517
8483
4ba11607d84a [entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8388
diff changeset
   518
    def test_cw_set_in_before_add(self):
5115
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   519
        # local hook
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   520
        class DummyBeforeHook(Hook):
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   521
            __regid__ = 'dummy-before-hook'
5877
0c7b7b76a84f [selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5717
diff changeset
   522
            __select__ = Hook.__select__ & is_instance('EmailAddress')
5115
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   523
            events = ('before_add_entity',)
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   524
            def __call__(self):
8483
4ba11607d84a [entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8388
diff changeset
   525
                # cw_set is forbidden within before_add_entity()
4ba11607d84a [entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8388
diff changeset
   526
                self.entity.cw_set(alias=u'foo')
5115
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   527
        with self.temporary_appobjects(DummyBeforeHook):
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   528
            req = self.request()
5126
c869d8e7d166 [test] fix expected error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5115
diff changeset
   529
            # XXX will fail with python -O
c869d8e7d166 [test] fix expected error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5115
diff changeset
   530
            self.assertRaises(AssertionError, req.create_entity,
5115
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   531
                              'EmailAddress', address=u'a@b.fr')
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   532
8483
4ba11607d84a [entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8388
diff changeset
   533
    def test_multiple_edit_cw_set(self):
6142
8bc6eac1fac1 [session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6030
diff changeset
   534
        """make sure cw_edited doesn't get cluttered
5213
8604000bf3b2 [repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5126
diff changeset
   535
        by previous entities on multiple set
8604000bf3b2 [repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5126
diff changeset
   536
        """
8604000bf3b2 [repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5126
diff changeset
   537
        # local hook
8604000bf3b2 [repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5126
diff changeset
   538
        class DummyBeforeHook(Hook):
8604000bf3b2 [repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5126
diff changeset
   539
            _test = self # keep reference to test instance
8604000bf3b2 [repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5126
diff changeset
   540
            __regid__ = 'dummy-before-hook'
5877
0c7b7b76a84f [selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5717
diff changeset
   541
            __select__ = Hook.__select__ & is_instance('Affaire')
5213
8604000bf3b2 [repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5126
diff changeset
   542
            events = ('before_update_entity',)
8604000bf3b2 [repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5126
diff changeset
   543
            def __call__(self):
8604000bf3b2 [repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5126
diff changeset
   544
                # invoiced attribute shouldn't be considered "edited" before the hook
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7723
diff changeset
   545
                self._test.assertFalse('invoiced' in self.entity.cw_edited,
6142
8bc6eac1fac1 [session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6030
diff changeset
   546
                                  'cw_edited cluttered by previous update')
8bc6eac1fac1 [session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6030
diff changeset
   547
                self.entity.cw_edited['invoiced'] = 10
5213
8604000bf3b2 [repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5126
diff changeset
   548
        with self.temporary_appobjects(DummyBeforeHook):
8604000bf3b2 [repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5126
diff changeset
   549
            req = self.request()
8604000bf3b2 [repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5126
diff changeset
   550
            req.create_entity('Affaire', ref=u'AFF01')
8604000bf3b2 [repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5126
diff changeset
   551
            req.create_entity('Affaire', ref=u'AFF02')
8604000bf3b2 [repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5126
diff changeset
   552
            req.execute('SET A duration 10 WHERE A is Affaire')
8604000bf3b2 [repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5126
diff changeset
   553
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   554
class SchemaDeserialTC(CubicWebTC):
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   555
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   556
    appid = 'data-schemaserial'
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   557
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   558
    @classmethod
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   559
    def setUpClass(cls):
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   560
        register_base_type('BabarTestType', ('jungle_speed',))
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   561
        helper = get_db_helper('sqlite')
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   562
        helper.TYPE_MAPPING['BabarTestType'] = 'TEXT'
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   563
        helper.TYPE_CONVERTERS['BabarTestType'] = lambda x: '"%s"' % x
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   564
        super(SchemaDeserialTC, cls).setUpClass()
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   565
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   566
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   567
    @classmethod
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   568
    def tearDownClass(cls):
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   569
        unregister_base_type('BabarTestType')
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   570
        helper = get_db_helper('sqlite')
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   571
        helper.TYPE_MAPPING.pop('BabarTestType', None)
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   572
        helper.TYPE_CONVERTERS.pop('BabarTestType', None)
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   573
        super(SchemaDeserialTC, cls).tearDownClass()
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   574
8947
3bbd416b09ec [repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8945
diff changeset
   575
    def test_deserialization_base(self):
3bbd416b09ec [repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8945
diff changeset
   576
        """Check the following deserialization
3bbd416b09ec [repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8945
diff changeset
   577
3bbd416b09ec [repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8945
diff changeset
   578
        * all CWEtype has name
3bbd416b09ec [repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8945
diff changeset
   579
        * Final type
3bbd416b09ec [repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8945
diff changeset
   580
        * CWUniqueTogetherConstraint
3bbd416b09ec [repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8945
diff changeset
   581
        * _unique_together__ content"""
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   582
        origshema = self.repo.schema
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   583
        try:
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   584
            self.repo.config.repairing = True # avoid versions checking
8947
3bbd416b09ec [repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8945
diff changeset
   585
            self.repo.set_schema(self.repo.deserialize_schema())
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   586
            table = SQL_PREFIX + 'CWEType'
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   587
            namecol = SQL_PREFIX + 'name'
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   588
            finalcol = SQL_PREFIX + 'final'
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   589
            self.session.set_cnxset()
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   590
            cu = self.session.system_sql('SELECT %s FROM %s WHERE %s is NULL' % (
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   591
                namecol, table, finalcol))
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   592
            self.assertEqual(cu.fetchall(), [])
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   593
            cu = self.session.system_sql('SELECT %s FROM %s WHERE %s=%%(final)s ORDER BY %s'
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   594
                                         % (namecol, table, finalcol, namecol), {'final': True})
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   595
            self.assertEqual(cu.fetchall(), [(u'BabarTestType',),
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   596
                                             (u'BigInt',), (u'Boolean',), (u'Bytes',),
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   597
                                             (u'Date',), (u'Datetime',),
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   598
                                             (u'Decimal',),(u'Float',),
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   599
                                             (u'Int',),
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   600
                                             (u'Interval',), (u'Password',),
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   601
                                             (u'String',),
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   602
                                             (u'TZDatetime',), (u'TZTime',), (u'Time',)])
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   603
            sql = ("SELECT etype.cw_eid, etype.cw_name, cstr.cw_eid, rel.eid_to "
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   604
                   "FROM cw_CWUniqueTogetherConstraint as cstr, "
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   605
                   "     relations_relation as rel, "
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   606
                   "     cw_CWEType as etype "
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   607
                   "WHERE cstr.cw_eid = rel.eid_from "
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   608
                   "  AND cstr.cw_constraint_of = etype.cw_eid "
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   609
                   "  AND etype.cw_name = 'Personne' "
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   610
                   ";")
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   611
            cu = self.session.system_sql(sql)
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   612
            rows = cu.fetchall()
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   613
            self.assertEqual(len(rows), 3)
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   614
            person = self.repo.schema.eschema('Personne')
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   615
            self.assertEqual(len(person._unique_together), 1)
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   616
            self.assertItemsEqual(person._unique_together[0],
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   617
                                  ('nom', 'prenom', 'inline2'))
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   618
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   619
        finally:
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   620
            self.repo.set_schema(origshema)
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   621
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   622
    def test_custom_attribute_param(self):
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   623
        origshema = self.repo.schema
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   624
        try:
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   625
            self.repo.config.repairing = True # avoid versions checking
8947
3bbd416b09ec [repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8945
diff changeset
   626
            self.repo.set_schema(self.repo.deserialize_schema())
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   627
            pes = self.repo.schema['Personne']
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   628
            attr = pes.rdef('custom_field_of_jungle')
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   629
            self.assertIn('jungle_speed', vars(attr))
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   630
            self.assertEqual(42, attr.jungle_speed)
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   631
        finally:
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   632
            self.repo.set_schema(origshema)
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   633
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8874
diff changeset
   634
5115
2e43ef618d14 [repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5106
diff changeset
   635
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   636
class DataHelpersTC(CubicWebTC):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   637
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   638
    def test_create_eid(self):
7398
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7382
diff changeset
   639
        self.session.set_cnxset()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   640
        self.assert_(self.repo.system_source.create_eid(self.session))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   641
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   642
    def test_source_from_eid(self):
7398
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7382
diff changeset
   643
        self.session.set_cnxset()
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   644
        self.assertEqual(self.repo.source_from_eid(1, self.session),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   645
                          self.repo.sources_by_uri['system'])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   646
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   647
    def test_source_from_eid_raise(self):
7398
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7382
diff changeset
   648
        self.session.set_cnxset()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   649
        self.assertRaises(UnknownEid, self.repo.source_from_eid, -2, self.session)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   650
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   651
    def test_type_from_eid(self):
7398
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7382
diff changeset
   652
        self.session.set_cnxset()
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6401
diff changeset
   653
        self.assertEqual(self.repo.type_from_eid(2, self.session), 'CWGroup')
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   654
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   655
    def test_type_from_eid_raise(self):
7398
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7382
diff changeset
   656
        self.session.set_cnxset()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   657
        self.assertRaises(UnknownEid, self.repo.type_from_eid, -2, self.session)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   658
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   659
    def test_add_delete_info(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: 2642
diff changeset
   660
        entity = self.repo.vreg['etypes'].etype_class('Personne')(self.session)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   661
        entity.eid = -1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   662
        entity.complete = lambda x: None
7398
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7382
diff changeset
   663
        self.session.set_cnxset()
4913
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 4835
diff changeset
   664
        self.repo.add_info(self.session, entity, self.repo.system_source)
2200
25bb65dc4559 test fixes, all server tests ok, except unittest_migractions (due to inter-tests-side-effects...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   665
        cu = self.session.system_sql('SELECT * FROM entities WHERE eid = -1')
25bb65dc4559 test fixes, all server tests ok, except unittest_migractions (due to inter-tests-side-effects...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   666
        data = cu.fetchall()
7543
570522300e22 [ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7539
diff changeset
   667
        self.assertIsInstance(data[0][4], datetime)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   668
        data[0] = list(data[0])
7543
570522300e22 [ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7539
diff changeset
   669
        data[0][4] = None
570522300e22 [ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7539
diff changeset
   670
        self.assertEqual(tuplify(data), [(-1, 'Personne', 'system', 'system',
570522300e22 [ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7539
diff changeset
   671
                                          None, None)])
4913
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 4835
diff changeset
   672
        self.repo.delete_info(self.session, entity, 'system', None)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   673
        #self.repo.commit()
2200
25bb65dc4559 test fixes, all server tests ok, except unittest_migractions (due to inter-tests-side-effects...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   674
        cu = self.session.system_sql('SELECT * FROM entities WHERE eid = -1')
25bb65dc4559 test fixes, all server tests ok, except unittest_migractions (due to inter-tests-side-effects...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   675
        data = cu.fetchall()
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   676
        self.assertEqual(data, [])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   677
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   678
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   679
class FTITC(CubicWebTC):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   680
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   681
    def test_reindex_and_modified_since(self):
5106
782ff24a7e46 [test] avoid critical log by informing the source we consider Personne as a multi-sources type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5105
diff changeset
   682
        self.repo.system_source.multisources_etypes.add('Personne')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   683
        eidp = self.execute('INSERT Personne X: X nom "toto", X prenom "tutu"')[0][0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   684
        self.commit()
1016
26387b836099 use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents: 17
diff changeset
   685
        ts = datetime.now()
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   686
        self.assertEqual(len(self.execute('Personne X WHERE X has_text "tutu"')), 1)
7398
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7382
diff changeset
   687
        self.session.set_cnxset()
2200
25bb65dc4559 test fixes, all server tests ok, except unittest_migractions (due to inter-tests-side-effects...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   688
        cu = self.session.system_sql('SELECT mtime, eid FROM entities WHERE eid = %s' % eidp)
25bb65dc4559 test fixes, all server tests ok, except unittest_migractions (due to inter-tests-side-effects...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   689
        omtime = cu.fetchone()[0]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   690
        # our sqlite datetime adapter is ignore seconds fraction, so we have to
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   691
        # ensure update is done the next seconds
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   692
        time.sleep(1 - (ts.second - int(ts.second)))
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5126
diff changeset
   693
        self.execute('SET X nom "tata" WHERE X eid %(x)s', {'x': eidp})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   694
        self.commit()
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   695
        self.assertEqual(len(self.execute('Personne X WHERE X has_text "tutu"')), 1)
7398
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7382
diff changeset
   696
        self.session.set_cnxset()
2200
25bb65dc4559 test fixes, all server tests ok, except unittest_migractions (due to inter-tests-side-effects...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   697
        cu = self.session.system_sql('SELECT mtime FROM entities WHERE eid = %s' % eidp)
25bb65dc4559 test fixes, all server tests ok, except unittest_migractions (due to inter-tests-side-effects...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   698
        mtime = cu.fetchone()[0]
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7723
diff changeset
   699
        self.assertTrue(omtime < mtime)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   700
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   701
        date, modified, deleted = self.repo.entities_modified_since(('Personne',), omtime)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   702
        self.assertEqual(modified, [('Personne', eidp)])
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   703
        self.assertEqual(deleted, [])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   704
        date, modified, deleted = self.repo.entities_modified_since(('Personne',), mtime)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   705
        self.assertEqual(modified, [])
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   706
        self.assertEqual(deleted, [])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   707
        self.execute('DELETE Personne X WHERE X eid %(x)s', {'x': eidp})
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   708
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   709
        date, modified, deleted = self.repo.entities_modified_since(('Personne',), omtime)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   710
        self.assertEqual(modified, [])
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   711
        self.assertEqual(deleted, [('Personne', eidp)])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   712
4806
4f12f59b1a13 [fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   713
    def test_fulltext_container_entity(self):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   714
        assert self.schema.rschema('use_email').fulltext_container == 'subject'
4806
4f12f59b1a13 [fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   715
        req = self.request()
4f12f59b1a13 [fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   716
        toto = req.create_entity('EmailAddress', address=u'toto@logilab.fr')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   717
        self.commit()
4806
4f12f59b1a13 [fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   718
        rset = req.execute('Any X WHERE X has_text %(t)s', {'t': 'toto'})
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   719
        self.assertEqual(rset.rows, [])
8483
4ba11607d84a [entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8388
diff changeset
   720
        req.user.cw_set(use_email=toto)
4806
4f12f59b1a13 [fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   721
        self.commit()
4f12f59b1a13 [fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   722
        rset = req.execute('Any X WHERE X has_text %(t)s', {'t': 'toto'})
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   723
        self.assertEqual(rset.rows, [[req.user.eid]])
4806
4f12f59b1a13 [fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   724
        req.execute('DELETE X use_email Y WHERE X login "admin", Y eid %(y)s',
4f12f59b1a13 [fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   725
                    {'y': toto.eid})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   726
        self.commit()
4806
4f12f59b1a13 [fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   727
        rset = req.execute('Any X WHERE X has_text %(t)s', {'t': 'toto'})
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   728
        self.assertEqual(rset.rows, [])
4806
4f12f59b1a13 [fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   729
        tutu = req.create_entity('EmailAddress', address=u'tutu@logilab.fr')
8483
4ba11607d84a [entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8388
diff changeset
   730
        req.user.cw_set(use_email=tutu)
4806
4f12f59b1a13 [fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   731
        self.commit()
4f12f59b1a13 [fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   732
        rset = req.execute('Any X WHERE X has_text %(t)s', {'t': 'tutu'})
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   733
        self.assertEqual(rset.rows, [[req.user.eid]])
8483
4ba11607d84a [entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8388
diff changeset
   734
        tutu.cw_set(address=u'hip@logilab.fr')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   735
        self.commit()
4806
4f12f59b1a13 [fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   736
        rset = req.execute('Any X WHERE X has_text %(t)s', {'t': 'tutu'})
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   737
        self.assertEqual(rset.rows, [])
4806
4f12f59b1a13 [fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   738
        rset = req.execute('Any X WHERE X has_text %(t)s', {'t': 'hip'})
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   739
        self.assertEqual(rset.rows, [[req.user.eid]])
4806
4f12f59b1a13 [fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   740
4f12f59b1a13 [fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   741
    def test_no_uncessary_ftiindex_op(self):
4f12f59b1a13 [fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   742
        req = self.request()
4f12f59b1a13 [fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   743
        req.create_entity('Workflow', name=u'dummy workflow', description=u'huuuuu')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7723
diff changeset
   744
        self.assertFalse(any(x for x in self.session.pending_operations
4806
4f12f59b1a13 [fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   745
                        if isinstance(x, native.FTIndexEntityOp)))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   746
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   747
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   748
class DBInitTC(CubicWebTC):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   749
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   750
    def test_versions_inserted(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   751
        inserted = [r[0] for r in self.execute('Any K ORDERBY K WHERE P pkey K, P pkey ~= "system.version.%"')]
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   752
        self.assertEqual(inserted,
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   753
                          [u'system.version.basket', u'system.version.card', u'system.version.comment',
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   754
                           u'system.version.cubicweb', u'system.version.email',
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   755
                           u'system.version.file', u'system.version.folder',
7795
b8027b317d1c [test] fix some tests broken since localperms cube extraction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7791
diff changeset
   756
                           u'system.version.localperms', u'system.version.tag'])
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   757
3445
32492e9e734b update and simplify test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   758
CALLED = []
32492e9e734b update and simplify test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   759
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   760
class InlineRelHooksTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   761
    """test relation hooks are called for inlined relations
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   762
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   763
    def setUp(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
   764
        CubicWebTC.setUp(self)
3445
32492e9e734b update and simplify test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   765
        CALLED[:] = ()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   766
7398
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7382
diff changeset
   767
    def _after_relation_hook(self, cnxset, fromeid, rtype, toeid):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   768
        self.called.append((fromeid, rtype, toeid))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   769
3445
32492e9e734b update and simplify test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   770
    def test_inline_relation(self):
32492e9e734b update and simplify test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   771
        """make sure <event>_relation hooks are called for inlined relation"""
4766
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   772
        class EcritParHook(hook.Hook):
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   773
            __regid__ = 'inlinedrelhook'
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   774
            __select__ = hook.Hook.__select__ & hook.match_rtype('ecrit_par')
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   775
            events = ('before_add_relation', 'after_add_relation',
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   776
                      'before_delete_relation', 'after_delete_relation')
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   777
            def __call__(self):
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   778
                CALLED.append((self.event, self.eidfrom, self.rtype, self.eidto))
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   779
5105
57e0fc953676 [test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5103
diff changeset
   780
        with self.temporary_appobjects(EcritParHook):
57e0fc953676 [test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5103
diff changeset
   781
            eidp = self.execute('INSERT Personne X: X nom "toto"')[0][0]
57e0fc953676 [test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5103
diff changeset
   782
            eidn = self.execute('INSERT Note X: X type "T"')[0][0]
57e0fc953676 [test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5103
diff changeset
   783
            self.execute('SET N ecrit_par Y WHERE N type "T", Y nom "toto"')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   784
            self.assertEqual(CALLED, [('before_add_relation', eidn, 'ecrit_par', eidp),
5105
57e0fc953676 [test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5103
diff changeset
   785
                                       ('after_add_relation', eidn, 'ecrit_par', eidp)])
57e0fc953676 [test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5103
diff changeset
   786
            CALLED[:] = ()
57e0fc953676 [test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5103
diff changeset
   787
            self.execute('DELETE N ecrit_par Y WHERE N type "T", Y nom "toto"')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   788
            self.assertEqual(CALLED, [('before_delete_relation', eidn, 'ecrit_par', eidp),
5105
57e0fc953676 [test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5103
diff changeset
   789
                                       ('after_delete_relation', eidn, 'ecrit_par', eidp)])
57e0fc953676 [test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5103
diff changeset
   790
            CALLED[:] = ()
57e0fc953676 [test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5103
diff changeset
   791
            eidn = self.execute('INSERT Note N: N ecrit_par P WHERE P nom "toto"')[0][0]
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6236
diff changeset
   792
            self.assertEqual(CALLED, [('before_add_relation', eidn, 'ecrit_par', eidp),
5105
57e0fc953676 [test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5103
diff changeset
   793
                                       ('after_add_relation', eidn, 'ecrit_par', eidp)])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   794
6236
9138f23ee263 [repo tests] add test case for RQLUniqueConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6208
diff changeset
   795
    def test_unique_contraint(self):
9138f23ee263 [repo tests] add test case for RQLUniqueConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6208
diff changeset
   796
        req = self.request()
9138f23ee263 [repo tests] add test case for RQLUniqueConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6208
diff changeset
   797
        toto = req.create_entity('Personne', nom=u'toto')
9138f23ee263 [repo tests] add test case for RQLUniqueConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6208
diff changeset
   798
        a01 = req.create_entity('Affaire', ref=u'A01', todo_by=toto)
9138f23ee263 [repo tests] add test case for RQLUniqueConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6208
diff changeset
   799
        req.cnx.commit()
9138f23ee263 [repo tests] add test case for RQLUniqueConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6208
diff changeset
   800
        req = self.request()
9138f23ee263 [repo tests] add test case for RQLUniqueConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6208
diff changeset
   801
        req.create_entity('Note', type=u'todo', inline1=a01)
9138f23ee263 [repo tests] add test case for RQLUniqueConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6208
diff changeset
   802
        req.cnx.commit()
9138f23ee263 [repo tests] add test case for RQLUniqueConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6208
diff changeset
   803
        req = self.request()
9138f23ee263 [repo tests] add test case for RQLUniqueConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6208
diff changeset
   804
        req.create_entity('Note', type=u'todo', inline1=a01)
6796
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6427
diff changeset
   805
        with self.assertRaises(ValidationError) as cm:
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6427
diff changeset
   806
            req.cnx.commit()
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6427
diff changeset
   807
        self.assertEqual(cm.exception.errors, {'inline1-subject': u'RQLUniqueConstraint S type T, S inline1 A1, A1 todo_by C, Y type T, Y inline1 A2, A2 todo_by C failed'})
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   808
7238
576abb8c4626 fix implementation of repository.glob_add_relations (closes ##1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7237
diff changeset
   809
    def test_add_relations_at_creation_with_del_existing_rel(self):
576abb8c4626 fix implementation of repository.glob_add_relations (closes ##1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7237
diff changeset
   810
        req = self.request()
576abb8c4626 fix implementation of repository.glob_add_relations (closes ##1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7237
diff changeset
   811
        person = req.create_entity('Personne', nom=u'Toto', prenom=u'Lanturlu', sexe=u'M')
576abb8c4626 fix implementation of repository.glob_add_relations (closes ##1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7237
diff changeset
   812
        users_rql = 'Any U WHERE U is CWGroup, U name "users"'
576abb8c4626 fix implementation of repository.glob_add_relations (closes ##1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7237
diff changeset
   813
        users = self.execute(users_rql).get_entity(0, 0)
576abb8c4626 fix implementation of repository.glob_add_relations (closes ##1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7237
diff changeset
   814
        req.create_entity('CWUser',
576abb8c4626 fix implementation of repository.glob_add_relations (closes ##1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7237
diff changeset
   815
                      login=u'Toto',
576abb8c4626 fix implementation of repository.glob_add_relations (closes ##1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7237
diff changeset
   816
                      upassword=u'firstname',
576abb8c4626 fix implementation of repository.glob_add_relations (closes ##1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7237
diff changeset
   817
                      firstname=u'firstname',
576abb8c4626 fix implementation of repository.glob_add_relations (closes ##1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7237
diff changeset
   818
                      surname=u'surname',
576abb8c4626 fix implementation of repository.glob_add_relations (closes ##1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7237
diff changeset
   819
                      reverse_login_user=person,
576abb8c4626 fix implementation of repository.glob_add_relations (closes ##1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7237
diff changeset
   820
                      in_group=users)
576abb8c4626 fix implementation of repository.glob_add_relations (closes ##1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7237
diff changeset
   821
        self.commit()
7236
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   822
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   823
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   824
class PerformanceTest(CubicWebTC):
7381
a10b2d90d1a3 [server test] restore logging level after test end
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   825
    def setUp(self):
a10b2d90d1a3 [server test] restore logging level after test end
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   826
        super(PerformanceTest, self).setUp()
7236
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   827
        logger = logging.getLogger('cubicweb.session')
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   828
        #logger.handlers = [logging.StreamHandler(sys.stdout)]
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   829
        logger.setLevel(logging.INFO)
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   830
        self.info = logger.info
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   831
7381
a10b2d90d1a3 [server test] restore logging level after test end
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   832
    def tearDown(self):
a10b2d90d1a3 [server test] restore logging level after test end
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   833
        super(PerformanceTest, self).tearDown()
7382
91061a22755d fix name error introduced in previous changeset
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7381
diff changeset
   834
        logger = logging.getLogger('cubicweb.session')
7381
a10b2d90d1a3 [server test] restore logging level after test end
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   835
        logger.setLevel(logging.CRITICAL)
a10b2d90d1a3 [server test] restore logging level after test end
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   836
7236
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   837
    def test_composite_deletion(self):
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   838
        req = self.request()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   839
        personnes = []
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   840
        t0 = time.time()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   841
        for i in xrange(2000):
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   842
            p = req.create_entity('Personne', nom=u'Doe%03d'%i, prenom=u'John', sexe=u'M')
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   843
            personnes.append(p)
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   844
        abraham = req.create_entity('Personne', nom=u'Abraham', prenom=u'John', sexe=u'M')
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   845
        for j in xrange(0, 2000, 100):
8483
4ba11607d84a [entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8388
diff changeset
   846
            abraham.cw_set(personne_composite=personnes[j:j+100])
7236
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   847
        t1 = time.time()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   848
        self.info('creation: %.2gs', (t1 - t0))
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   849
        req.cnx.commit()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   850
        t2 = time.time()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   851
        self.info('commit creation: %.2gs', (t2 - t1))
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   852
        self.execute('DELETE Personne P WHERE P eid %(eid)s', {'eid': abraham.eid})
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   853
        t3 = time.time()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   854
        self.info('deletion: %.2gs', (t3 - t2))
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   855
        req.cnx.commit()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   856
        t4 = time.time()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   857
        self.info("commit deletion: %2gs", (t4 - t3))
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   858
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   859
    def test_add_relation_non_inlined(self):
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   860
        req = self.request()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   861
        personnes = []
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   862
        for i in xrange(2000):
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   863
            p = req.create_entity('Personne', nom=u'Doe%03d'%i, prenom=u'John', sexe=u'M')
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   864
            personnes.append(p)
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   865
        req.cnx.commit()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   866
        t0 = time.time()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   867
        abraham = req.create_entity('Personne', nom=u'Abraham', prenom=u'John', sexe=u'M',
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   868
                                    personne_composite=personnes[:100])
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   869
        t1 = time.time()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   870
        self.info('creation: %.2gs', (t1 - t0))
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   871
        for j in xrange(100, 2000, 100):
8483
4ba11607d84a [entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8388
diff changeset
   872
            abraham.cw_set(personne_composite=personnes[j:j+100])
7236
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   873
        t2 = time.time()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   874
        self.info('more relations: %.2gs', (t2-t1))
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   875
        req.cnx.commit()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   876
        t3 = time.time()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   877
        self.info('commit creation: %.2gs', (t3 - t2))
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   878
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   879
    def test_add_relation_inlined(self):
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   880
        req = self.request()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   881
        personnes = []
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   882
        for i in xrange(2000):
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   883
            p = req.create_entity('Personne', nom=u'Doe%03d'%i, prenom=u'John', sexe=u'M')
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   884
            personnes.append(p)
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   885
        req.cnx.commit()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   886
        t0 = time.time()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   887
        abraham = req.create_entity('Personne', nom=u'Abraham', prenom=u'John', sexe=u'M',
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   888
                                    personne_inlined=personnes[:100])
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   889
        t1 = time.time()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   890
        self.info('creation: %.2gs', (t1 - t0))
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   891
        for j in xrange(100, 2000, 100):
8483
4ba11607d84a [entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8388
diff changeset
   892
            abraham.cw_set(personne_inlined=personnes[j:j+100])
7236
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   893
        t2 = time.time()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   894
        self.info('more relations: %.2gs', (t2-t1))
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   895
        req.cnx.commit()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   896
        t3 = time.time()
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   897
        self.info('commit creation: %.2gs', (t3 - t2))
b91205ada414 added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7194
diff changeset
   898
7237
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   899
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   900
    def test_session_add_relation(self):
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   901
        """ to be compared with test_session_add_relations"""
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   902
        req = self.request()
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   903
        personnes = []
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   904
        for i in xrange(2000):
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   905
            p = req.create_entity('Personne', nom=u'Doe%03d'%i, prenom=u'John', sexe=u'M')
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   906
            personnes.append(p)
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   907
        abraham = req.create_entity('Personne', nom=u'Abraham', prenom=u'John', sexe=u'M')
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   908
        req.cnx.commit()
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   909
        t0 = time.time()
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   910
        add_relation = self.session.add_relation
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   911
        for p in personnes:
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   912
            add_relation(abraham.eid, 'personne_composite', p.eid)
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   913
        req.cnx.commit()
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   914
        t1 = time.time()
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   915
        self.info('add relation: %.2gs', t1-t0)
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   916
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   917
    def test_session_add_relations (self):
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   918
        """ to be compared with test_session_add_relation"""
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   919
        req = self.request()
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   920
        personnes = []
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   921
        for i in xrange(2000):
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   922
            p = req.create_entity('Personne', nom=u'Doe%03d'%i, prenom=u'John', sexe=u'M')
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   923
            personnes.append(p)
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   924
        abraham = req.create_entity('Personne', nom=u'Abraham', prenom=u'John', sexe=u'M')
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   925
        req.cnx.commit()
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   926
        t0 = time.time()
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   927
        add_relations = self.session.add_relations
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   928
        relations = [('personne_composite', [(abraham.eid, p.eid) for p in personnes])]
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   929
        add_relations(relations)
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   930
        req.cnx.commit()
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   931
        t1 = time.time()
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   932
        self.info('add relations: %.2gs', t1-t0)
7543
570522300e22 [ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7539
diff changeset
   933
7237
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   934
    def test_session_add_relation_inlined(self):
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   935
        """ to be compared with test_session_add_relations"""
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   936
        req = self.request()
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   937
        personnes = []
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   938
        for i in xrange(2000):
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   939
            p = req.create_entity('Personne', nom=u'Doe%03d'%i, prenom=u'John', sexe=u'M')
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   940
            personnes.append(p)
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   941
        abraham = req.create_entity('Personne', nom=u'Abraham', prenom=u'John', sexe=u'M')
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   942
        req.cnx.commit()
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   943
        t0 = time.time()
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   944
        add_relation = self.session.add_relation
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   945
        for p in personnes:
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   946
            add_relation(abraham.eid, 'personne_inlined', p.eid)
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   947
        req.cnx.commit()
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   948
        t1 = time.time()
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   949
        self.info('add relation (inlined): %.2gs', t1-t0)
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   950
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   951
    def test_session_add_relations_inlined (self):
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   952
        """ to be compared with test_session_add_relation"""
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   953
        req = self.request()
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   954
        personnes = []
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   955
        for i in xrange(2000):
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   956
            p = req.create_entity('Personne', nom=u'Doe%03d'%i, prenom=u'John', sexe=u'M')
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   957
            personnes.append(p)
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   958
        abraham = req.create_entity('Personne', nom=u'Abraham', prenom=u'John', sexe=u'M')
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   959
        req.cnx.commit()
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   960
        t0 = time.time()
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   961
        add_relations = self.session.add_relations
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   962
        relations = [('personne_inlined', [(abraham.eid, p.eid) for p in personnes])]
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   963
        add_relations(relations)
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   964
        req.cnx.commit()
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   965
        t1 = time.time()
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   966
        self.info('add relations (inlined): %.2gs', t1-t0)
9f619715665b [server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7236
diff changeset
   967
7513
8f4422391e5a [repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   968
    def test_optional_relation_reset_1(self):
8f4422391e5a [repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   969
        req = self.request()
8f4422391e5a [repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   970
        p1 = req.create_entity('Personne', nom=u'Vincent')
8f4422391e5a [repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   971
        p2 = req.create_entity('Personne', nom=u'Florent')
8f4422391e5a [repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   972
        w = req.create_entity('Affaire', ref=u'wc')
8483
4ba11607d84a [entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8388
diff changeset
   973
        w.cw_set(todo_by=[p1,p2])
7539
7cd9fc2adcac [test] update to 3.13 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7514
diff changeset
   974
        w.cw_clear_all_caches()
7513
8f4422391e5a [repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   975
        self.commit()
8f4422391e5a [repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   976
        self.assertEqual(len(w.todo_by), 1)
8f4422391e5a [repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   977
        self.assertEqual(w.todo_by[0].eid, p2.eid)
8f4422391e5a [repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   978
8f4422391e5a [repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   979
    def test_optional_relation_reset_2(self):
8f4422391e5a [repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   980
        req = self.request()
8f4422391e5a [repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   981
        p1 = req.create_entity('Personne', nom=u'Vincent')
8f4422391e5a [repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   982
        p2 = req.create_entity('Personne', nom=u'Florent')
8f4422391e5a [repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   983
        w = req.create_entity('Affaire', ref=u'wc')
8483
4ba11607d84a [entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8388
diff changeset
   984
        w.cw_set(todo_by=p1)
7513
8f4422391e5a [repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   985
        self.commit()
8483
4ba11607d84a [entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8388
diff changeset
   986
        w.cw_set(todo_by=p2)
7539
7cd9fc2adcac [test] update to 3.13 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7514
diff changeset
   987
        w.cw_clear_all_caches()
7513
8f4422391e5a [repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   988
        self.commit()
8f4422391e5a [repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   989
        self.assertEqual(len(w.todo_by), 1)
8f4422391e5a [repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7343
diff changeset
   990
        self.assertEqual(w.todo_by[0].eid, p2.eid)
7238
576abb8c4626 fix implementation of repository.glob_add_relations (closes ##1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7237
diff changeset
   991
576abb8c4626 fix implementation of repository.glob_add_relations (closes ##1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7237
diff changeset
   992
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   993
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   994
    unittest_main()