author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Fri, 02 Jul 2010 18:56:05 +0200 | |
changeset 5874 | 6afc88f439e8 |
parent 5717 | 3c281b6f16c6 |
child 5877 | 0c7b7b76a84f |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: iso-8859-1 -*- |
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
|
2 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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/>. |
5717
3c281b6f16c6
[3.9] fix tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
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, |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
35 |
UnknownEid, AuthenticationError) |
5115
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
36 |
from cubicweb.selectors import implements |
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)) |
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
|
68 |
self.assertEquals(cu.fetchall(), []) |
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'}) |
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
|
71 |
self.assertEquals(cu.fetchall(), [(u'Boolean',), (u'Bytes',), |
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
|
72 |
(u'Date',), (u'Datetime',), |
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
|
73 |
(u'Decimal',),(u'Float',), |
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
|
74 |
(u'Int',), |
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
|
75 |
(u'Interval',), (u'Password',), |
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
|
76 |
(u'String',), (u'Time',)]) |
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
|
77 |
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
|
78 |
self.repo.set_schema(origshema) |
1787 | 79 |
|
0 | 80 |
def test_schema_has_owner(self): |
81 |
repo = self.repo |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
82 |
cnxid = repo.connect(self.admlogin, password=self.admpassword) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
83 |
self.failIf(repo.execute(cnxid, 'CWEType X WHERE NOT X owned_by U')) |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
84 |
self.failIf(repo.execute(cnxid, 'CWRType X WHERE NOT X owned_by U')) |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
85 |
self.failIf(repo.execute(cnxid, 'CWAttribute X WHERE NOT X owned_by U')) |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
86 |
self.failIf(repo.execute(cnxid, 'CWRelation X WHERE NOT X owned_by U')) |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
87 |
self.failIf(repo.execute(cnxid, 'CWConstraint X WHERE NOT X owned_by U')) |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
88 |
self.failIf(repo.execute(cnxid, 'CWConstraintType X WHERE NOT X owned_by U')) |
1787 | 89 |
|
0 | 90 |
def test_connect(self): |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
91 |
self.assert_(self.repo.connect(self.admlogin, password=self.admpassword)) |
0 | 92 |
self.assertRaises(AuthenticationError, |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
93 |
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
|
94 |
self.assertRaises(AuthenticationError, |
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
95 |
self.repo.connect, self.admlogin, password=None) |
0 | 96 |
self.assertRaises(AuthenticationError, |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
97 |
self.repo.connect, None, password=None) |
0 | 98 |
self.assertRaises(AuthenticationError, |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
99 |
self.repo.connect, self.admlogin) |
0 | 100 |
self.assertRaises(AuthenticationError, |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
101 |
self.repo.connect, None) |
1787 | 102 |
|
0 | 103 |
def test_execute(self): |
104 |
repo = self.repo |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
105 |
cnxid = repo.connect(self.admlogin, password=self.admpassword) |
0 | 106 |
repo.execute(cnxid, 'Any X') |
107 |
repo.execute(cnxid, 'Any X where X is Personne') |
|
108 |
repo.execute(cnxid, 'Any X where X is Personne, X nom ~= "to"') |
|
109 |
repo.execute(cnxid, 'Any X WHERE X has_text %(text)s', {'text': u'\xe7a'}) |
|
110 |
repo.close(cnxid) |
|
1787 | 111 |
|
0 | 112 |
def test_login_upassword_accent(self): |
113 |
repo = self.repo |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
114 |
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
|
115 |
repo.execute(cnxid, 'INSERT CWUser X: X login %(login)s, X upassword %(passwd)s, X in_group G WHERE G name "users"', |
0 | 116 |
{'login': u"barnab�", 'passwd': u"h�h�h�".encode('UTF8')}) |
117 |
repo.commit(cnxid) |
|
118 |
repo.close(cnxid) |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
119 |
self.assert_(repo.connect(u"barnab�", password=u"h�h�h�".encode('UTF8'))) |
1787 | 120 |
|
0 | 121 |
def test_invalid_entity_rollback(self): |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
122 |
cnxid = self.repo.connect(self.admlogin, password=self.admpassword) |
1787 | 123 |
# no group |
3771 | 124 |
self.repo.execute(cnxid, |
125 |
'INSERT CWUser X: X login %(login)s, X upassword %(passwd)s', |
|
126 |
{'login': u"tutetute", 'passwd': 'tutetute'}) |
|
127 |
self.assertRaises(ValidationError, self.repo.commit, cnxid) |
|
128 |
self.failIf(self.repo.execute(cnxid, 'CWUser X WHERE X login "tutetute"')) |
|
1787 | 129 |
|
0 | 130 |
def test_close(self): |
131 |
repo = self.repo |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
132 |
cnxid = repo.connect(self.admlogin, password=self.admpassword) |
0 | 133 |
self.assert_(cnxid) |
134 |
repo.close(cnxid) |
|
135 |
self.assertRaises(BadConnectionId, repo.execute, cnxid, 'Any X') |
|
1787 | 136 |
|
0 | 137 |
def test_invalid_cnxid(self): |
138 |
self.assertRaises(BadConnectionId, self.repo.execute, 0, 'Any X') |
|
139 |
self.assertRaises(BadConnectionId, self.repo.close, None) |
|
1787 | 140 |
|
0 | 141 |
def test_shared_data(self): |
142 |
repo = self.repo |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
143 |
cnxid = repo.connect(self.admlogin, password=self.admpassword) |
0 | 144 |
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
|
145 |
cnxid2 = repo.connect(self.admlogin, password=self.admpassword) |
0 | 146 |
self.assertEquals(repo.get_shared_data(cnxid, 'data'), 4) |
147 |
self.assertEquals(repo.get_shared_data(cnxid2, 'data'), None) |
|
148 |
repo.set_shared_data(cnxid2, 'data', 5) |
|
149 |
self.assertEquals(repo.get_shared_data(cnxid, 'data'), 4) |
|
150 |
self.assertEquals(repo.get_shared_data(cnxid2, 'data'), 5) |
|
151 |
repo.get_shared_data(cnxid2, 'data', pop=True) |
|
152 |
self.assertEquals(repo.get_shared_data(cnxid, 'data'), 4) |
|
153 |
self.assertEquals(repo.get_shared_data(cnxid2, 'data'), None) |
|
154 |
repo.close(cnxid) |
|
155 |
repo.close(cnxid2) |
|
156 |
self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid, 'data') |
|
157 |
self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid2, 'data') |
|
158 |
self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid, 'data', 1) |
|
159 |
self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid2, 'data', 1) |
|
160 |
||
161 |
def test_check_session(self): |
|
162 |
repo = self.repo |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
163 |
cnxid = repo.connect(self.admlogin, password=self.admpassword) |
0 | 164 |
self.assertEquals(repo.check_session(cnxid), None) |
165 |
repo.close(cnxid) |
|
166 |
self.assertRaises(BadConnectionId, repo.check_session, cnxid) |
|
167 |
||
168 |
def test_transaction_base(self): |
|
169 |
repo = self.repo |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
170 |
cnxid = repo.connect(self.admlogin, password=self.admpassword) |
0 | 171 |
# check db state |
172 |
result = repo.execute(cnxid, 'Personne X') |
|
173 |
self.assertEquals(result.rowcount, 0) |
|
174 |
# rollback entity insertion |
|
175 |
repo.execute(cnxid, "INSERT Personne X: X nom 'bidule'") |
|
176 |
result = repo.execute(cnxid, 'Personne X') |
|
177 |
self.assertEquals(result.rowcount, 1) |
|
178 |
repo.rollback(cnxid) |
|
179 |
result = repo.execute(cnxid, 'Personne X') |
|
180 |
self.assertEquals(result.rowcount, 0, result.rows) |
|
181 |
# commit |
|
182 |
repo.execute(cnxid, "INSERT Personne X: X nom 'bidule'") |
|
183 |
repo.commit(cnxid) |
|
184 |
result = repo.execute(cnxid, 'Personne X') |
|
185 |
self.assertEquals(result.rowcount, 1) |
|
186 |
||
187 |
def test_transaction_base2(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 |
# rollback relation insertion |
191 |
repo.execute(cnxid, "SET U in_group G WHERE U login 'admin', G name 'guests'") |
|
192 |
result = repo.execute(cnxid, "Any U WHERE U in_group G, U login 'admin', G name 'guests'") |
|
193 |
self.assertEquals(result.rowcount, 1) |
|
194 |
repo.rollback(cnxid) |
|
195 |
result = repo.execute(cnxid, "Any U WHERE U in_group G, U login 'admin', G name 'guests'") |
|
196 |
self.assertEquals(result.rowcount, 0, result.rows) |
|
1787 | 197 |
|
0 | 198 |
def test_transaction_base3(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 |
# 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
|
202 |
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
|
203 |
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
|
204 |
user = session.user |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5429
diff
changeset
|
205 |
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
|
206 |
rset = repo.execute(cnxid, 'TrInfo T WHERE T wf_info_for X, X eid %(x)s', {'x': user.eid}) |
0 | 207 |
self.assertEquals(len(rset), 1) |
208 |
repo.rollback(cnxid) |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
209 |
rset = repo.execute(cnxid, 'TrInfo T WHERE T wf_info_for X, X eid %(x)s', {'x': user.eid}) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
210 |
self.assertEquals(len(rset), 0) |
1787 | 211 |
|
0 | 212 |
def test_transaction_interleaved(self): |
213 |
self.skip('implement me') |
|
214 |
||
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
|
215 |
def test_close_wait_processing_request(self): |
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
|
216 |
repo = self.repo |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
217 |
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
|
218 |
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
|
219 |
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
|
220 |
# 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
|
221 |
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
|
222 |
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
|
223 |
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
|
224 |
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
|
225 |
t.start() |
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
|
226 |
try: |
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
|
227 |
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
|
228 |
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
|
229 |
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
|
230 |
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
|
231 |
|
0 | 232 |
def test_initial_schema(self): |
233 |
schema = self.repo.schema |
|
234 |
# check order of attributes is respected |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
235 |
self.assertListEquals([r.type for r in schema.eschema('CWAttribute').ordered_relations() |
1787 | 236 |
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
|
237 |
'creation_date', 'modification_date', 'cwuri', |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
238 |
'owned_by', 'created_by', |
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
|
239 |
'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
|
240 |
'in_basket')], |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
241 |
['relation_type', |
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
242 |
'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
|
243 |
'constrained_by', |
1787 | 244 |
'cardinality', 'ordernum', |
0 | 245 |
'indexed', 'fulltextindexed', 'internationalizable', |
5717
3c281b6f16c6
[3.9] fix tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5590
diff
changeset
|
246 |
'defaultval', 'description', 'description_format']) |
0 | 247 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
248 |
self.assertEquals(schema.eschema('CWEType').main_attribute(), 'name') |
0 | 249 |
self.assertEquals(schema.eschema('State').main_attribute(), 'name') |
250 |
||
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
251 |
constraints = schema.rschema('name').rdef('CWEType', 'String').constraints |
0 | 252 |
self.assertEquals(len(constraints), 2) |
253 |
for cstr in constraints[:]: |
|
254 |
if isinstance(cstr, UniqueConstraint): |
|
255 |
constraints.remove(cstr) |
|
256 |
break |
|
257 |
else: |
|
258 |
self.fail('unique constraint not found') |
|
259 |
sizeconstraint = constraints[0] |
|
260 |
self.assertEquals(sizeconstraint.min, None) |
|
261 |
self.assertEquals(sizeconstraint.max, 64) |
|
262 |
||
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
263 |
constraints = schema.rschema('relation_type').rdef('CWAttribute', 'CWRType').constraints |
0 | 264 |
self.assertEquals(len(constraints), 1) |
265 |
cstr = constraints[0] |
|
266 |
self.assert_(isinstance(cstr, RQLConstraint)) |
|
267 |
self.assertEquals(cstr.restriction, 'O final TRUE') |
|
268 |
||
269 |
ownedby = schema.rschema('owned_by') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
270 |
self.assertEquals(ownedby.objects('CWEType'), ('CWUser',)) |
0 | 271 |
|
272 |
def test_pyro(self): |
|
273 |
import Pyro |
|
274 |
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
|
275 |
done = [] |
0 | 276 |
# 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
|
277 |
t = threading.Thread(target=self._pyro_client, args=(done,)) |
0 | 278 |
try: |
279 |
daemon = self.repo.pyro_register() |
|
280 |
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
|
281 |
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
|
282 |
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
|
283 |
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
|
284 |
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
|
285 |
self.fail('something went wrong, thread still alive') |
0 | 286 |
finally: |
287 |
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
|
288 |
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
|
289 |
pyro_ext._DAEMONS.clear() |
1787 | 290 |
|
5115
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
291 |
|
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
|
292 |
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
|
293 |
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
|
294 |
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
|
295 |
try: |
5429
5ca1f8fe8a42
[dbapi] more test and documentation of dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
296 |
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
|
297 |
# 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
|
298 |
schema = cnx.get_schema() |
5429
5ca1f8fe8a42
[dbapi] more test and documentation of dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
299 |
self.failUnless(cnx.vreg) |
5ca1f8fe8a42
[dbapi] more test and documentation of dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
300 |
self.failUnless('etypes'in cnx.vreg) |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2642
diff
changeset
|
301 |
self.assertEquals(schema.__hashmode__, None) |
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
|
302 |
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
|
303 |
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
|
304 |
user = iter(rset.entities()).next() |
5ca1f8fe8a42
[dbapi] more test and documentation of dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
305 |
self.failUnless(user._cw) |
5ca1f8fe8a42
[dbapi] more test and documentation of dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
306 |
self.failUnless(user._cw.vreg) |
5ca1f8fe8a42
[dbapi] more test and documentation of dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
307 |
from cubicweb.entities import authobjs |
5ca1f8fe8a42
[dbapi] more test and documentation of dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
308 |
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
|
309 |
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
|
310 |
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
|
311 |
finally: |
5115
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
312 |
# 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
|
313 |
multiple_connections_unfix() |
0 | 314 |
|
315 |
def test_internal_api(self): |
|
316 |
repo = self.repo |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
317 |
cnxid = repo.connect(self.admlogin, password=self.admpassword) |
0 | 318 |
session = repo._get_session(cnxid, setpool=True) |
1954 | 319 |
self.assertEquals(repo.type_and_source_from_eid(1, session), |
320 |
('CWGroup', 'system', None)) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
321 |
self.assertEquals(repo.type_from_eid(1, session), 'CWGroup') |
0 | 322 |
self.assertEquals(repo.source_from_eid(1, session).uri, 'system') |
323 |
self.assertEquals(repo.eid2extid(repo.system_source, 1, session), None) |
|
324 |
class dummysource: uri = 'toto' |
|
325 |
self.assertRaises(UnknownEid, repo.eid2extid, dummysource, 1, session) |
|
326 |
||
327 |
def test_public_api(self): |
|
328 |
self.assertEquals(self.repo.get_schema(), self.repo.schema) |
|
329 |
self.assertEquals(self.repo.source_defs(), {'system': {'adapter': 'native', 'uri': 'system'}}) |
|
330 |
# .properties() return a result set |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
331 |
self.assertEquals(self.repo.properties().rql, 'Any K,V WHERE P is CWProperty,P pkey K, P value V, NOT P for_user U') |
0 | 332 |
|
333 |
def test_session_api(self): |
|
334 |
repo = self.repo |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
335 |
cnxid = repo.connect(self.admlogin, password=self.admpassword) |
0 | 336 |
self.assertEquals(repo.user_info(cnxid), (5, 'admin', set([u'managers']), {})) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
337 |
self.assertEquals(repo.describe(cnxid, 1), (u'CWGroup', u'system', None)) |
0 | 338 |
repo.close(cnxid) |
339 |
self.assertRaises(BadConnectionId, repo.user_info, cnxid) |
|
340 |
self.assertRaises(BadConnectionId, repo.describe, cnxid, 1) |
|
341 |
||
342 |
def test_shared_data_api(self): |
|
343 |
repo = self.repo |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
344 |
cnxid = repo.connect(self.admlogin, password=self.admpassword) |
0 | 345 |
self.assertEquals(repo.get_shared_data(cnxid, 'data'), None) |
346 |
repo.set_shared_data(cnxid, 'data', 4) |
|
347 |
self.assertEquals(repo.get_shared_data(cnxid, 'data'), 4) |
|
348 |
repo.get_shared_data(cnxid, 'data', pop=True) |
|
349 |
repo.get_shared_data(cnxid, 'whatever', pop=True) |
|
350 |
self.assertEquals(repo.get_shared_data(cnxid, 'data'), None) |
|
351 |
repo.close(cnxid) |
|
352 |
self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid, 'data', 0) |
|
353 |
self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid, 'data') |
|
1787 | 354 |
|
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
|
355 |
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
|
356 |
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
|
357 |
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
|
358 |
|
2642 | 359 |
# def test_perfo(self): |
360 |
# self.set_debug(True) |
|
361 |
# from time import time, clock |
|
362 |
# t, c = time(), clock() |
|
363 |
# try: |
|
364 |
# self.create_user('toto') |
|
365 |
# finally: |
|
366 |
# self.set_debug(False) |
|
367 |
# print 'test time: %.3f (time) %.3f (cpu)' % ((time() - t), clock() - c) |
|
368 |
||
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
|
369 |
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
|
370 |
note = self.request().create_entity('Affaire') |
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
371 |
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
|
372 |
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
|
373 |
{'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
|
374 |
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
|
375 |
{'x': note.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
|
376 |
self.assertEquals(len(rset), 1) |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
377 |
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
|
378 |
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
|
379 |
{'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
|
380 |
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
|
381 |
{'x': note.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
|
382 |
self.assertEquals(len(rset), 1) |
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
|
383 |
self.assertEquals(rset.rows[0][0], 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
|
384 |
|
0 | 385 |
|
5115
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
386 |
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
|
387 |
# local hook |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
388 |
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
|
389 |
__regid__ = 'dummy-before-hook' |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
390 |
__select__ = Hook.__select__ & implements('EmailAddress') |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
391 |
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
|
392 |
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
|
393 |
# 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
|
394 |
# 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
|
395 |
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
|
396 |
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
|
397 |
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
|
398 |
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
|
399 |
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
|
400 |
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
|
401 |
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
|
402 |
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
|
403 |
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
|
404 |
{'x': addr.eid}) |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
405 |
self.assertEquals(rset.rows, [[u'a@b.com', u'foo']]) |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
406 |
|
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
407 |
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
|
408 |
# local hook |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
409 |
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
|
410 |
__regid__ = 'dummy-before-hook' |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
411 |
__select__ = Hook.__select__ & implements('EmailAddress') |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
412 |
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
|
413 |
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
|
414 |
# 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
|
415 |
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
|
416 |
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
|
417 |
req = self.request() |
5126
c869d8e7d166
[test] fix expected error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
418 |
# XXX will fail with python -O |
c869d8e7d166
[test] fix expected error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
419 |
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
|
420 |
'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
|
421 |
|
5213
8604000bf3b2
[repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5126
diff
changeset
|
422 |
def test_multiple_edit_set_attributes(self): |
8604000bf3b2
[repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5126
diff
changeset
|
423 |
"""make sure edited_attributes doesn't get cluttered |
8604000bf3b2
[repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5126
diff
changeset
|
424 |
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
|
425 |
""" |
8604000bf3b2
[repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5126
diff
changeset
|
426 |
# local hook |
8604000bf3b2
[repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5126
diff
changeset
|
427 |
class DummyBeforeHook(Hook): |
8604000bf3b2
[repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5126
diff
changeset
|
428 |
_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
|
429 |
__regid__ = 'dummy-before-hook' |
8604000bf3b2
[repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5126
diff
changeset
|
430 |
__select__ = Hook.__select__ & implements('Affaire') |
8604000bf3b2
[repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5126
diff
changeset
|
431 |
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
|
432 |
def __call__(self): |
8604000bf3b2
[repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5126
diff
changeset
|
433 |
# invoiced attribute shouldn't be considered "edited" before the hook |
8604000bf3b2
[repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5126
diff
changeset
|
434 |
self._test.failIf('invoiced' in self.entity.edited_attributes, |
8604000bf3b2
[repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5126
diff
changeset
|
435 |
'edited_attributes cluttered by previous update') |
8604000bf3b2
[repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5126
diff
changeset
|
436 |
self.entity['invoiced'] = 10 |
8604000bf3b2
[repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5126
diff
changeset
|
437 |
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
|
438 |
req = self.request() |
8604000bf3b2
[repository] fix edited_attributes management in multiple SET queries
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5126
diff
changeset
|
439 |
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
|
440 |
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
|
441 |
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
|
442 |
|
5115
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5106
diff
changeset
|
443 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
444 |
class DataHelpersTC(CubicWebTC): |
1787 | 445 |
|
0 | 446 |
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
|
447 |
self.session.set_pool() |
0 | 448 |
self.assert_(self.repo.system_source.create_eid(self.session)) |
449 |
||
450 |
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
|
451 |
self.session.set_pool() |
0 | 452 |
self.assertEquals(self.repo.source_from_eid(1, self.session), |
453 |
self.repo.sources_by_uri['system']) |
|
454 |
||
455 |
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
|
456 |
self.session.set_pool() |
0 | 457 |
self.assertRaises(UnknownEid, self.repo.source_from_eid, -2, self.session) |
458 |
||
459 |
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
|
460 |
self.session.set_pool() |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
461 |
self.assertEquals(self.repo.type_from_eid(1, self.session), 'CWGroup') |
1787 | 462 |
|
0 | 463 |
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
|
464 |
self.session.set_pool() |
0 | 465 |
self.assertRaises(UnknownEid, self.repo.type_from_eid, -2, self.session) |
1787 | 466 |
|
0 | 467 |
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
|
468 |
entity = self.repo.vreg['etypes'].etype_class('Personne')(self.session) |
0 | 469 |
entity.eid = -1 |
470 |
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
|
471 |
self.session.set_pool() |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4835
diff
changeset
|
472 |
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
|
473 |
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
|
474 |
data = cu.fetchall() |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
17
diff
changeset
|
475 |
self.assertIsInstance(data[0][3], datetime) |
0 | 476 |
data[0] = list(data[0]) |
477 |
data[0][3] = None |
|
478 |
self.assertEquals(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
|
479 |
self.repo.delete_info(self.session, entity, 'system', None) |
0 | 480 |
#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
|
481 |
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
|
482 |
data = cu.fetchall() |
0 | 483 |
self.assertEquals(data, []) |
484 |
||
485 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
486 |
class FTITC(CubicWebTC): |
1787 | 487 |
|
0 | 488 |
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
|
489 |
self.repo.system_source.multisources_etypes.add('Personne') |
0 | 490 |
eidp = self.execute('INSERT Personne X: X nom "toto", X prenom "tutu"')[0][0] |
491 |
self.commit() |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
17
diff
changeset
|
492 |
ts = datetime.now() |
0 | 493 |
self.assertEquals(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
|
494 |
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
|
495 |
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
|
496 |
omtime = cu.fetchone()[0] |
0 | 497 |
# our sqlite datetime adapter is ignore seconds fraction, so we have to |
498 |
# ensure update is done the next seconds |
|
499 |
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
|
500 |
self.execute('SET X nom "tata" WHERE X eid %(x)s', {'x': eidp}) |
0 | 501 |
self.commit() |
502 |
self.assertEquals(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
|
503 |
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
|
504 |
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
|
505 |
mtime = cu.fetchone()[0] |
0 | 506 |
self.failUnless(omtime < mtime) |
507 |
self.commit() |
|
508 |
date, modified, deleted = self.repo.entities_modified_since(('Personne',), omtime) |
|
509 |
self.assertEquals(modified, [('Personne', eidp)]) |
|
510 |
self.assertEquals(deleted, []) |
|
511 |
date, modified, deleted = self.repo.entities_modified_since(('Personne',), mtime) |
|
512 |
self.assertEquals(modified, []) |
|
513 |
self.assertEquals(deleted, []) |
|
514 |
self.execute('DELETE Personne X WHERE X eid %(x)s', {'x': eidp}) |
|
515 |
self.commit() |
|
516 |
date, modified, deleted = self.repo.entities_modified_since(('Personne',), omtime) |
|
517 |
self.assertEquals(modified, []) |
|
518 |
self.assertEquals(deleted, [('Personne', eidp)]) |
|
519 |
||
4806
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
520 |
def test_fulltext_container_entity(self): |
0 | 521 |
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
|
522 |
req = self.request() |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
523 |
toto = req.create_entity('EmailAddress', address=u'toto@logilab.fr') |
0 | 524 |
self.commit() |
4806
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
525 |
rset = req.execute('Any X WHERE X has_text %(t)s', {'t': 'toto'}) |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
526 |
self.assertEquals(rset.rows, []) |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
527 |
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
|
528 |
self.commit() |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
529 |
rset = req.execute('Any X WHERE X has_text %(t)s', {'t': 'toto'}) |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
530 |
self.assertEquals(rset.rows, [[req.user.eid]]) |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
531 |
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
|
532 |
{'y': toto.eid}) |
0 | 533 |
self.commit() |
4806
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
534 |
rset = req.execute('Any X WHERE X has_text %(t)s', {'t': 'toto'}) |
0 | 535 |
self.assertEquals(rset.rows, []) |
4806
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
536 |
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
|
537 |
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
|
538 |
self.commit() |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
539 |
rset = req.execute('Any X WHERE X has_text %(t)s', {'t': 'tutu'}) |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
540 |
self.assertEquals(rset.rows, [[req.user.eid]]) |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
541 |
tutu.set_attributes(address=u'hip@logilab.fr') |
0 | 542 |
self.commit() |
4806
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
543 |
rset = req.execute('Any X WHERE X has_text %(t)s', {'t': 'tutu'}) |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
544 |
self.assertEquals(rset.rows, []) |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
545 |
rset = req.execute('Any X WHERE X has_text %(t)s', {'t': 'hip'}) |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
546 |
self.assertEquals(rset.rows, [[req.user.eid]]) |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
547 |
|
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
548 |
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
|
549 |
req = self.request() |
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
550 |
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
|
551 |
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
|
552 |
if isinstance(x, native.FTIndexEntityOp))) |
1787 | 553 |
|
554 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
555 |
class DBInitTC(CubicWebTC): |
1787 | 556 |
|
0 | 557 |
def test_versions_inserted(self): |
558 |
inserted = [r[0] for r in self.execute('Any K ORDERBY K WHERE P pkey K, P pkey ~= "system.version.%"')] |
|
559 |
self.assertEquals(inserted, |
|
1787 | 560 |
[u'system.version.basket', u'system.version.card', u'system.version.comment', |
561 |
u'system.version.cubicweb', u'system.version.email', |
|
562 |
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
|
563 |
u'system.version.tag']) |
1787 | 564 |
|
3445
32492e9e734b
update and simplify test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
565 |
CALLED = [] |
32492e9e734b
update and simplify test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
566 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
567 |
class InlineRelHooksTC(CubicWebTC): |
0 | 568 |
"""test relation hooks are called for inlined relations |
569 |
""" |
|
570 |
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
|
571 |
CubicWebTC.setUp(self) |
3445
32492e9e734b
update and simplify test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
572 |
CALLED[:] = () |
0 | 573 |
|
574 |
def _after_relation_hook(self, pool, fromeid, rtype, toeid): |
|
575 |
self.called.append((fromeid, rtype, toeid)) |
|
1787 | 576 |
|
3445
32492e9e734b
update and simplify test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
577 |
def test_inline_relation(self): |
32492e9e734b
update and simplify test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
578 |
"""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
|
579 |
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
|
580 |
__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
|
581 |
__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
|
582 |
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
|
583 |
'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
|
584 |
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
|
585 |
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
|
586 |
|
5105
57e0fc953676
[test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5103
diff
changeset
|
587 |
with self.temporary_appobjects(EcritParHook): |
57e0fc953676
[test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5103
diff
changeset
|
588 |
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
|
589 |
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
|
590 |
self.execute('SET N ecrit_par Y WHERE N type "T", Y nom "toto"') |
57e0fc953676
[test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5103
diff
changeset
|
591 |
self.assertEquals(CALLED, [('before_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
|
592 |
('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
|
593 |
CALLED[:] = () |
57e0fc953676
[test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5103
diff
changeset
|
594 |
self.execute('DELETE N ecrit_par Y WHERE N type "T", Y nom "toto"') |
57e0fc953676
[test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5103
diff
changeset
|
595 |
self.assertEquals(CALLED, [('before_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
|
596 |
('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
|
597 |
CALLED[:] = () |
57e0fc953676
[test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5103
diff
changeset
|
598 |
eidn = self.execute('INSERT Note N: N ecrit_par P WHERE P nom "toto"')[0][0] |
57e0fc953676
[test] use new temporary_appobjects context manager
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5103
diff
changeset
|
599 |
self.assertEquals(CALLED, [('before_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
|
600 |
('after_add_relation', eidn, 'ecrit_par', eidp)]) |
0 | 601 |
|
1787 | 602 |
|
0 | 603 |
if __name__ == '__main__': |
604 |
unittest_main() |