author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 02 Sep 2009 10:23:38 +0200 | |
branch | 3.5 |
changeset 3084 | 096d680c9da2 |
parent 2923 | b97a0f8dd4dc |
child 2968 | 0e3460341023 |
child 3771 | 234b003f0fe0 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: iso-8859-1 -*- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1954
diff
changeset
|
2 |
"""unit tests for module cubicweb.server.repository |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1954
diff
changeset
|
3 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1954
diff
changeset
|
4 |
:organization: Logilab |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1954
diff
changeset
|
5 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1954
diff
changeset
|
6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1954
diff
changeset
|
7 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1954
diff
changeset
|
8 |
""" |
0 | 9 |
|
10 |
import os |
|
11 |
import sys |
|
12 |
import threading |
|
13 |
import time |
|
14 |
from copy import deepcopy |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
17
diff
changeset
|
15 |
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
|
16 |
|
0 | 17 |
from logilab.common.testlib import TestCase, unittest_main |
18 |
||
19 |
from yams.constraints import UniqueConstraint |
|
20 |
||
21 |
from cubicweb import BadConnectionId, RepositoryError, ValidationError, UnknownEid, AuthenticationError |
|
22 |
from cubicweb.schema import CubicWebSchema, RQLConstraint |
|
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
|
23 |
from cubicweb.dbapi import connect, repo_connect, multiple_connections_unfix |
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
|
24 |
from cubicweb.devtools.apptest import RepositoryBasedTC |
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
|
25 |
from cubicweb.devtools.repotest import tuplify |
1787 | 26 |
from cubicweb.server import repository |
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
|
27 |
from cubicweb.server.sqlutils import SQL_PREFIX |
0 | 28 |
|
29 |
||
30 |
# start name server anyway, process will fail if already running |
|
31 |
os.system('pyro-ns >/dev/null 2>/dev/null &') |
|
32 |
||
33 |
||
34 |
class RepositoryTC(RepositoryBasedTC): |
|
35 |
""" singleton providing access to a persistent storage for entities |
|
36 |
and relation |
|
37 |
""" |
|
1787 | 38 |
|
0 | 39 |
# def setUp(self): |
40 |
# pass |
|
1787 | 41 |
|
0 | 42 |
# def tearDown(self): |
43 |
# self.repo.config.db_perms = True |
|
44 |
# cnxid = self.repo.connect(*self.default_user_password()) |
|
45 |
# for etype in ('Affaire', 'Note', 'Societe', 'Personne'): |
|
46 |
# self.repo.execute(cnxid, 'DELETE %s X' % etype) |
|
47 |
# self.repo.commit(cnxid) |
|
48 |
# self.repo.close(cnxid) |
|
49 |
||
50 |
def test_fill_schema(self): |
|
51 |
self.repo.schema = CubicWebSchema(self.repo.config.appid) |
|
52 |
self.repo.config._cubes = None # avoid assertion error |
|
53 |
self.repo.fill_schema() |
|
54 |
pool = self.repo._get_pool() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
55 |
table = SQL_PREFIX + 'CWEType' |
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
|
56 |
namecol = SQL_PREFIX + 'name' |
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
|
57 |
finalcol = SQL_PREFIX + 'final' |
0 | 58 |
try: |
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
|
59 |
cu = self.session.system_sql('SELECT %s FROM %s WHERE %s is NULL' % ( |
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
|
60 |
namecol, table, finalcol)) |
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
|
61 |
self.assertEquals(cu.fetchall(), []) |
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
|
62 |
cu = self.session.system_sql('SELECT %s FROM %s WHERE %s=%%(final)s ORDER BY %s' |
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
|
63 |
% (namecol, table, finalcol, namecol), {'final': 'TRUE'}) |
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
|
64 |
self.assertEquals(cu.fetchall(), [(u'Boolean',), (u'Bytes',), |
0 | 65 |
(u'Date',), (u'Datetime',), |
66 |
(u'Decimal',),(u'Float',), |
|
67 |
(u'Int',), |
|
68 |
(u'Interval',), (u'Password',), |
|
69 |
(u'String',), (u'Time',)]) |
|
70 |
finally: |
|
71 |
self.repo._free_pool(pool) |
|
1787 | 72 |
|
0 | 73 |
def test_schema_has_owner(self): |
74 |
repo = self.repo |
|
75 |
cnxid = repo.connect(*self.default_user_password()) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
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
|
81 |
self.failIf(repo.execute(cnxid, 'CWConstraintType X WHERE NOT X owned_by U')) |
1787 | 82 |
|
0 | 83 |
def test_connect(self): |
84 |
login, passwd = self.default_user_password() |
|
85 |
self.assert_(self.repo.connect(login, passwd)) |
|
86 |
self.assertRaises(AuthenticationError, |
|
87 |
self.repo.connect, login, 'nimportnawak') |
|
88 |
self.assertRaises(AuthenticationError, |
|
89 |
self.repo.connect, login, None) |
|
90 |
self.assertRaises(AuthenticationError, |
|
91 |
self.repo.connect, None, None) |
|
1787 | 92 |
|
0 | 93 |
def test_execute(self): |
94 |
repo = self.repo |
|
95 |
cnxid = repo.connect(*self.default_user_password()) |
|
96 |
repo.execute(cnxid, 'Any X') |
|
97 |
repo.execute(cnxid, 'Any X where X is Personne') |
|
98 |
repo.execute(cnxid, 'Any X where X is Personne, X nom ~= "to"') |
|
99 |
repo.execute(cnxid, 'Any X WHERE X has_text %(text)s', {'text': u'\xe7a'}) |
|
100 |
repo.close(cnxid) |
|
1787 | 101 |
|
0 | 102 |
def test_login_upassword_accent(self): |
103 |
repo = self.repo |
|
104 |
cnxid = repo.connect(*self.default_user_password()) |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
105 |
repo.execute(cnxid, 'INSERT CWUser X: X login %(login)s, X upassword %(passwd)s, X in_group G WHERE G name "users"', |
0 | 106 |
{'login': u"barnab�", 'passwd': u"h�h�h�".encode('UTF8')}) |
107 |
repo.commit(cnxid) |
|
108 |
repo.close(cnxid) |
|
109 |
self.assert_(repo.connect(u"barnab�", u"h�h�h�".encode('UTF8'))) |
|
1787 | 110 |
|
0 | 111 |
def test_invalid_entity_rollback(self): |
112 |
repo = self.repo |
|
113 |
cnxid = repo.connect(*self.default_user_password()) |
|
1787 | 114 |
# no group |
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', |
0 | 116 |
{'login': u"tutetute", 'passwd': 'tutetute'}) |
117 |
self.assertRaises(ValidationError, repo.commit, cnxid) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
118 |
rset = repo.execute(cnxid, 'CWUser X WHERE X login "tutetute"') |
0 | 119 |
self.assertEquals(rset.rowcount, 0) |
1787 | 120 |
|
0 | 121 |
def test_close(self): |
122 |
repo = self.repo |
|
123 |
cnxid = repo.connect(*self.default_user_password()) |
|
124 |
self.assert_(cnxid) |
|
125 |
repo.close(cnxid) |
|
126 |
self.assertRaises(BadConnectionId, repo.execute, cnxid, 'Any X') |
|
1787 | 127 |
|
0 | 128 |
def test_invalid_cnxid(self): |
129 |
self.assertRaises(BadConnectionId, self.repo.execute, 0, 'Any X') |
|
130 |
self.assertRaises(BadConnectionId, self.repo.close, None) |
|
1787 | 131 |
|
0 | 132 |
def test_shared_data(self): |
133 |
repo = self.repo |
|
134 |
cnxid = repo.connect(*self.default_user_password()) |
|
135 |
repo.set_shared_data(cnxid, 'data', 4) |
|
136 |
cnxid2 = repo.connect(*self.default_user_password()) |
|
137 |
self.assertEquals(repo.get_shared_data(cnxid, 'data'), 4) |
|
138 |
self.assertEquals(repo.get_shared_data(cnxid2, 'data'), None) |
|
139 |
repo.set_shared_data(cnxid2, 'data', 5) |
|
140 |
self.assertEquals(repo.get_shared_data(cnxid, 'data'), 4) |
|
141 |
self.assertEquals(repo.get_shared_data(cnxid2, 'data'), 5) |
|
142 |
repo.get_shared_data(cnxid2, 'data', pop=True) |
|
143 |
self.assertEquals(repo.get_shared_data(cnxid, 'data'), 4) |
|
144 |
self.assertEquals(repo.get_shared_data(cnxid2, 'data'), None) |
|
145 |
repo.close(cnxid) |
|
146 |
repo.close(cnxid2) |
|
147 |
self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid, 'data') |
|
148 |
self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid2, 'data') |
|
149 |
self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid, 'data', 1) |
|
150 |
self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid2, 'data', 1) |
|
151 |
||
152 |
def test_check_session(self): |
|
153 |
repo = self.repo |
|
154 |
cnxid = repo.connect(*self.default_user_password()) |
|
155 |
self.assertEquals(repo.check_session(cnxid), None) |
|
156 |
repo.close(cnxid) |
|
157 |
self.assertRaises(BadConnectionId, repo.check_session, cnxid) |
|
158 |
||
159 |
def test_transaction_base(self): |
|
160 |
repo = self.repo |
|
161 |
cnxid = repo.connect(*self.default_user_password()) |
|
162 |
# check db state |
|
163 |
result = repo.execute(cnxid, 'Personne X') |
|
164 |
self.assertEquals(result.rowcount, 0) |
|
165 |
# rollback entity insertion |
|
166 |
repo.execute(cnxid, "INSERT Personne X: X nom 'bidule'") |
|
167 |
result = repo.execute(cnxid, 'Personne X') |
|
168 |
self.assertEquals(result.rowcount, 1) |
|
169 |
repo.rollback(cnxid) |
|
170 |
result = repo.execute(cnxid, 'Personne X') |
|
171 |
self.assertEquals(result.rowcount, 0, result.rows) |
|
172 |
# commit |
|
173 |
repo.execute(cnxid, "INSERT Personne X: X nom 'bidule'") |
|
174 |
repo.commit(cnxid) |
|
175 |
result = repo.execute(cnxid, 'Personne X') |
|
176 |
self.assertEquals(result.rowcount, 1) |
|
177 |
||
178 |
def test_transaction_base2(self): |
|
179 |
repo = self.repo |
|
180 |
cnxid = repo.connect(*self.default_user_password()) |
|
181 |
# rollback relation insertion |
|
182 |
repo.execute(cnxid, "SET U in_group G WHERE U login 'admin', G name 'guests'") |
|
183 |
result = repo.execute(cnxid, "Any U WHERE U in_group G, U login 'admin', G name 'guests'") |
|
184 |
self.assertEquals(result.rowcount, 1) |
|
185 |
repo.rollback(cnxid) |
|
186 |
result = repo.execute(cnxid, "Any U WHERE U in_group G, U login 'admin', G name 'guests'") |
|
187 |
self.assertEquals(result.rowcount, 0, result.rows) |
|
1787 | 188 |
|
0 | 189 |
def test_transaction_base3(self): |
190 |
repo = self.repo |
|
191 |
cnxid = repo.connect(*self.default_user_password()) |
|
192 |
# rollback state change which trigger TrInfo insertion |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
193 |
user = repo._get_session(cnxid).user |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
194 |
user.fire_transition('deactivate') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
195 |
rset = repo.execute(cnxid, 'TrInfo T WHERE T wf_info_for X, X eid %(x)s', {'x': user.eid}) |
0 | 196 |
self.assertEquals(len(rset), 1) |
197 |
repo.rollback(cnxid) |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
198 |
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
|
199 |
self.assertEquals(len(rset), 0) |
1787 | 200 |
|
0 | 201 |
def test_transaction_interleaved(self): |
202 |
self.skip('implement me') |
|
203 |
||
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
|
204 |
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
|
205 |
repo = self.repo |
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
|
206 |
cnxid = repo.connect(*self.default_user_password()) |
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
|
207 |
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
|
208 |
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
|
209 |
# 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
|
210 |
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
|
211 |
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
|
212 |
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
|
213 |
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
|
214 |
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
|
215 |
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
|
216 |
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
|
217 |
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
|
218 |
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
|
219 |
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
|
220 |
|
0 | 221 |
def test_initial_schema(self): |
222 |
schema = self.repo.schema |
|
223 |
# 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
|
224 |
self.assertListEquals([r.type for r in schema.eschema('CWAttribute').ordered_relations() |
1787 | 225 |
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
|
226 |
'creation_date', 'modification_date', 'cwuri', |
0 | 227 |
'owned_by', 'created_by')], |
2608
21856eda34f6
[F repo tests] tests have to be updated:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2588
diff
changeset
|
228 |
['relation_type', 'from_entity', 'in_basket', 'to_entity', 'constrained_by', |
1787 | 229 |
'cardinality', 'ordernum', |
0 | 230 |
'indexed', 'fulltextindexed', 'internationalizable', |
2608
21856eda34f6
[F repo tests] tests have to be updated:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2588
diff
changeset
|
231 |
'defaultval', 'description', 'description_format']) |
0 | 232 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
233 |
self.assertEquals(schema.eschema('CWEType').main_attribute(), 'name') |
0 | 234 |
self.assertEquals(schema.eschema('State').main_attribute(), 'name') |
235 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
236 |
constraints = schema.rschema('name').rproperty('CWEType', 'String', 'constraints') |
0 | 237 |
self.assertEquals(len(constraints), 2) |
238 |
for cstr in constraints[:]: |
|
239 |
if isinstance(cstr, UniqueConstraint): |
|
240 |
constraints.remove(cstr) |
|
241 |
break |
|
242 |
else: |
|
243 |
self.fail('unique constraint not found') |
|
244 |
sizeconstraint = constraints[0] |
|
245 |
self.assertEquals(sizeconstraint.min, None) |
|
246 |
self.assertEquals(sizeconstraint.max, 64) |
|
247 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
248 |
constraints = schema.rschema('relation_type').rproperty('CWAttribute', 'CWRType', 'constraints') |
0 | 249 |
self.assertEquals(len(constraints), 1) |
250 |
cstr = constraints[0] |
|
251 |
self.assert_(isinstance(cstr, RQLConstraint)) |
|
252 |
self.assertEquals(cstr.restriction, 'O final TRUE') |
|
253 |
||
254 |
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
|
255 |
self.assertEquals(ownedby.objects('CWEType'), ('CWUser',)) |
0 | 256 |
|
257 |
def test_pyro(self): |
|
258 |
import Pyro |
|
259 |
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
|
260 |
done = [] |
0 | 261 |
# 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
|
262 |
t = threading.Thread(target=self._pyro_client, args=(done,)) |
0 | 263 |
try: |
264 |
daemon = self.repo.pyro_register() |
|
265 |
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
|
266 |
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
|
267 |
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
|
268 |
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
|
269 |
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
|
270 |
self.fail('something went wrong, thread still alive') |
0 | 271 |
finally: |
272 |
repository.pyro_unregister(self.repo.config) |
|
1787 | 273 |
|
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
|
274 |
def _pyro_client(self, done): |
0 | 275 |
cnx = connect(self.repo.config.appid, u'admin', 'gingkow') |
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
|
276 |
try: |
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
|
277 |
# 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
|
278 |
schema = cnx.get_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
|
279 |
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
|
280 |
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
|
281 |
rset = cu.execute('Any U,G WHERE U in_group G') |
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
|
282 |
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
|
283 |
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
|
284 |
finally: |
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
|
285 |
# connect monkey path some method by default, remove them |
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
|
286 |
multiple_connections_unfix() |
0 | 287 |
|
288 |
def test_internal_api(self): |
|
289 |
repo = self.repo |
|
290 |
cnxid = repo.connect(*self.default_user_password()) |
|
291 |
session = repo._get_session(cnxid, setpool=True) |
|
1954 | 292 |
self.assertEquals(repo.type_and_source_from_eid(1, session), |
293 |
('CWGroup', 'system', None)) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
294 |
self.assertEquals(repo.type_from_eid(1, session), 'CWGroup') |
0 | 295 |
self.assertEquals(repo.source_from_eid(1, session).uri, 'system') |
296 |
self.assertEquals(repo.eid2extid(repo.system_source, 1, session), None) |
|
297 |
class dummysource: uri = 'toto' |
|
298 |
self.assertRaises(UnknownEid, repo.eid2extid, dummysource, 1, session) |
|
299 |
||
300 |
def test_public_api(self): |
|
301 |
self.assertEquals(self.repo.get_schema(), self.repo.schema) |
|
302 |
self.assertEquals(self.repo.source_defs(), {'system': {'adapter': 'native', 'uri': 'system'}}) |
|
303 |
# .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
|
304 |
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 | 305 |
|
306 |
def test_session_api(self): |
|
307 |
repo = self.repo |
|
308 |
cnxid = repo.connect(*self.default_user_password()) |
|
309 |
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
|
310 |
self.assertEquals(repo.describe(cnxid, 1), (u'CWGroup', u'system', None)) |
0 | 311 |
repo.close(cnxid) |
312 |
self.assertRaises(BadConnectionId, repo.user_info, cnxid) |
|
313 |
self.assertRaises(BadConnectionId, repo.describe, cnxid, 1) |
|
314 |
||
315 |
def test_shared_data_api(self): |
|
316 |
repo = self.repo |
|
317 |
cnxid = repo.connect(*self.default_user_password()) |
|
318 |
self.assertEquals(repo.get_shared_data(cnxid, 'data'), None) |
|
319 |
repo.set_shared_data(cnxid, 'data', 4) |
|
320 |
self.assertEquals(repo.get_shared_data(cnxid, 'data'), 4) |
|
321 |
repo.get_shared_data(cnxid, 'data', pop=True) |
|
322 |
repo.get_shared_data(cnxid, 'whatever', pop=True) |
|
323 |
self.assertEquals(repo.get_shared_data(cnxid, 'data'), None) |
|
324 |
repo.close(cnxid) |
|
325 |
self.assertRaises(BadConnectionId, repo.set_shared_data, cnxid, 'data', 0) |
|
326 |
self.assertRaises(BadConnectionId, repo.get_shared_data, cnxid, 'data') |
|
1787 | 327 |
|
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
|
328 |
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
|
329 |
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
|
330 |
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
|
331 |
|
2642 | 332 |
# def test_perfo(self): |
333 |
# self.set_debug(True) |
|
334 |
# from time import time, clock |
|
335 |
# t, c = time(), clock() |
|
336 |
# try: |
|
337 |
# self.create_user('toto') |
|
338 |
# finally: |
|
339 |
# self.set_debug(False) |
|
340 |
# print 'test time: %.3f (time) %.3f (cpu)' % ((time() - t), clock() - c) |
|
341 |
||
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
|
342 |
def test_delete_if_singlecard1(self): |
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
|
343 |
note = self.add_entity('Affaire') |
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
|
344 |
p1 = self.add_entity('Personne', nom=u'toto') |
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
|
345 |
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
|
346 |
{'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
|
347 |
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
|
348 |
{'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
|
349 |
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
|
350 |
p2 = self.add_entity('Personne', nom=u'tutu') |
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
|
351 |
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
|
352 |
{'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
|
353 |
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
|
354 |
{'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
|
355 |
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
|
356 |
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
|
357 |
|
0 | 358 |
|
359 |
class DataHelpersTC(RepositoryBasedTC): |
|
1787 | 360 |
|
0 | 361 |
def setUp(self): |
362 |
""" called before each test from this class """ |
|
363 |
cnxid = self.repo.connect(*self.default_user_password()) |
|
364 |
self.session = self.repo._sessions[cnxid] |
|
365 |
self.session.set_pool() |
|
366 |
||
367 |
def tearDown(self): |
|
368 |
self.session.rollback() |
|
1787 | 369 |
|
0 | 370 |
def test_create_eid(self): |
371 |
self.assert_(self.repo.system_source.create_eid(self.session)) |
|
372 |
||
373 |
def test_source_from_eid(self): |
|
374 |
self.assertEquals(self.repo.source_from_eid(1, self.session), |
|
375 |
self.repo.sources_by_uri['system']) |
|
376 |
||
377 |
def test_source_from_eid_raise(self): |
|
378 |
self.assertRaises(UnknownEid, self.repo.source_from_eid, -2, self.session) |
|
379 |
||
380 |
def test_type_from_eid(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
381 |
self.assertEquals(self.repo.type_from_eid(1, self.session), 'CWGroup') |
1787 | 382 |
|
0 | 383 |
def test_type_from_eid_raise(self): |
384 |
self.assertRaises(UnknownEid, self.repo.type_from_eid, -2, self.session) |
|
1787 | 385 |
|
0 | 386 |
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
|
387 |
entity = self.repo.vreg['etypes'].etype_class('Personne')(self.session) |
0 | 388 |
entity.eid = -1 |
389 |
entity.complete = lambda x: None |
|
390 |
self.repo.add_info(self.session, entity, self.repo.sources_by_uri['system']) |
|
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
|
391 |
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
|
392 |
data = cu.fetchall() |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
17
diff
changeset
|
393 |
self.assertIsInstance(data[0][3], datetime) |
0 | 394 |
data[0] = list(data[0]) |
395 |
data[0][3] = None |
|
396 |
self.assertEquals(tuplify(data), [(-1, 'Personne', 'system', None, None)]) |
|
397 |
self.repo.delete_info(self.session, -1) |
|
398 |
#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
|
399 |
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
|
400 |
data = cu.fetchall() |
0 | 401 |
self.assertEquals(data, []) |
402 |
||
403 |
||
404 |
class FTITC(RepositoryBasedTC): |
|
1787 | 405 |
|
0 | 406 |
def test_reindex_and_modified_since(self): |
407 |
eidp = self.execute('INSERT Personne X: X nom "toto", X prenom "tutu"')[0][0] |
|
408 |
self.commit() |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
17
diff
changeset
|
409 |
ts = datetime.now() |
0 | 410 |
self.assertEquals(len(self.execute('Personne X WHERE X has_text "tutu"')), 1) |
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
|
411 |
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
|
412 |
omtime = cu.fetchone()[0] |
0 | 413 |
# our sqlite datetime adapter is ignore seconds fraction, so we have to |
414 |
# ensure update is done the next seconds |
|
415 |
time.sleep(1 - (ts.second - int(ts.second))) |
|
416 |
self.execute('SET X nom "tata" WHERE X eid %(x)s', {'x': eidp}, 'x') |
|
417 |
self.commit() |
|
418 |
self.assertEquals(len(self.execute('Personne X WHERE X has_text "tutu"')), 1) |
|
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
|
419 |
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
|
420 |
mtime = cu.fetchone()[0] |
0 | 421 |
self.failUnless(omtime < mtime) |
422 |
self.commit() |
|
423 |
date, modified, deleted = self.repo.entities_modified_since(('Personne',), omtime) |
|
424 |
self.assertEquals(modified, [('Personne', eidp)]) |
|
425 |
self.assertEquals(deleted, []) |
|
426 |
date, modified, deleted = self.repo.entities_modified_since(('Personne',), mtime) |
|
427 |
self.assertEquals(modified, []) |
|
428 |
self.assertEquals(deleted, []) |
|
429 |
self.execute('DELETE Personne X WHERE X eid %(x)s', {'x': eidp}) |
|
430 |
self.commit() |
|
431 |
date, modified, deleted = self.repo.entities_modified_since(('Personne',), omtime) |
|
432 |
self.assertEquals(modified, []) |
|
433 |
self.assertEquals(deleted, [('Personne', eidp)]) |
|
434 |
||
435 |
def test_composite_entity(self): |
|
436 |
assert self.schema.rschema('use_email').fulltext_container == 'subject' |
|
437 |
eid = self.add_entity('EmailAddress', address=u'toto@logilab.fr').eid |
|
438 |
self.commit() |
|
439 |
rset = self.execute('Any X WHERE X has_text %(t)s', {'t': 'toto'}) |
|
440 |
self.assertEquals(rset.rows, [[eid]]) |
|
441 |
self.execute('SET X use_email Y WHERE X login "admin", Y eid %(y)s', {'y': eid}) |
|
442 |
self.commit() |
|
443 |
rset = self.execute('Any X WHERE X has_text %(t)s', {'t': 'toto'}) |
|
444 |
self.assertEquals(rset.rows, [[self.session.user.eid]]) |
|
445 |
self.execute('DELETE X use_email Y WHERE X login "admin", Y eid %(y)s', {'y': eid}) |
|
446 |
self.commit() |
|
447 |
rset = self.execute('Any X WHERE X has_text %(t)s', {'t': 'toto'}) |
|
448 |
self.assertEquals(rset.rows, []) |
|
449 |
eid = self.add_entity('EmailAddress', address=u'tutu@logilab.fr').eid |
|
450 |
self.execute('SET X use_email Y WHERE X login "admin", Y eid %(y)s', {'y': eid}) |
|
451 |
self.commit() |
|
452 |
rset = self.execute('Any X WHERE X has_text %(t)s', {'t': 'tutu'}) |
|
453 |
self.assertEquals(rset.rows, [[self.session.user.eid]]) |
|
1787 | 454 |
|
455 |
||
0 | 456 |
class DBInitTC(RepositoryBasedTC): |
1787 | 457 |
|
0 | 458 |
def test_versions_inserted(self): |
459 |
inserted = [r[0] for r in self.execute('Any K ORDERBY K WHERE P pkey K, P pkey ~= "system.version.%"')] |
|
460 |
self.assertEquals(inserted, |
|
1787 | 461 |
[u'system.version.basket', u'system.version.card', u'system.version.comment', |
462 |
u'system.version.cubicweb', u'system.version.email', |
|
463 |
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
|
464 |
u'system.version.tag']) |
1787 | 465 |
|
0 | 466 |
class InlineRelHooksTC(RepositoryBasedTC): |
467 |
"""test relation hooks are called for inlined relations |
|
468 |
""" |
|
469 |
def setUp(self): |
|
470 |
RepositoryBasedTC.setUp(self) |
|
471 |
self.hm = self.repo.hm |
|
472 |
self.called = [] |
|
1787 | 473 |
|
0 | 474 |
def _before_relation_hook(self, pool, fromeid, rtype, toeid): |
475 |
self.called.append((fromeid, rtype, toeid)) |
|
476 |
||
477 |
def _after_relation_hook(self, pool, fromeid, rtype, toeid): |
|
478 |
self.called.append((fromeid, rtype, toeid)) |
|
1787 | 479 |
|
0 | 480 |
def test_before_add_inline_relation(self): |
481 |
"""make sure before_<event>_relation hooks are called directly""" |
|
482 |
self.hm.register_hook(self._before_relation_hook, |
|
483 |
'before_add_relation', 'ecrit_par') |
|
484 |
eidp = self.execute('INSERT Personne X: X nom "toto"')[0][0] |
|
485 |
eidn = self.execute('INSERT Note X: X type "T"')[0][0] |
|
486 |
self.execute('SET N ecrit_par Y WHERE N type "T", Y nom "toto"') |
|
487 |
self.assertEquals(self.called, [(eidn, 'ecrit_par', eidp)]) |
|
1787 | 488 |
|
0 | 489 |
def test_after_add_inline_relation(self): |
490 |
"""make sure after_<event>_relation hooks are deferred""" |
|
491 |
self.hm.register_hook(self._after_relation_hook, |
|
492 |
'after_add_relation', 'ecrit_par') |
|
493 |
eidp = self.execute('INSERT Personne X: X nom "toto"')[0][0] |
|
494 |
eidn = self.execute('INSERT Note X: X type "T"')[0][0] |
|
495 |
self.assertEquals(self.called, []) |
|
496 |
self.execute('SET N ecrit_par Y WHERE N type "T", Y nom "toto"') |
|
497 |
self.assertEquals(self.called, [(eidn, 'ecrit_par', eidp,)]) |
|
1787 | 498 |
|
0 | 499 |
def test_after_add_inline(self): |
500 |
"""make sure after_<event>_relation hooks are deferred""" |
|
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
|
501 |
p1 = self.add_entity('Personne', nom=u'toto') |
0 | 502 |
self.hm.register_hook(self._after_relation_hook, |
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
|
503 |
'after_add_relation', 'ecrit_par') |
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
|
504 |
eidn = self.execute('INSERT Note N: N ecrit_par P WHERE P nom "toto"')[0][0] |
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
|
505 |
self.assertEquals(self.called, [(eidn, 'ecrit_par', p1.eid,)]) |
1787 | 506 |
|
0 | 507 |
def test_before_delete_inline_relation(self): |
508 |
"""make sure before_<event>_relation hooks are called directly""" |
|
509 |
self.hm.register_hook(self._before_relation_hook, |
|
510 |
'before_delete_relation', 'ecrit_par') |
|
511 |
eidp = self.execute('INSERT Personne X: X nom "toto"')[0][0] |
|
512 |
eidn = self.execute('INSERT Note X: X type "T"')[0][0] |
|
513 |
self.execute('SET N ecrit_par Y WHERE N type "T", Y nom "toto"') |
|
514 |
self.execute('DELETE N ecrit_par Y WHERE N type "T", Y nom "toto"') |
|
515 |
self.assertEquals(self.called, [(eidn, 'ecrit_par', eidp)]) |
|
516 |
rset = self.execute('Any Y where N ecrit_par Y, N type "T", Y nom "toto"') |
|
517 |
# make sure the relation is really deleted |
|
518 |
self.failUnless(len(rset) == 0, "failed to delete inline relation") |
|
519 |
||
520 |
def test_after_delete_inline_relation(self): |
|
521 |
"""make sure after_<event>_relation hooks are deferred""" |
|
522 |
self.hm.register_hook(self._after_relation_hook, |
|
523 |
'after_delete_relation', 'ecrit_par') |
|
524 |
eidp = self.execute('INSERT Personne X: X nom "toto"')[0][0] |
|
525 |
eidn = self.execute('INSERT Note X: X type "T"')[0][0] |
|
526 |
self.execute('SET N ecrit_par Y WHERE N type "T", Y nom "toto"') |
|
527 |
self.assertEquals(self.called, []) |
|
528 |
self.execute('DELETE N ecrit_par Y WHERE N type "T", Y nom "toto"') |
|
529 |
self.assertEquals(self.called, [(eidn, 'ecrit_par', eidp,)]) |
|
530 |
||
1787 | 531 |
|
0 | 532 |
if __name__ == '__main__': |
533 |
unittest_main() |