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