author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Tue, 10 Jun 2014 14:44:36 +0200 | |
changeset 10358 | d551d0a162d5 |
parent 10351 | 91e63306e277 |
child 10612 | 84468b90e9c1 |
permissions | -rw-r--r-- |
10351
91e63306e277
[connection] replace .running_dbapi_query with .hooks_in_progress
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10315
diff
changeset
|
1 |
# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4850
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4850
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4850
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4850
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4850
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4850
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4850
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4850
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4850
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4850
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4850
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4850
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4850
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4850
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4850
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
"""Fake objects to ease testing of cubicweb without a fully working environment |
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
19 |
""" |
0 | 20 |
|
21 |
__docformat__ = "restructuredtext en" |
|
22 |
||
10351
91e63306e277
[connection] replace .running_dbapi_query with .hooks_in_progress
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10315
diff
changeset
|
23 |
from contextlib import contextmanager |
91e63306e277
[connection] replace .running_dbapi_query with .hooks_in_progress
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10315
diff
changeset
|
24 |
|
4848
41f84eea63c9
rename logilab.db into logilab.database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
25 |
from logilab.database import get_db_helper |
0 | 26 |
|
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2773
diff
changeset
|
27 |
from cubicweb.req import RequestSessionBase |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7870
diff
changeset
|
28 |
from cubicweb.cwvreg import CWRegistryStore |
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8930
diff
changeset
|
29 |
from cubicweb.web.request import ConnectionCubicWebRequestBase |
7224
e5833657c646
[testlib] make a clear distinction between input / output HTTP headers
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6851
diff
changeset
|
30 |
|
0 | 31 |
from cubicweb.devtools import BASE_URL, BaseApptestConfiguration |
32 |
||
33 |
||
34 |
class FakeConfig(dict, BaseApptestConfiguration): |
|
35 |
translations = {} |
|
5467
57372dbfd114
[https] fix resource urls in https version of a site: should use the https version as well to avoid warnings from the nrowser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
36 |
uiprops = {} |
8276
57d8f3b3e165
[devtools/fake] add some https related properties to FakeRequest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8216
diff
changeset
|
37 |
https_uiprops = {} |
0 | 38 |
apphome = None |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7870
diff
changeset
|
39 |
debugmode = False |
0 | 40 |
def __init__(self, appid='data', apphome=None, cubes=()): |
41 |
self.appid = appid |
|
42 |
self.apphome = apphome |
|
43 |
self._cubes = cubes |
|
44 |
self['auth-mode'] = 'cookie' |
|
1482 | 45 |
self['uid'] = None |
0 | 46 |
self['base-url'] = BASE_URL |
8182
d062d3b7da6c
[config] fix rql-cache-size initial values (closes #2162160)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7870
diff
changeset
|
47 |
self['rql-cache-size'] = 3000 |
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5443
diff
changeset
|
48 |
self.datadir_url = BASE_URL + 'data/' |
8276
57d8f3b3e165
[devtools/fake] add some https related properties to FakeRequest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8216
diff
changeset
|
49 |
self.https_datadir_url = (BASE_URL + 'data/').replace('http://', 'https://') |
1482 | 50 |
|
0 | 51 |
def cubes(self, expand=False): |
52 |
return self._cubes |
|
1482 | 53 |
|
0 | 54 |
def sources(self): |
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
55 |
return {'system': {'db-driver': 'sqlite'}} |
0 | 56 |
|
57 |
||
9070
4a803380f718
PARTIAL: Using the repoapi in test
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8930
diff
changeset
|
58 |
class FakeRequest(ConnectionCubicWebRequestBase): |
0 | 59 |
"""test implementation of an cubicweb request object""" |
60 |
||
61 |
def __init__(self, *args, **kwargs): |
|
62 |
if not (args or 'vreg' in kwargs): |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7870
diff
changeset
|
63 |
kwargs['vreg'] = CWRegistryStore(FakeConfig(), initlog=False) |
0 | 64 |
kwargs['https'] = False |
8315
166e6d5d8e17
[fake-request] support `http_method()`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8314
diff
changeset
|
65 |
self._http_method = kwargs.pop('method', 'GET') |
7434
17ef6f9efaa1
[test] fix tests broken by 7427:5338d895b891
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7232
diff
changeset
|
66 |
self._url = kwargs.pop('url', None) or 'view?rql=Blop&vid=blop' |
0 | 67 |
super(FakeRequest, self).__init__(*args, **kwargs) |
68 |
self._session_data = {} |
|
69 |
||
10001
1245357b3b3e
[web] add support for HttpOnly cookie flag
Julien Cristau <julien.cristau@logilab.fr>
parents:
9570
diff
changeset
|
70 |
def set_cookie(self, name, value, maxage=300, expires=None, secure=False, httponly=False): |
1245357b3b3e
[web] add support for HttpOnly cookie flag
Julien Cristau <julien.cristau@logilab.fr>
parents:
9570
diff
changeset
|
71 |
super(FakeRequest, self).set_cookie(name, value, maxage, expires, secure, httponly) |
7224
e5833657c646
[testlib] make a clear distinction between input / output HTTP headers
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6851
diff
changeset
|
72 |
cookie = self.get_response_header('Set-Cookie') |
e5833657c646
[testlib] make a clear distinction between input / output HTTP headers
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6851
diff
changeset
|
73 |
self._headers_in.setHeader('Cookie', cookie) |
e5833657c646
[testlib] make a clear distinction between input / output HTTP headers
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6851
diff
changeset
|
74 |
|
e5833657c646
[testlib] make a clear distinction between input / output HTTP headers
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6851
diff
changeset
|
75 |
## Implement request abstract API |
8315
166e6d5d8e17
[fake-request] support `http_method()`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8314
diff
changeset
|
76 |
def http_method(self): |
166e6d5d8e17
[fake-request] support `http_method()`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8314
diff
changeset
|
77 |
return self._http_method |
166e6d5d8e17
[fake-request] support `http_method()`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8314
diff
changeset
|
78 |
|
0 | 79 |
def relative_path(self, includeparams=True): |
80 |
"""return the normalized path of the request (ie at least relative |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2471
diff
changeset
|
81 |
to the instance's root, but some other normalization may be needed |
0 | 82 |
so that the returned path may be used to compare to generated urls |
83 |
""" |
|
84 |
if self._url.startswith(BASE_URL): |
|
85 |
url = self._url[len(BASE_URL):] |
|
86 |
else: |
|
87 |
url = self._url |
|
88 |
if includeparams: |
|
89 |
return url |
|
90 |
return url.split('?', 1)[0] |
|
91 |
||
7224
e5833657c646
[testlib] make a clear distinction between input / output HTTP headers
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6851
diff
changeset
|
92 |
def set_request_header(self, header, value, raw=False): |
9570
14452b344d19
[devtools] add a 'method' argument to RepoAccess.web_request
David Douard <david.douard@logilab.fr>
parents:
9478
diff
changeset
|
93 |
"""set an incoming HTTP header (for test purpose only)""" |
7224
e5833657c646
[testlib] make a clear distinction between input / output HTTP headers
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6851
diff
changeset
|
94 |
if isinstance(value, basestring): |
e5833657c646
[testlib] make a clear distinction between input / output HTTP headers
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6851
diff
changeset
|
95 |
value = [value] |
9570
14452b344d19
[devtools] add a 'method' argument to RepoAccess.web_request
David Douard <david.douard@logilab.fr>
parents:
9478
diff
changeset
|
96 |
if raw: |
8314
cfd6ab461849
[Web-Request] Use rich header (closes #2204164)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8276
diff
changeset
|
97 |
# adding encoded header is important, else page content |
cfd6ab461849
[Web-Request] Use rich header (closes #2204164)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8276
diff
changeset
|
98 |
# will be reconverted back to unicode and apart unefficiency, this |
cfd6ab461849
[Web-Request] Use rich header (closes #2204164)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8276
diff
changeset
|
99 |
# may cause decoding problem (e.g. when downloading a file) |
7224
e5833657c646
[testlib] make a clear distinction between input / output HTTP headers
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6851
diff
changeset
|
100 |
self._headers_in.setRawHeaders(header, value) |
9570
14452b344d19
[devtools] add a 'method' argument to RepoAccess.web_request
David Douard <david.douard@logilab.fr>
parents:
9478
diff
changeset
|
101 |
else: |
8314
cfd6ab461849
[Web-Request] Use rich header (closes #2204164)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8276
diff
changeset
|
102 |
self._headers_in.setHeader(header, value) # |
1482 | 103 |
|
7224
e5833657c646
[testlib] make a clear distinction between input / output HTTP headers
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6851
diff
changeset
|
104 |
def get_response_header(self, header, default=None, raw=False): |
9570
14452b344d19
[devtools] add a 'method' argument to RepoAccess.web_request
David Douard <david.douard@logilab.fr>
parents:
9478
diff
changeset
|
105 |
"""return output header (for test purpose only)""" |
14452b344d19
[devtools] add a 'method' argument to RepoAccess.web_request
David Douard <david.douard@logilab.fr>
parents:
9478
diff
changeset
|
106 |
if raw: |
8314
cfd6ab461849
[Web-Request] Use rich header (closes #2204164)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8276
diff
changeset
|
107 |
return self.headers_out.getRawHeaders(header, [default])[0] |
cfd6ab461849
[Web-Request] Use rich header (closes #2204164)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8276
diff
changeset
|
108 |
return self.headers_out.getHeader(header, default) |
0 | 109 |
|
6595
00cd0b273cf5
[test] fix test to follow recent changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
110 |
def build_url_params(self, **kwargs): |
00cd0b273cf5
[test] fix test to follow recent changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
111 |
# overriden to get predictable resultts |
00cd0b273cf5
[test] fix test to follow recent changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
112 |
args = [] |
00cd0b273cf5
[test] fix test to follow recent changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
113 |
for param, values in sorted(kwargs.iteritems()): |
00cd0b273cf5
[test] fix test to follow recent changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
114 |
if not isinstance(values, (list, tuple)): |
00cd0b273cf5
[test] fix test to follow recent changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
115 |
values = (values,) |
00cd0b273cf5
[test] fix test to follow recent changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
116 |
for value in values: |
00cd0b273cf5
[test] fix test to follow recent changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
117 |
assert value is not None |
00cd0b273cf5
[test] fix test to follow recent changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
118 |
args.append(u'%s=%s' % (param, self.url_quote(value))) |
00cd0b273cf5
[test] fix test to follow recent changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
119 |
return '&'.join(args) |
0 | 120 |
|
121 |
class FakeUser(object): |
|
122 |
login = 'toto' |
|
123 |
eid = 0 |
|
124 |
def in_groups(self, groups): |
|
125 |
return True |
|
126 |
||
127 |
||
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2773
diff
changeset
|
128 |
class FakeSession(RequestSessionBase): |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4831
diff
changeset
|
129 |
|
7360
dbff01dd3c3c
[testlib] fake session can be given a vreg
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7356
diff
changeset
|
130 |
def __init__(self, repo=None, user=None, vreg=None): |
0 | 131 |
self.repo = repo |
7360
dbff01dd3c3c
[testlib] fake session can be given a vreg
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7356
diff
changeset
|
132 |
if vreg is None: |
dbff01dd3c3c
[testlib] fake session can be given a vreg
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7356
diff
changeset
|
133 |
vreg = getattr(self.repo, 'vreg', None) |
dbff01dd3c3c
[testlib] fake session can be given a vreg
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7356
diff
changeset
|
134 |
if vreg is None: |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7870
diff
changeset
|
135 |
vreg = CWRegistryStore(FakeConfig(), initlog=False) |
7360
dbff01dd3c3c
[testlib] fake session can be given a vreg
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7356
diff
changeset
|
136 |
self.vreg = vreg |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7360
diff
changeset
|
137 |
self.cnxset = FakeConnectionsSet() |
0 | 138 |
self.user = user or FakeUser() |
139 |
self.is_internal_session = False |
|
2101
08003e0354a7
update transaction data api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
140 |
self.transaction_data = {} |
1482 | 141 |
|
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4831
diff
changeset
|
142 |
def execute(self, *args, **kwargs): |
0 | 143 |
pass |
2703
27c04321fc81
[cleanup] delete-trailing-whitespace + removed debug print
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2650
diff
changeset
|
144 |
|
0 | 145 |
def commit(self, *args): |
2101
08003e0354a7
update transaction data api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
146 |
self.transaction_data.clear() |
0 | 147 |
def close(self, *args): |
148 |
pass |
|
149 |
def system_sql(self, sql, args=None): |
|
150 |
pass |
|
151 |
||
152 |
def set_entity_cache(self, entity): |
|
153 |
pass |
|
1482 | 154 |
|
8562
0d2fb4604265
[session] fix arguments default value and promote usage of security_enabled as session method. Closes #2481820
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8316
diff
changeset
|
155 |
def security_enabled(self, read=False, write=False): |
0d2fb4604265
[session] fix arguments default value and promote usage of security_enabled as session method. Closes #2481820
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8316
diff
changeset
|
156 |
class FakeCM(object): |
0d2fb4604265
[session] fix arguments default value and promote usage of security_enabled as session method. Closes #2481820
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8316
diff
changeset
|
157 |
def __enter__(self): pass |
0d2fb4604265
[session] fix arguments default value and promote usage of security_enabled as session method. Closes #2481820
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8316
diff
changeset
|
158 |
def __exit__(self, exctype, exc, traceback): pass |
0d2fb4604265
[session] fix arguments default value and promote usage of security_enabled as session method. Closes #2481820
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8316
diff
changeset
|
159 |
return FakeCM() |
0d2fb4604265
[session] fix arguments default value and promote usage of security_enabled as session method. Closes #2481820
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8316
diff
changeset
|
160 |
|
7356
73d7863d97c1
resurrect code lost by too much patch manipulation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7232
diff
changeset
|
161 |
# for use with enabled_security context manager |
73d7863d97c1
resurrect code lost by too much patch manipulation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7232
diff
changeset
|
162 |
read_security = write_security = True |
73d7863d97c1
resurrect code lost by too much patch manipulation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7232
diff
changeset
|
163 |
|
10351
91e63306e277
[connection] replace .running_dbapi_query with .hooks_in_progress
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10315
diff
changeset
|
164 |
@contextmanager |
91e63306e277
[connection] replace .running_dbapi_query with .hooks_in_progress
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10315
diff
changeset
|
165 |
def running_hooks_ops(self): |
91e63306e277
[connection] replace .running_dbapi_query with .hooks_in_progress
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10315
diff
changeset
|
166 |
yield |
91e63306e277
[connection] replace .running_dbapi_query with .hooks_in_progress
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10315
diff
changeset
|
167 |
|
0 | 168 |
class FakeRepo(object): |
169 |
querier = None |
|
170 |
def __init__(self, schema, vreg=None, config=None): |
|
171 |
self.extids = {} |
|
172 |
self.eids = {} |
|
173 |
self._count = 0 |
|
174 |
self.schema = schema |
|
175 |
self.config = config or FakeConfig() |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7870
diff
changeset
|
176 |
self.vreg = vreg or CWRegistryStore(self.config, initlog=False) |
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2703
diff
changeset
|
177 |
self.vreg.schema = schema |
0 | 178 |
|
179 |
def internal_session(self): |
|
180 |
return FakeSession(self) |
|
1481 | 181 |
|
10315
0f3489d622ba
[repository] replace session with cnx in a few places
Julien Cristau <julien.cristau@logilab.fr>
parents:
10001
diff
changeset
|
182 |
def extid2eid(self, source, extid, etype, cnx, insert=True): |
0 | 183 |
try: |
184 |
return self.extids[extid] |
|
185 |
except KeyError: |
|
186 |
if not insert: |
|
187 |
return None |
|
188 |
self._count += 1 |
|
189 |
eid = self._count |
|
10315
0f3489d622ba
[repository] replace session with cnx in a few places
Julien Cristau <julien.cristau@logilab.fr>
parents:
10001
diff
changeset
|
190 |
entity = source.before_entity_insertion(cnx, extid, etype, eid) |
0 | 191 |
self.extids[extid] = eid |
192 |
self.eids[eid] = extid |
|
10315
0f3489d622ba
[repository] replace session with cnx in a few places
Julien Cristau <julien.cristau@logilab.fr>
parents:
10001
diff
changeset
|
193 |
source.after_entity_insertion(cnx, extid, entity) |
0 | 194 |
return eid |
1482 | 195 |
|
0 | 196 |
|
197 |
class FakeSource(object): |
|
4831
c5aec27c1bf7
[repo] use logilab.db instead of lgc.adbh/lgc.db/lgc.sqlgen/indexer, test new date extranction functions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4459
diff
changeset
|
198 |
dbhelper = get_db_helper('sqlite') |
0 | 199 |
def __init__(self, uri): |
200 |
self.uri = uri |
|
201 |
||
1482 | 202 |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7360
diff
changeset
|
203 |
class FakeConnectionsSet(object): |
0 | 204 |
def source(self, uri): |
205 |
return FakeSource(uri) |