author | Alexandre Fayolle <alexandre.fayolle@logilab.fr> |
Fri, 15 Apr 2011 16:05:20 +0200 | |
changeset 7236 | b91205ada414 |
parent 7194 | 79686c864bbf |
child 7237 | 9f619715665b |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: iso-8859-1 -*- |
7186
287f2273917f
[test] drop some warnings introduced by new test dabase handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6796
diff
changeset
|
2 |
# copyright 2003-2011 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 | 20 |
|
5115
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
21 |
from __future__ import with_statement |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
22 |
|
0 | 23 |
import os |
24 |
import sys |
|
25 |
import threading |
|
26 |
import time |
|
27 |
from copy import deepcopy |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
17
diff
changeset
|
28 |
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
|
29 |
|
0 | 30 |
from logilab.common.testlib import TestCase, unittest_main |
31 |
||
32 |
from yams.constraints import UniqueConstraint |
|
33 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
34 |
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
|
35 |
UnknownEid, AuthenticationError, Unauthorized, QueryError) |
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
|
36 |
from cubicweb.selectors import is_instance |
0 | 37 |
from cubicweb.schema import CubicWebSchema, RQLConstraint |
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
|
38 |
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
|
39 |
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
|
40 |
from cubicweb.devtools.repotest import tuplify |
3445
32492e9e734b
update and simplify test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
41 |
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
|
42 |
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
|
43 |
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
|
44 |
from cubicweb.server.sources import native |
0 | 45 |
|
46 |
# start name server anyway, process will fail if already running |
|
47 |
os.system('pyro-ns >/dev/null 2>/dev/null &') |
|
48 |
||
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 | 51 |
""" singleton providing access to a persistent storage for entities |
52 |
and relation |
|
53 |
""" |
|
1787 | 54 |
|
0 | 55 |
def test_fill_schema(self): |
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
|
56 |
origshema = self.repo.schema |
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
|
57 |
try: |
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
|
58 |
self.repo.schema = CubicWebSchema(self.repo.config.appid) |
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
|
59 |
self.repo.config._cubes = None # avoid assertion error |
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
|
60 |
self.repo.config.repairing = True # avoid versions checking |
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
|
61 |
self.repo.fill_schema() |
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
|
62 |
table = SQL_PREFIX + 'CWEType' |
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
|
63 |
namecol = SQL_PREFIX + 'name' |
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
|
64 |
finalcol = SQL_PREFIX + 'final' |
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
|
65 |
self.session.set_pool() |
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
|
66 |
cu = self.session.system_sql('SELECT %s FROM %s WHERE %s is NULL' % ( |
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
|
67 |
namecol, table, finalcol)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6236
diff
changeset
|
68 |
self.assertEqual(cu.fetchall(), []) |
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
|
69 |
cu = self.session.system_sql('SELECT %s FROM %s WHERE %s=%%(final)s ORDER BY %s' |
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
|
70 |
% (namecol, table, finalcol, namecol), {'final': '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
|
71 |
self.assertEqual(cu.fetchall(), [(u'Boolean',), (u'Bytes',), |
7148
753b9b48b41e
more TZDatetime/TZTime test fixes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6796
diff
changeset
|
72 |
(u'Date',), (u'Datetime',), |
753b9b48b41e
more TZDatetime/TZTime test fixes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6796
diff
changeset
|
73 |
(u'Decimal',),(u'Float',), |
753b9b48b41e
more TZDatetime/TZTime test fixes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6796
diff
changeset
|
74 |
(u'Int',), |
753b9b48b41e
more TZDatetime/TZTime test fixes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6796
diff
changeset
|
75 |
(u'Interval',), (u'Password',), |
753b9b48b41e
more TZDatetime/TZTime test fixes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6796
diff
changeset
|
76 |
(u'String',), |
753b9b48b41e
more TZDatetime/TZTime test fixes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6796
diff
changeset
|
77 |
(u'TZDatetime',), (u'TZTime',), (u'Time',)]) |
6208
07b176640a8c
unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6188
diff
changeset
|
78 |
sql = ("SELECT etype.cw_eid, etype.cw_name, cstr.cw_eid, rel.eid_to " |
07b176640a8c
unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6188
diff
changeset
|
79 |
"FROM cw_CWUniqueTogetherConstraint as cstr, " |
07b176640a8c
unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6188
diff
changeset
|
80 |
" relations_relation as rel, " |
07b176640a8c
unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6188
diff
changeset
|
81 |
" cw_CWEType as etype " |
07b176640a8c
unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6188
diff
changeset
|
82 |
"WHERE cstr.cw_eid = rel.eid_from " |
07b176640a8c
unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6188
diff
changeset
|
83 |
" AND cstr.cw_constraint_of = etype.cw_eid " |
07b176640a8c
unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6188
diff
changeset
|
84 |
" AND etype.cw_name = 'Personne' " |
07b176640a8c
unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6188
diff
changeset
|
85 |
";") |
07b176640a8c
unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6188
diff
changeset
|
86 |
cu = self.session.system_sql(sql) |
07b176640a8c
unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6188
diff
changeset
|
87 |
rows = 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
|
88 |
self.assertEqual(len(rows), 3) |
6208
07b176640a8c
unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6188
diff
changeset
|
89 |
self.test_unique_together() |
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
|
90 |
finally: |
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
|
91 |
self.repo.set_schema(origshema) |
1787 | 92 |
|
6208
07b176640a8c
unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6188
diff
changeset
|
93 |
def test_unique_together(self): |
07b176640a8c
unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6188
diff
changeset
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
('nom', 'prenom', 'inline2')) |
07b176640a8c
unique_together integration in CW (alf+syt)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6188
diff
changeset
|
98 |
|
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6401
diff
changeset
|
99 |
def test_all_entities_have_owner(self): |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6401
diff
changeset
|
100 |
self.failIf(self.execute('Any X WHERE NOT X owned_by U')) |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6401
diff
changeset
|
101 |
|
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6401
diff
changeset
|
102 |
def test_all_entities_have_is(self): |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6401
diff
changeset
|
103 |
self.failIf(self.execute('Any X WHERE NOT X is ET')) |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6401
diff
changeset
|
104 |
|
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6401
diff
changeset
|
105 |
def test_all_entities_have_cw_source(self): |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6401
diff
changeset
|
106 |
self.failIf(self.execute('Any X WHERE NOT X cw_source S')) |
1787 | 107 |
|
0 | 108 |
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
|
109 |
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
|
110 |
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
|
111 |
self.repo.close(cnxid) |
0 | 112 |
self.assertRaises(AuthenticationError, |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
113 |
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
|
114 |
self.assertRaises(AuthenticationError, |
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
115 |
self.repo.connect, self.admlogin, password=None) |
0 | 116 |
self.assertRaises(AuthenticationError, |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
117 |
self.repo.connect, None, password=None) |
0 | 118 |
self.assertRaises(AuthenticationError, |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
119 |
self.repo.connect, self.admlogin) |
0 | 120 |
self.assertRaises(AuthenticationError, |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
121 |
self.repo.connect, None) |
1787 | 122 |
|
0 | 123 |
def test_execute(self): |
124 |
repo = self.repo |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
125 |
cnxid = repo.connect(self.admlogin, password=self.admpassword) |
0 | 126 |
repo.execute(cnxid, 'Any X') |
127 |
repo.execute(cnxid, 'Any X where X is Personne') |
|
128 |
repo.execute(cnxid, 'Any X where X is Personne, X nom ~= "to"') |
|
129 |
repo.execute(cnxid, 'Any X WHERE X has_text %(text)s', {'text': u'\xe7a'}) |
|
130 |
repo.close(cnxid) |
|
1787 | 131 |
|
0 | 132 |
def test_login_upassword_accent(self): |
133 |
repo = self.repo |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
134 |
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
|
135 |
repo.execute(cnxid, 'INSERT CWUser X: X login %(login)s, X upassword %(passwd)s, X in_group G WHERE G name "users"', |
0 | 136 |
{'login': u"barnab�", 'passwd': u"h�h�h�".encode('UTF8')}) |
137 |
repo.commit(cnxid) |
|
138 |
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
|
139 |
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
|
140 |
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
|
141 |
repo.close(cnxid) |
1787 | 142 |
|
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
|
143 |
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
|
144 |
cnxid = self.repo.connect(self.admlogin, password=self.admpassword) |
3771 | 145 |
self.repo.execute(cnxid, |
146 |
'INSERT CWUser X: X login %(login)s, X upassword %(passwd)s', |
|
147 |
{'login': u"tutetute", 'passwd': 'tutetute'}) |
|
148 |
self.assertRaises(ValidationError, self.repo.commit, cnxid) |
|
149 |
self.failIf(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
|
150 |
self.repo.close(cnxid) |
1787 | 151 |
|
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
|
152 |
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
|
153 |
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
|
154 |
__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
|
155 |
__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
|
156 |
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
|
157 |
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
|
158 |
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
|
159 |
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
|
160 |
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
|
161 |
self.execute, 'SET X name "toto" WHERE X is CWGroup, X name "guests"') |
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
|
162 |
self.failUnless(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
|
163 |
with self.assertRaises(QueryError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
164 |
self.commit() |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
165 |
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
|
166 |
self.rollback() |
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
|
167 |
self.failIf(self.execute('Any X WHERE X is CWGroup, X name "toto"')) |
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
|
168 |
|
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
|
169 |
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
|
170 |
class UnauthorizedAfterHook(Hook): |
6364
ad9ed9803eb6
cleanup and micro-optimization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6361
diff
changeset
|
171 |
__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
|
172 |
__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
|
173 |
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
|
174 |
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
|
175 |
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
|
176 |
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
|
177 |
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
|
178 |
self.execute, 'SET X name "toto" WHERE X is CWGroup, X name "guests"') |
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
|
179 |
self.failUnless(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
|
180 |
with self.assertRaises(QueryError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
181 |
self.commit() |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
182 |
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
|
183 |
self.rollback() |
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
|
184 |
self.failIf(self.execute('Any X WHERE X is CWGroup, X name "toto"')) |
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
|
185 |
|
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
|
186 |
|
0 | 187 |
def test_close(self): |
188 |
repo = self.repo |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
189 |
cnxid = repo.connect(self.admlogin, password=self.admpassword) |
0 | 190 |
self.assert_(cnxid) |
191 |
repo.close(cnxid) |
|
192 |
self.assertRaises(BadConnectionId, repo.execute, cnxid, 'Any X') |
|
1787 | 193 |
|
0 | 194 |
def test_invalid_cnxid(self): |
195 |
self.assertRaises(BadConnectionId, self.repo.execute, 0, 'Any X') |
|
196 |
self.assertRaises(BadConnectionId, self.repo.close, None) |
|
1787 | 197 |
|
0 | 198 |
def test_shared_data(self): |
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 | 201 |
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
|
202 |
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
|
203 |
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
|
204 |
self.assertEqual(repo.get_shared_data(cnxid2, 'data'), None) |
0 | 205 |
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
|
206 |
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
|
207 |
self.assertEqual(repo.get_shared_data(cnxid2, 'data'), 5) |
0 | 208 |
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
|
209 |
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
|
210 |
self.assertEqual(repo.get_shared_data(cnxid2, 'data'), None) |
0 | 211 |
repo.close(cnxid) |
212 |
repo.close(cnxid2) |
|
213 |
self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid, 'data') |
|
214 |
self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid2, 'data') |
|
215 |
self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid, 'data', 1) |
|
216 |
self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid2, 'data', 1) |
|
217 |
||
218 |
def test_check_session(self): |
|
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) |
6030
a1544ca8913e
[test] check_session returns an int since 6012:d56fd78006cd
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
221 |
self.assertIsInstance(repo.check_session(cnxid), float) |
0 | 222 |
repo.close(cnxid) |
223 |
self.assertRaises(BadConnectionId, repo.check_session, cnxid) |
|
224 |
||
225 |
def test_transaction_base(self): |
|
226 |
repo = self.repo |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
227 |
cnxid = repo.connect(self.admlogin, password=self.admpassword) |
0 | 228 |
# check db state |
229 |
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
|
230 |
self.assertEqual(result.rowcount, 0) |
0 | 231 |
# rollback entity insertion |
232 |
repo.execute(cnxid, "INSERT Personne X: X nom 'bidule'") |
|
233 |
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
|
234 |
self.assertEqual(result.rowcount, 1) |
0 | 235 |
repo.rollback(cnxid) |
236 |
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
|
237 |
self.assertEqual(result.rowcount, 0, result.rows) |
0 | 238 |
# commit |
239 |
repo.execute(cnxid, "INSERT Personne X: X nom 'bidule'") |
|
240 |
repo.commit(cnxid) |
|
241 |
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
|
242 |
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
|
243 |
repo.close(cnxid) |
0 | 244 |
|
245 |
def test_transaction_base2(self): |
|
246 |
repo = self.repo |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
247 |
cnxid = repo.connect(self.admlogin, password=self.admpassword) |
0 | 248 |
# rollback relation insertion |
249 |
repo.execute(cnxid, "SET U in_group G WHERE U login 'admin', G name 'guests'") |
|
250 |
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
|
251 |
self.assertEqual(result.rowcount, 1) |
0 | 252 |
repo.rollback(cnxid) |
253 |
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
|
254 |
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
|
255 |
repo.close(cnxid) |
1787 | 256 |
|
0 | 257 |
def test_transaction_base3(self): |
258 |
repo = self.repo |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
259 |
cnxid = repo.connect(self.admlogin, password=self.admpassword) |
0 | 260 |
# 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
|
261 |
session = repo._get_session(cnxid) |
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
|
262 |
session.set_pool() |
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
|
263 |
user = session.user |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5429
diff
changeset
|
264 |
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
|
265 |
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
|
266 |
self.assertEqual(len(rset), 1) |
0 | 267 |
repo.rollback(cnxid) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
268 |
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
|
269 |
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
|
270 |
repo.close(cnxid) |
1787 | 271 |
|
0 | 272 |
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
|
273 |
self.skipTest('implement me') |
0 | 274 |
|
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
|
275 |
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
|
276 |
repo = self.repo |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
277 |
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
|
278 |
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
|
279 |
repo.commit(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
|
280 |
# 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
|
281 |
def 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
|
282 |
time.sleep(0.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
|
283 |
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
|
284 |
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
|
285 |
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
|
286 |
def run_transaction(): |
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
|
287 |
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
|
288 |
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
|
289 |
try: |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
290 |
with self.assertRaises(Exception) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
291 |
run_transaction() |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
292 |
self.assertEqual(str(cm.exception), 'try to access pool on a closed session') |
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
|
293 |
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
|
294 |
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
|
295 |
|
0 | 296 |
def test_initial_schema(self): |
297 |
schema = self.repo.schema |
|
298 |
# 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
|
299 |
self.assertListEqual([r.type for r in schema.eschema('CWAttribute').ordered_relations() |
1787 | 300 |
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
|
301 |
'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
|
302 |
'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
|
303 |
'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
|
304 |
'in_basket')], |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
305 |
['relation_type', |
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
306 |
'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
|
307 |
'constrained_by', |
1787 | 308 |
'cardinality', 'ordernum', |
0 | 309 |
'indexed', 'fulltextindexed', 'internationalizable', |
2608
21856eda34f6
[F repo tests] tests have to be updated:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2588
diff
changeset
|
310 |
'defaultval', 'description', 'description_format']) |
0 | 311 |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6236
diff
changeset
|
312 |
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
|
313 |
self.assertEqual(schema.eschema('State').main_attribute(), 'name') |
0 | 314 |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
315 |
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
|
316 |
self.assertEqual(len(constraints), 2) |
0 | 317 |
for cstr in constraints[:]: |
318 |
if isinstance(cstr, UniqueConstraint): |
|
319 |
constraints.remove(cstr) |
|
320 |
break |
|
321 |
else: |
|
322 |
self.fail('unique constraint not found') |
|
323 |
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
|
324 |
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
|
325 |
self.assertEqual(sizeconstraint.max, 64) |
0 | 326 |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
327 |
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
|
328 |
self.assertEqual(len(constraints), 1) |
0 | 329 |
cstr = constraints[0] |
330 |
self.assert_(isinstance(cstr, RQLConstraint)) |
|
7161
e3f69df8dac7
fix failing tests before 3.12 release
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7148
diff
changeset
|
331 |
self.assertEqual(cstr.expression, 'O final TRUE') |
0 | 332 |
|
333 |
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
|
334 |
self.assertEqual(ownedby.objects('CWEType'), ('CWUser',)) |
0 | 335 |
|
336 |
def test_pyro(self): |
|
337 |
import Pyro |
|
338 |
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
|
339 |
done = [] |
0 | 340 |
# the client part has to be in the thread due to sqlite limitations |
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
|
341 |
t = threading.Thread(target=self._pyro_client, args=(done,)) |
0 | 342 |
try: |
343 |
daemon = self.repo.pyro_register() |
|
344 |
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
|
345 |
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
|
346 |
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
|
347 |
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
|
348 |
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
|
349 |
self.fail('something went wrong, thread still alive') |
0 | 350 |
finally: |
351 |
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
|
352 |
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
|
353 |
pyro_ext._DAEMONS.clear() |
1787 | 354 |
|
5115
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
355 |
|
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
|
356 |
def _pyro_client(self, done): |
5115
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
357 |
cnx = connect(self.repo.config.appid, u'admin', password='gingkow', |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
358 |
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
|
359 |
try: |
5429
5ca1f8fe8a42
[dbapi] more test and documentation of dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
360 |
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
|
361 |
# 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
|
362 |
schema = cnx.get_schema() |
5429
5ca1f8fe8a42
[dbapi] more test and documentation of dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
363 |
self.failUnless(cnx.vreg) |
5ca1f8fe8a42
[dbapi] more test and documentation of dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
364 |
self.failUnless('etypes'in cnx.vreg) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6236
diff
changeset
|
365 |
self.assertEqual(schema.__hashmode__, None) |
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
|
366 |
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
|
367 |
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
|
368 |
user = iter(rset.entities()).next() |
5ca1f8fe8a42
[dbapi] more test and documentation of dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
369 |
self.failUnless(user._cw) |
5ca1f8fe8a42
[dbapi] more test and documentation of dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
370 |
self.failUnless(user._cw.vreg) |
5ca1f8fe8a42
[dbapi] more test and documentation of dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
371 |
from cubicweb.entities import authobjs |
5ca1f8fe8a42
[dbapi] more test and documentation of dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
372 |
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
|
373 |
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
|
374 |
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
|
375 |
finally: |
5115
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
376 |
# 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
|
377 |
multiple_connections_unfix() |
0 | 378 |
|
379 |
def test_internal_api(self): |
|
380 |
repo = self.repo |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
381 |
cnxid = repo.connect(self.admlogin, password=self.admpassword) |
0 | 382 |
session = repo._get_session(cnxid, setpool=True) |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6401
diff
changeset
|
383 |
self.assertEqual(repo.type_and_source_from_eid(2, session), |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6401
diff
changeset
|
384 |
('CWGroup', 'system', None)) |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6401
diff
changeset
|
385 |
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
|
386 |
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
|
387 |
self.assertEqual(repo.eid2extid(repo.system_source, 2, session), None) |
0 | 388 |
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
|
389 |
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
|
390 |
repo.close(cnxid) |
0 | 391 |
|
392 |
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
|
393 |
self.assertEqual(self.repo.get_schema(), self.repo.schema) |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6401
diff
changeset
|
394 |
self.assertEqual(self.repo.source_defs(), {'system': {'type': 'native', 'uri': 'system'}}) |
0 | 395 |
# .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
|
396 |
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 | 397 |
|
398 |
def test_session_api(self): |
|
399 |
repo = self.repo |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
400 |
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
|
401 |
self.assertEqual(repo.user_info(cnxid), (6, 'admin', set([u'managers']), {})) |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6401
diff
changeset
|
402 |
self.assertEqual(repo.describe(cnxid, 2), (u'CWGroup', u'system', None)) |
0 | 403 |
repo.close(cnxid) |
404 |
self.assertRaises(BadConnectionId, repo.user_info, cnxid) |
|
405 |
self.assertRaises(BadConnectionId, repo.describe, cnxid, 1) |
|
406 |
||
407 |
def test_shared_data_api(self): |
|
408 |
repo = self.repo |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
409 |
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
|
410 |
self.assertEqual(repo.get_shared_data(cnxid, 'data'), None) |
0 | 411 |
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
|
412 |
self.assertEqual(repo.get_shared_data(cnxid, 'data'), 4) |
0 | 413 |
repo.get_shared_data(cnxid, 'data', pop=True) |
414 |
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
|
415 |
self.assertEqual(repo.get_shared_data(cnxid, 'data'), None) |
0 | 416 |
repo.close(cnxid) |
417 |
self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid, 'data', 0) |
|
418 |
self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid, 'data') |
|
1787 | 419 |
|
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
|
420 |
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
|
421 |
no_is_rset = self.execute('Any X WHERE NOT X is ET') |
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
|
422 |
self.failIf(no_is_rset, no_is_rset.description) |
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
|
423 |
|
2642 | 424 |
# def test_perfo(self): |
425 |
# self.set_debug(True) |
|
426 |
# from time import time, clock |
|
427 |
# t, c = time(), clock() |
|
428 |
# try: |
|
429 |
# self.create_user('toto') |
|
430 |
# finally: |
|
431 |
# self.set_debug(False) |
|
432 |
# print 'test time: %.3f (time) %.3f (cpu)' % ((time() - t), clock() - c) |
|
433 |
||
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
|
434 |
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
|
435 |
note = self.request().create_entity('Affaire') |
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
436 |
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
|
437 |
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
|
438 |
{'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
|
439 |
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
|
440 |
{'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
|
441 |
self.assertEqual(len(rset), 1) |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
442 |
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
|
443 |
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
|
444 |
{'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
|
445 |
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
|
446 |
{'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
|
447 |
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
|
448 |
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
|
449 |
|
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
|
450 |
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
|
451 |
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
|
452 |
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
|
453 |
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
|
454 |
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
|
455 |
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
|
456 |
self.assertEqual(len(c.reverse_fiche), 1) |
0 | 457 |
|
5115
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
458 |
def test_set_attributes_in_before_update(self): |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
459 |
# local hook |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
460 |
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
|
461 |
__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
|
462 |
__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
|
463 |
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
|
464 |
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
|
465 |
# 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
|
466 |
# 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
|
467 |
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
|
468 |
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
|
469 |
pendings.add(self.entity.eid) |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
470 |
self.entity.set_attributes(alias=u'foo') |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
471 |
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
|
472 |
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
|
473 |
addr = req.create_entity('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
|
474 |
addr.set_attributes(address=u'a@b.com') |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
475 |
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
|
476 |
{'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
|
477 |
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
|
478 |
|
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
479 |
def test_set_attributes_in_before_add(self): |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
480 |
# local hook |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
481 |
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
|
482 |
__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
|
483 |
__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
|
484 |
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
|
485 |
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
|
486 |
# set_attributes is forbidden within 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
|
487 |
self.entity.set_attributes(alias=u'foo') |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
488 |
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
|
489 |
req = self.request() |
5126
c869d8e7d166
[test] fix expected error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
490 |
# XXX will fail with python -O |
c869d8e7d166
[test] fix expected error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
491 |
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
|
492 |
'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
|
493 |
|
5213
8604000bf3b2
[repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5126
diff
changeset
|
494 |
def test_multiple_edit_set_attributes(self): |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6030
diff
changeset
|
495 |
"""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
|
496 |
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
|
497 |
""" |
8604000bf3b2
[repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5126
diff
changeset
|
498 |
# local hook |
8604000bf3b2
[repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5126
diff
changeset
|
499 |
class DummyBeforeHook(Hook): |
8604000bf3b2
[repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5126
diff
changeset
|
500 |
_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
|
501 |
__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
|
502 |
__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
|
503 |
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
|
504 |
def __call__(self): |
8604000bf3b2
[repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5126
diff
changeset
|
505 |
# invoiced attribute shouldn't be considered "edited" before the hook |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6030
diff
changeset
|
506 |
self._test.failIf('invoiced' in self.entity.cw_edited, |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6030
diff
changeset
|
507 |
'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
|
508 |
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
|
509 |
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
|
510 |
req = self.request() |
8604000bf3b2
[repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5126
diff
changeset
|
511 |
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
|
512 |
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
|
513 |
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
|
514 |
|
5115
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
515 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
516 |
class DataHelpersTC(CubicWebTC): |
1787 | 517 |
|
0 | 518 |
def test_create_eid(self): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
519 |
self.session.set_pool() |
0 | 520 |
self.assert_(self.repo.system_source.create_eid(self.session)) |
521 |
||
522 |
def test_source_from_eid(self): |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
523 |
self.session.set_pool() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6236
diff
changeset
|
524 |
self.assertEqual(self.repo.source_from_eid(1, self.session), |
0 | 525 |
self.repo.sources_by_uri['system']) |
526 |
||
527 |
def test_source_from_eid_raise(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
|
528 |
self.session.set_pool() |
0 | 529 |
self.assertRaises(UnknownEid, self.repo.source_from_eid, -2, self.session) |
530 |
||
531 |
def test_type_from_eid(self): |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
532 |
self.session.set_pool() |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6401
diff
changeset
|
533 |
self.assertEqual(self.repo.type_from_eid(2, self.session), 'CWGroup') |
1787 | 534 |
|
0 | 535 |
def test_type_from_eid_raise(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
|
536 |
self.session.set_pool() |
0 | 537 |
self.assertRaises(UnknownEid, self.repo.type_from_eid, -2, self.session) |
1787 | 538 |
|
0 | 539 |
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
|
540 |
entity = self.repo.vreg['etypes'].etype_class('Personne')(self.session) |
0 | 541 |
entity.eid = -1 |
542 |
entity.complete = lambda x: None |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
543 |
self.session.set_pool() |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4835
diff
changeset
|
544 |
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
|
545 |
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
|
546 |
data = cu.fetchall() |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
17
diff
changeset
|
547 |
self.assertIsInstance(data[0][3], datetime) |
0 | 548 |
data[0] = list(data[0]) |
549 |
data[0][3] = None |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6236
diff
changeset
|
550 |
self.assertEqual(tuplify(data), [(-1, 'Personne', 'system', None, None)]) |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4835
diff
changeset
|
551 |
self.repo.delete_info(self.session, entity, 'system', None) |
0 | 552 |
#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
|
553 |
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
|
554 |
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
|
555 |
self.assertEqual(data, []) |
0 | 556 |
|
557 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
558 |
class FTITC(CubicWebTC): |
1787 | 559 |
|
0 | 560 |
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
|
561 |
self.repo.system_source.multisources_etypes.add('Personne') |
0 | 562 |
eidp = self.execute('INSERT Personne X: X nom "toto", X prenom "tutu"')[0][0] |
563 |
self.commit() |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
17
diff
changeset
|
564 |
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
|
565 |
self.assertEqual(len(self.execute('Personne X WHERE X has_text "tutu"')), 1) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
566 |
self.session.set_pool() |
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
|
567 |
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
|
568 |
omtime = cu.fetchone()[0] |
0 | 569 |
# our sqlite datetime adapter is ignore seconds fraction, so we have to |
570 |
# ensure update is done the next seconds |
|
571 |
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
|
572 |
self.execute('SET X nom "tata" WHERE X eid %(x)s', {'x': eidp}) |
0 | 573 |
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
|
574 |
self.assertEqual(len(self.execute('Personne X WHERE X has_text "tutu"')), 1) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
575 |
self.session.set_pool() |
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
|
576 |
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
|
577 |
mtime = cu.fetchone()[0] |
0 | 578 |
self.failUnless(omtime < mtime) |
579 |
self.commit() |
|
580 |
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
|
581 |
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
|
582 |
self.assertEqual(deleted, []) |
0 | 583 |
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
|
584 |
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
|
585 |
self.assertEqual(deleted, []) |
0 | 586 |
self.execute('DELETE Personne X WHERE X eid %(x)s', {'x': eidp}) |
587 |
self.commit() |
|
588 |
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
|
589 |
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
|
590 |
self.assertEqual(deleted, [('Personne', eidp)]) |
0 | 591 |
|
4806
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
592 |
def test_fulltext_container_entity(self): |
0 | 593 |
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
|
594 |
req = self.request() |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
595 |
toto = req.create_entity('EmailAddress', address=u'toto@logilab.fr') |
0 | 596 |
self.commit() |
4806
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
597 |
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
|
598 |
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
|
599 |
req.user.set_relations(use_email=toto) |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
600 |
self.commit() |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
601 |
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
|
602 |
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
|
603 |
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
|
604 |
{'y': toto.eid}) |
0 | 605 |
self.commit() |
4806
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
606 |
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
|
607 |
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
|
608 |
tutu = req.create_entity('EmailAddress', address=u'tutu@logilab.fr') |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
609 |
req.user.set_relations(use_email=tutu) |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
610 |
self.commit() |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
611 |
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
|
612 |
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
|
613 |
tutu.set_attributes(address=u'hip@logilab.fr') |
0 | 614 |
self.commit() |
4806
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
615 |
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
|
616 |
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
|
617 |
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
|
618 |
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
|
619 |
|
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
620 |
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
|
621 |
req = self.request() |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
622 |
req.create_entity('Workflow', name=u'dummy workflow', description=u'huuuuu') |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
623 |
self.failIf(any(x for x in self.session.pending_operations |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
624 |
if isinstance(x, native.FTIndexEntityOp))) |
1787 | 625 |
|
626 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
627 |
class DBInitTC(CubicWebTC): |
1787 | 628 |
|
0 | 629 |
def test_versions_inserted(self): |
630 |
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
|
631 |
self.assertEqual(inserted, |
1787 | 632 |
[u'system.version.basket', u'system.version.card', u'system.version.comment', |
633 |
u'system.version.cubicweb', u'system.version.email', |
|
634 |
u'system.version.file', u'system.version.folder', |
|
17
62ce3e6126e0
work in progress: fix cubicweb/server tests
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
635 |
u'system.version.tag']) |
1787 | 636 |
|
3445
32492e9e734b
update and simplify test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
637 |
CALLED = [] |
32492e9e734b
update and simplify test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
638 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
639 |
class InlineRelHooksTC(CubicWebTC): |
0 | 640 |
"""test relation hooks are called for inlined relations |
641 |
""" |
|
642 |
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
|
643 |
CubicWebTC.setUp(self) |
3445
32492e9e734b
update and simplify test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
644 |
CALLED[:] = () |
0 | 645 |
|
646 |
def _after_relation_hook(self, pool, fromeid, rtype, toeid): |
|
647 |
self.called.append((fromeid, rtype, toeid)) |
|
1787 | 648 |
|
3445
32492e9e734b
update and simplify test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
649 |
def test_inline_relation(self): |
32492e9e734b
update and simplify test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
650 |
"""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
|
651 |
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
|
652 |
__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
|
653 |
__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
|
654 |
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
|
655 |
'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
|
656 |
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
|
657 |
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
|
658 |
|
5105
57e0fc953676
[test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5103
diff
changeset
|
659 |
with self.temporary_appobjects(EcritParHook): |
57e0fc953676
[test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5103
diff
changeset
|
660 |
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
|
661 |
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
|
662 |
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
|
663 |
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
|
664 |
('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
|
665 |
CALLED[:] = () |
57e0fc953676
[test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5103
diff
changeset
|
666 |
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
|
667 |
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
|
668 |
('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
|
669 |
CALLED[:] = () |
57e0fc953676
[test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5103
diff
changeset
|
670 |
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
|
671 |
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
|
672 |
('after_add_relation', eidn, 'ecrit_par', eidp)]) |
0 | 673 |
|
6236
9138f23ee263
[repo tests] add test case for RQLUniqueConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
674 |
def test_unique_contraint(self): |
9138f23ee263
[repo tests] add test case for RQLUniqueConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
675 |
req = self.request() |
9138f23ee263
[repo tests] add test case for RQLUniqueConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
676 |
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
|
677 |
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
|
678 |
req.cnx.commit() |
9138f23ee263
[repo tests] add test case for RQLUniqueConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
679 |
req = self.request() |
9138f23ee263
[repo tests] add test case for RQLUniqueConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
680 |
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
|
681 |
req.cnx.commit() |
9138f23ee263
[repo tests] add test case for RQLUniqueConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
682 |
req = self.request() |
9138f23ee263
[repo tests] add test case for RQLUniqueConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6208
diff
changeset
|
683 |
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
|
684 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
685 |
req.cnx.commit() |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
686 |
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 | 687 |
|
7236
b91205ada414
added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7194
diff
changeset
|
688 |
|
b91205ada414
added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7194
diff
changeset
|
689 |
|
b91205ada414
added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7194
diff
changeset
|
690 |
class PerformanceTest(CubicWebTC): |
b91205ada414
added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7194
diff
changeset
|
691 |
def setup_database(self): |
b91205ada414
added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7194
diff
changeset
|
692 |
import logging |
b91205ada414
added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7194
diff
changeset
|
693 |
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
|
694 |
#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
|
695 |
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
|
696 |
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
|
697 |
|
b91205ada414
added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7194
diff
changeset
|
698 |
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
|
699 |
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
|
700 |
personnes = [] |
b91205ada414
added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7194
diff
changeset
|
701 |
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
|
702 |
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
|
703 |
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
|
704 |
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
|
705 |
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
|
706 |
for j in xrange(0, 2000, 100): |
b91205ada414
added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7194
diff
changeset
|
707 |
abraham.set_relations(personne_composite=personnes[j:j+100]) |
b91205ada414
added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7194
diff
changeset
|
708 |
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
|
709 |
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
|
710 |
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
|
711 |
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
|
712 |
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
|
713 |
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
|
714 |
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
|
715 |
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
|
716 |
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
|
717 |
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
|
718 |
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
|
719 |
|
b91205ada414
added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7194
diff
changeset
|
720 |
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
|
721 |
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
|
722 |
personnes = [] |
b91205ada414
added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7194
diff
changeset
|
723 |
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
|
724 |
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
|
725 |
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
|
726 |
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
|
727 |
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
|
728 |
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
|
729 |
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
|
730 |
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
|
731 |
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
|
732 |
for j in xrange(100, 2000, 100): |
b91205ada414
added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7194
diff
changeset
|
733 |
abraham.set_relations(personne_composite=personnes[j:j+100]) |
b91205ada414
added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7194
diff
changeset
|
734 |
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
|
735 |
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
|
736 |
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
|
737 |
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
|
738 |
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
|
739 |
|
b91205ada414
added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7194
diff
changeset
|
740 |
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
|
741 |
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
|
742 |
personnes = [] |
b91205ada414
added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7194
diff
changeset
|
743 |
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
|
744 |
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
|
745 |
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
|
746 |
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
|
747 |
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
|
748 |
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
|
749 |
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
|
750 |
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
|
751 |
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
|
752 |
for j in xrange(100, 2000, 100): |
b91205ada414
added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7194
diff
changeset
|
753 |
abraham.set_relations(personne_inlined=personnes[j:j+100]) |
b91205ada414
added test case to monitor speed improvements in the repository code.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7194
diff
changeset
|
754 |
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
|
755 |
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
|
756 |
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
|
757 |
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
|
758 |
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
|
759 |
|
0 | 760 |
if __name__ == '__main__': |
761 |
unittest_main() |