author | Rémi Cardona <remi.cardona@logilab.fr> |
Thu, 17 Sep 2015 15:35:26 +0200 | |
changeset 10705 | e7eafadbeb15 |
parent 10704 | 73367a56ee41 |
child 10706 | b261d90149d0 |
permissions | -rw-r--r-- |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
1 |
# copyright 2003-2014 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:
5240
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:
5240
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:
5240
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:
5240
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:
5240
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:
5240
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:
5240
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:
5240
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:
5240
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:
5240
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:
5240
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:
5240
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:
5240
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:
5240
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:
5240
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
18 |
"""unit tests for module cubicweb.server.sources.storages""" |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
19 |
|
6382
4efd0f07fd53
[test] improve tag for server/test/unittest_storage.py
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6340
diff
changeset
|
20 |
from logilab.common.testlib import unittest_main, tag, Tags |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
21 |
from cubicweb.devtools.testlib import CubicWebTC |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
22 |
|
10453
76f601a90aa7
[storage] use mkstemp to create files in bfss
Julien Cristau <julien.cristau@logilab.fr>
parents:
9783
diff
changeset
|
23 |
from glob import glob |
8180
1f6ba9afb925
[storage] BFSS now create read only file (closes #2151672)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7979
diff
changeset
|
24 |
import os |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
25 |
import os.path as osp |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
26 |
import shutil |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
27 |
import tempfile |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
28 |
|
5013
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5008
diff
changeset
|
29 |
from cubicweb import Binary, QueryError |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8180
diff
changeset
|
30 |
from cubicweb.predicates import is_instance |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
31 |
from cubicweb.server.sources import storages |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
32 |
from cubicweb.server.hook import Hook |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
33 |
|
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
34 |
class DummyBeforeHook(Hook): |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
35 |
__regid__ = 'dummy-before-hook' |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5717
diff
changeset
|
36 |
__select__ = Hook.__select__ & is_instance('File') |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
37 |
events = ('before_add_entity',) |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
38 |
|
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
39 |
def __call__(self): |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
40 |
self._cw.transaction_data['orig_file_value'] = self.entity.data.getvalue() |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
41 |
|
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
42 |
|
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
43 |
class DummyAfterHook(Hook): |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
44 |
__regid__ = 'dummy-after-hook' |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5717
diff
changeset
|
45 |
__select__ = Hook.__select__ & is_instance('File') |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
46 |
events = ('after_add_entity',) |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
47 |
|
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
48 |
def __call__(self): |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
49 |
# new value of entity.data should be the same as before |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
50 |
oldvalue = self._cw.transaction_data['orig_file_value'] |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
51 |
assert oldvalue == self.entity.data.getvalue() |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
52 |
|
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
53 |
class StorageTC(CubicWebTC): |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
54 |
tempdir = None |
6382
4efd0f07fd53
[test] improve tag for server/test/unittest_storage.py
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6340
diff
changeset
|
55 |
tags = CubicWebTC.tags | Tags('Storage', 'BFSS') |
4efd0f07fd53
[test] improve tag for server/test/unittest_storage.py
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6340
diff
changeset
|
56 |
|
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
57 |
def setup_database(self): |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
58 |
self.tempdir = tempfile.mkdtemp() |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
59 |
bfs_storage = storages.BytesFileSystemStorage(self.tempdir) |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
60 |
storages.set_attribute_storage(self.repo, 'File', 'data', bfs_storage) |
7694
bd56a29acaa8
[bfss] Fix update of BFSS attribute to None (close #1875289)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7057
diff
changeset
|
61 |
storages.set_attribute_storage(self.repo, 'BFSSTestable', 'opt_attr', bfs_storage) |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
62 |
|
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
63 |
def tearDown(self): |
7057
daa1da99a071
[test] fix bad super call
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6796
diff
changeset
|
64 |
super(StorageTC, self).tearDown() |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
65 |
storages.unset_attribute_storage(self.repo, 'File', 'data') |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
66 |
shutil.rmtree(self.tempdir) |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
67 |
|
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
68 |
|
10704
73367a56ee41
[py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
69 |
def create_file(self, cnx, content=b'the-data'): |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
70 |
return cnx.create_entity('File', data=Binary(content), |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
71 |
data_format=u'text/plain', |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
72 |
data_name=u'foo.pdf') |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
73 |
|
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
74 |
def fspath(self, cnx, entity): |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
75 |
fspath = cnx.execute('Any fspath(D) WHERE F eid %(f)s, F data D', |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
76 |
{'f': entity.eid})[0][0] |
5183
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
77 |
return fspath.getvalue() |
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
78 |
|
6788
0f31ed3fff79
[bfss storage] Improve fspath() error message.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6383
diff
changeset
|
79 |
def test_bfss_wrong_fspath_usage(self): |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
80 |
with self.admin_access.repo_cnx() as cnx: |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
81 |
f1 = self.create_file(cnx) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
82 |
cnx.execute('Any fspath(D) WHERE F eid %(f)s, F data D', {'f': f1.eid}) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
83 |
with self.assertRaises(NotImplementedError) as cm: |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
84 |
cnx.execute('Any fspath(F) WHERE F eid %(f)s', {'f': f1.eid}) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
85 |
self.assertEqual(str(cm.exception), |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
86 |
'This callback is only available for BytesFileSystemStorage ' |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
87 |
'managed attribute. Is FSPATH() argument BFSS managed?') |
6788
0f31ed3fff79
[bfss storage] Improve fspath() error message.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6383
diff
changeset
|
88 |
|
5008
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
89 |
def test_bfss_storage(self): |
10550
d4bd28d5fca8
[server/sources] make sure entity._cw is a Connection before calling Storages
Julien Cristau <julien.cristau@logilab.fr>
parents:
10453
diff
changeset
|
90 |
with self.admin_access.web_request() as req: |
d4bd28d5fca8
[server/sources] make sure entity._cw is a Connection before calling Storages
Julien Cristau <julien.cristau@logilab.fr>
parents:
10453
diff
changeset
|
91 |
cnx = req.cnx |
d4bd28d5fca8
[server/sources] make sure entity._cw is a Connection before calling Storages
Julien Cristau <julien.cristau@logilab.fr>
parents:
10453
diff
changeset
|
92 |
f1 = self.create_file(req) |
10453
76f601a90aa7
[storage] use mkstemp to create files in bfss
Julien Cristau <julien.cristau@logilab.fr>
parents:
9783
diff
changeset
|
93 |
filepaths = glob(osp.join(self.tempdir, '%s_data_*' % f1.eid)) |
76f601a90aa7
[storage] use mkstemp to create files in bfss
Julien Cristau <julien.cristau@logilab.fr>
parents:
9783
diff
changeset
|
94 |
self.assertEqual(len(filepaths), 1, filepaths) |
76f601a90aa7
[storage] use mkstemp to create files in bfss
Julien Cristau <julien.cristau@logilab.fr>
parents:
9783
diff
changeset
|
95 |
expected_filepath = filepaths[0] |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
96 |
# file should be read only |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
97 |
self.assertFalse(os.access(expected_filepath, os.W_OK)) |
10550
d4bd28d5fca8
[server/sources] make sure entity._cw is a Connection before calling Storages
Julien Cristau <julien.cristau@logilab.fr>
parents:
10453
diff
changeset
|
98 |
self.assertEqual(open(expected_filepath).read(), 'the-data') |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
99 |
cnx.rollback() |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
100 |
self.assertFalse(osp.isfile(expected_filepath)) |
10453
76f601a90aa7
[storage] use mkstemp to create files in bfss
Julien Cristau <julien.cristau@logilab.fr>
parents:
9783
diff
changeset
|
101 |
filepaths = glob(osp.join(self.tempdir, '%s_data_*' % f1.eid)) |
76f601a90aa7
[storage] use mkstemp to create files in bfss
Julien Cristau <julien.cristau@logilab.fr>
parents:
9783
diff
changeset
|
102 |
self.assertEqual(len(filepaths), 0, filepaths) |
10550
d4bd28d5fca8
[server/sources] make sure entity._cw is a Connection before calling Storages
Julien Cristau <julien.cristau@logilab.fr>
parents:
10453
diff
changeset
|
103 |
f1 = self.create_file(req) |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
104 |
cnx.commit() |
10453
76f601a90aa7
[storage] use mkstemp to create files in bfss
Julien Cristau <julien.cristau@logilab.fr>
parents:
9783
diff
changeset
|
105 |
filepaths = glob(osp.join(self.tempdir, '%s_data_*' % f1.eid)) |
76f601a90aa7
[storage] use mkstemp to create files in bfss
Julien Cristau <julien.cristau@logilab.fr>
parents:
9783
diff
changeset
|
106 |
self.assertEqual(len(filepaths), 1, filepaths) |
76f601a90aa7
[storage] use mkstemp to create files in bfss
Julien Cristau <julien.cristau@logilab.fr>
parents:
9783
diff
changeset
|
107 |
expected_filepath = filepaths[0] |
10550
d4bd28d5fca8
[server/sources] make sure entity._cw is a Connection before calling Storages
Julien Cristau <julien.cristau@logilab.fr>
parents:
10453
diff
changeset
|
108 |
self.assertEqual(open(expected_filepath).read(), 'the-data') |
d4bd28d5fca8
[server/sources] make sure entity._cw is a Connection before calling Storages
Julien Cristau <julien.cristau@logilab.fr>
parents:
10453
diff
changeset
|
109 |
|
d4bd28d5fca8
[server/sources] make sure entity._cw is a Connection before calling Storages
Julien Cristau <julien.cristau@logilab.fr>
parents:
10453
diff
changeset
|
110 |
# add f1 back to the entity cache with req as _cw |
d4bd28d5fca8
[server/sources] make sure entity._cw is a Connection before calling Storages
Julien Cristau <julien.cristau@logilab.fr>
parents:
10453
diff
changeset
|
111 |
f1 = req.entity_from_eid(f1.eid) |
10704
73367a56ee41
[py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
112 |
f1.cw_set(data=Binary(b'the new data')) |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
113 |
cnx.rollback() |
10550
d4bd28d5fca8
[server/sources] make sure entity._cw is a Connection before calling Storages
Julien Cristau <julien.cristau@logilab.fr>
parents:
10453
diff
changeset
|
114 |
self.assertEqual(open(expected_filepath).read(), 'the-data') |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
115 |
f1.cw_delete() |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
116 |
self.assertTrue(osp.isfile(expected_filepath)) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
117 |
cnx.rollback() |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
118 |
self.assertTrue(osp.isfile(expected_filepath)) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
119 |
f1.cw_delete() |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
120 |
cnx.commit() |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
121 |
self.assertFalse(osp.isfile(expected_filepath)) |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
122 |
|
5008
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
123 |
def test_bfss_sqlite_fspath(self): |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
124 |
with self.admin_access.repo_cnx() as cnx: |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
125 |
f1 = self.create_file(cnx) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
126 |
expected_filepath = osp.join(self.tempdir, '%s_data_%s' % (f1.eid, f1.data_name)) |
10453
76f601a90aa7
[storage] use mkstemp to create files in bfss
Julien Cristau <julien.cristau@logilab.fr>
parents:
9783
diff
changeset
|
127 |
base, ext = osp.splitext(expected_filepath) |
76f601a90aa7
[storage] use mkstemp to create files in bfss
Julien Cristau <julien.cristau@logilab.fr>
parents:
9783
diff
changeset
|
128 |
self.assertTrue(self.fspath(cnx, f1).startswith(base)) |
76f601a90aa7
[storage] use mkstemp to create files in bfss
Julien Cristau <julien.cristau@logilab.fr>
parents:
9783
diff
changeset
|
129 |
self.assertTrue(self.fspath(cnx, f1).endswith(ext)) |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
130 |
|
5008
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
131 |
def test_bfss_fs_importing_doesnt_touch_path(self): |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
132 |
with self.admin_access.repo_cnx() as cnx: |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
133 |
cnx.transaction_data['fs_importing'] = True |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
134 |
filepath = osp.abspath(__file__) |
10704
73367a56ee41
[py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
135 |
f1 = cnx.create_entity('File', data=Binary(filepath.encode(sys.getfilesystemencoding())), |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
136 |
data_format=u'text/plain', data_name=u'foo') |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
137 |
self.assertEqual(self.fspath(cnx, f1), filepath) |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
138 |
|
5008
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
139 |
def test_source_storage_transparency(self): |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
140 |
with self.admin_access.repo_cnx() as cnx: |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
141 |
with self.temporary_appobjects(DummyBeforeHook, DummyAfterHook): |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
142 |
self.create_file(cnx) |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
143 |
|
5013
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5008
diff
changeset
|
144 |
def test_source_mapped_attribute_error_cases(self): |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
145 |
with self.admin_access.repo_cnx() as cnx: |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
146 |
with self.assertRaises(QueryError) as cm: |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
147 |
cnx.execute('Any X WHERE X data ~= "hop", X is File') |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
148 |
self.assertEqual(str(cm.exception), 'can\'t use File.data (X data ILIKE "hop") in restriction') |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
149 |
with self.assertRaises(QueryError) as cm: |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
150 |
cnx.execute('Any X, Y WHERE X data D, Y data D, ' |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
151 |
'NOT X identity Y, X is File, Y is File') |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
152 |
self.assertEqual(str(cm.exception), "can't use D as a restriction variable") |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
153 |
# query returning mix of mapped / regular attributes (only file.data |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
154 |
# mapped, not image.data for instance) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
155 |
with self.assertRaises(QueryError) as cm: |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
156 |
cnx.execute('Any X WITH X BEING (' |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
157 |
' (Any NULL)' |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
158 |
' UNION ' |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
159 |
' (Any D WHERE X data D, X is File)' |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
160 |
')') |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
161 |
self.assertEqual(str(cm.exception), 'query fetch some source mapped attribute, some not') |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
162 |
with self.assertRaises(QueryError) as cm: |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
163 |
cnx.execute('(Any D WHERE X data D, X is File)' |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
164 |
' UNION ' |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
165 |
'(Any D WHERE X title D, X is Bookmark)') |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
166 |
self.assertEqual(str(cm.exception), 'query fetch some source mapped attribute, some not') |
5717
3c281b6f16c6
[3.9] fix tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5627
diff
changeset
|
167 |
|
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
168 |
storages.set_attribute_storage(self.repo, 'State', 'name', |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
169 |
storages.BytesFileSystemStorage(self.tempdir)) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
170 |
try: |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
171 |
with self.assertRaises(QueryError) as cm: |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
172 |
cnx.execute('Any D WHERE X name D, X is IN (State, Transition)') |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
173 |
self.assertEqual(str(cm.exception), 'query fetch some source mapped attribute, some not') |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
174 |
finally: |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
175 |
storages.unset_attribute_storage(self.repo, 'State', 'name') |
5013
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5008
diff
changeset
|
176 |
|
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5008
diff
changeset
|
177 |
def test_source_mapped_attribute_advanced(self): |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
178 |
with self.admin_access.repo_cnx() as cnx: |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
179 |
f1 = self.create_file(cnx) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
180 |
rset = cnx.execute('Any X,D WITH D,X BEING (' |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
181 |
' (Any D, X WHERE X eid %(x)s, X data D)' |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
182 |
' UNION ' |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
183 |
' (Any D, X WHERE X eid %(x)s, X data D)' |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
184 |
')', {'x': f1.eid}) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
185 |
self.assertEqual(len(rset), 2) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
186 |
self.assertEqual(rset[0][0], f1.eid) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
187 |
self.assertEqual(rset[1][0], f1.eid) |
10705
e7eafadbeb15
[py3k] Binary.getvalue() returns bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
188 |
self.assertEqual(rset[0][1].getvalue(), b'the-data') |
e7eafadbeb15
[py3k] Binary.getvalue() returns bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
189 |
self.assertEqual(rset[1][1].getvalue(), b'the-data') |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
190 |
rset = cnx.execute('Any X,LENGTH(D) WHERE X eid %(x)s, X data D', |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
191 |
{'x': f1.eid}) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
192 |
self.assertEqual(len(rset), 1) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
193 |
self.assertEqual(rset[0][0], f1.eid) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
194 |
self.assertEqual(rset[0][1], len('the-data')) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
195 |
rset = cnx.execute('Any X,LENGTH(D) WITH D,X BEING (' |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
196 |
' (Any D, X WHERE X eid %(x)s, X data D)' |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
197 |
' UNION ' |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
198 |
' (Any D, X WHERE X eid %(x)s, X data D)' |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
199 |
')', {'x': f1.eid}) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
200 |
self.assertEqual(len(rset), 2) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
201 |
self.assertEqual(rset[0][0], f1.eid) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
202 |
self.assertEqual(rset[1][0], f1.eid) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
203 |
self.assertEqual(rset[0][1], len('the-data')) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
204 |
self.assertEqual(rset[1][1], len('the-data')) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
205 |
with self.assertRaises(QueryError) as cm: |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
206 |
cnx.execute('Any X,UPPER(D) WHERE X eid %(x)s, X data D', |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
207 |
{'x': f1.eid}) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
208 |
self.assertEqual(str(cm.exception), 'UPPER can not be called on mapped attribute') |
5013
ad91f93bbb93
[source storage] refactor source sql generation and results handling to allow repository side callbacks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5008
diff
changeset
|
209 |
|
5131
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
210 |
|
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
211 |
def test_bfss_fs_importing_transparency(self): |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
212 |
with self.admin_access.repo_cnx() as cnx: |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
213 |
cnx.transaction_data['fs_importing'] = True |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
214 |
filepath = osp.abspath(__file__) |
10704
73367a56ee41
[py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
215 |
f1 = cnx.create_entity('File', data=Binary(filepath.encode(sys.getfilesystemencoding())), |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
216 |
data_format=u'text/plain', data_name=u'foo') |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
217 |
cw_value = f1.data.getvalue() |
10705
e7eafadbeb15
[py3k] Binary.getvalue() returns bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
218 |
fs_value = open(filepath, 'rb').read() |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
219 |
if cw_value != fs_value: |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
220 |
self.fail('cw value %r is different from file content' % cw_value) |
5131
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
221 |
|
6382
4efd0f07fd53
[test] improve tag for server/test/unittest_storage.py
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6340
diff
changeset
|
222 |
@tag('update') |
5131
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
223 |
def test_bfss_update_with_existing_data(self): |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
224 |
with self.admin_access.repo_cnx() as cnx: |
10704
73367a56ee41
[py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
225 |
f1 = cnx.create_entity('File', data=Binary(b'some data'), |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
226 |
data_format=u'text/plain', data_name=u'foo') |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
227 |
# NOTE: do not use cw_set() which would automatically |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
228 |
# update f1's local dict. We want the pure rql version to work |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
229 |
cnx.execute('SET F data %(d)s WHERE F eid %(f)s', |
10704
73367a56ee41
[py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
230 |
{'d': Binary(b'some other data'), 'f': f1.eid}) |
10705
e7eafadbeb15
[py3k] Binary.getvalue() returns bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
231 |
self.assertEqual(f1.data.getvalue(), b'some other data') |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
232 |
cnx.commit() |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
233 |
f2 = cnx.execute('Any F WHERE F eid %(f)s, F is File', {'f': f1.eid}).get_entity(0, 0) |
10705
e7eafadbeb15
[py3k] Binary.getvalue() returns bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
234 |
self.assertEqual(f2.data.getvalue(), b'some other data') |
5131
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
235 |
|
6382
4efd0f07fd53
[test] improve tag for server/test/unittest_storage.py
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6340
diff
changeset
|
236 |
@tag('update', 'extension', 'commit') |
5599
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
237 |
def test_bfss_update_with_different_extension_commited(self): |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
238 |
with self.admin_access.repo_cnx() as cnx: |
10704
73367a56ee41
[py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
239 |
f1 = cnx.create_entity('File', data=Binary(b'some data'), |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
240 |
data_format=u'text/plain', data_name=u'foo.txt') |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
241 |
# NOTE: do not use cw_set() which would automatically |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
242 |
# update f1's local dict. We want the pure rql version to work |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
243 |
cnx.commit() |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
244 |
old_path = self.fspath(cnx, f1) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
245 |
self.assertTrue(osp.isfile(old_path)) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
246 |
self.assertEqual(osp.splitext(old_path)[1], '.txt') |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
247 |
cnx.execute('SET F data %(d)s, F data_name %(dn)s, ' |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
248 |
'F data_format %(df)s WHERE F eid %(f)s', |
10704
73367a56ee41
[py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
249 |
{'d': Binary(b'some other data'), 'f': f1.eid, |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
250 |
'dn': u'bar.jpg', 'df': u'image/jpeg'}) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
251 |
cnx.commit() |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
252 |
# the new file exists with correct extension |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
253 |
# the old file is dead |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
254 |
f2 = cnx.execute('Any F WHERE F eid %(f)s, F is File', {'f': f1.eid}).get_entity(0, 0) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
255 |
new_path = self.fspath(cnx, f2) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
256 |
self.assertFalse(osp.isfile(old_path)) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
257 |
self.assertTrue(osp.isfile(new_path)) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
258 |
self.assertEqual(osp.splitext(new_path)[1], '.jpg') |
5599
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
259 |
|
6382
4efd0f07fd53
[test] improve tag for server/test/unittest_storage.py
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6340
diff
changeset
|
260 |
@tag('update', 'extension', 'rollback') |
9267
24d9b86dfa54
spelling: rollbacked -> rolled back
Rémi Cardona <remi.cardona@logilab.fr>
parents:
8694
diff
changeset
|
261 |
def test_bfss_update_with_different_extension_rolled_back(self): |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
262 |
with self.admin_access.repo_cnx() as cnx: |
10704
73367a56ee41
[py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
263 |
f1 = cnx.create_entity('File', data=Binary(b'some data'), |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
264 |
data_format=u'text/plain', data_name=u'foo.txt') |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
265 |
# NOTE: do not use cw_set() which would automatically |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
266 |
# update f1's local dict. We want the pure rql version to work |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
267 |
cnx.commit() |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
268 |
old_path = self.fspath(cnx, f1) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
269 |
old_data = f1.data.getvalue() |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
270 |
self.assertTrue(osp.isfile(old_path)) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
271 |
self.assertEqual(osp.splitext(old_path)[1], '.txt') |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
272 |
cnx.execute('SET F data %(d)s, F data_name %(dn)s, ' |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
273 |
'F data_format %(df)s WHERE F eid %(f)s', |
10704
73367a56ee41
[py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
274 |
{'d': Binary(b'some other data'), |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
275 |
'f': f1.eid, |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
276 |
'dn': u'bar.jpg', |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
277 |
'df': u'image/jpeg'}) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
278 |
cnx.rollback() |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
279 |
# the new file exists with correct extension |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
280 |
# the old file is dead |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
281 |
f2 = cnx.execute('Any F WHERE F eid %(f)s, F is File', |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
282 |
{'f': f1.eid}).get_entity(0, 0) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
283 |
new_path = self.fspath(cnx, f2) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
284 |
new_data = f2.data.getvalue() |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
285 |
self.assertTrue(osp.isfile(new_path)) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
286 |
self.assertEqual(osp.splitext(new_path)[1], '.txt') |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
287 |
self.assertEqual(old_path, new_path) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
288 |
self.assertEqual(old_data, new_data) |
5131
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
289 |
|
7694
bd56a29acaa8
[bfss] Fix update of BFSS attribute to None (close #1875289)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7057
diff
changeset
|
290 |
@tag('update', 'NULL') |
bd56a29acaa8
[bfss] Fix update of BFSS attribute to None (close #1875289)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7057
diff
changeset
|
291 |
def test_bfss_update_to_None(self): |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
292 |
with self.admin_access.repo_cnx() as cnx: |
10704
73367a56ee41
[py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
293 |
f = cnx.create_entity('Affaire', opt_attr=Binary(b'toto')) |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
294 |
cnx.commit() |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
295 |
f.cw_set(opt_attr=None) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
296 |
cnx.commit() |
7694
bd56a29acaa8
[bfss] Fix update of BFSS attribute to None (close #1875289)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7057
diff
changeset
|
297 |
|
6382
4efd0f07fd53
[test] improve tag for server/test/unittest_storage.py
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6340
diff
changeset
|
298 |
@tag('fs_importing', 'update') |
5183
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
299 |
def test_bfss_update_with_fs_importing(self): |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
300 |
with self.admin_access.repo_cnx() as cnx: |
10704
73367a56ee41
[py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
301 |
f1 = cnx.create_entity('File', data=Binary(b'some data'), |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
302 |
data_format=u'text/plain', |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
303 |
data_name=u'foo') |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
304 |
old_fspath = self.fspath(cnx, f1) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
305 |
cnx.transaction_data['fs_importing'] = True |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
306 |
new_fspath = osp.join(self.tempdir, 'newfile.txt') |
10614
57dfde80df11
[py3k] file → open
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10550
diff
changeset
|
307 |
open(new_fspath, 'w').write('the new data') |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
308 |
cnx.execute('SET F data %(d)s WHERE F eid %(f)s', |
10704
73367a56ee41
[py3k] ensure Binary objects are initialized with bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
309 |
{'d': Binary(new_fspath.encode(sys.getfilesystemencoding())), 'f': f1.eid}) |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
310 |
cnx.commit() |
10705
e7eafadbeb15
[py3k] Binary.getvalue() returns bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10704
diff
changeset
|
311 |
self.assertEqual(f1.data.getvalue(), b'the new data') |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
312 |
self.assertEqual(self.fspath(cnx, f1), new_fspath) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
313 |
self.assertFalse(osp.isfile(old_fspath)) |
5183
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
314 |
|
6383
19ebe0b994d6
Add a fsimport context manage to localy enable fsimporting.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6382
diff
changeset
|
315 |
@tag('fsimport') |
19ebe0b994d6
Add a fsimport context manage to localy enable fsimporting.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6382
diff
changeset
|
316 |
def test_clean(self): |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
317 |
with self.admin_access.repo_cnx() as cnx: |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
318 |
fsimport = storages.fsimport |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
319 |
td = cnx.transaction_data |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
320 |
self.assertNotIn('fs_importing', td) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
321 |
with fsimport(cnx): |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
322 |
self.assertIn('fs_importing', td) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
323 |
self.assertTrue(td['fs_importing']) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
324 |
self.assertNotIn('fs_importing', td) |
6383
19ebe0b994d6
Add a fsimport context manage to localy enable fsimporting.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6382
diff
changeset
|
325 |
|
19ebe0b994d6
Add a fsimport context manage to localy enable fsimporting.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6382
diff
changeset
|
326 |
@tag('fsimport') |
19ebe0b994d6
Add a fsimport context manage to localy enable fsimporting.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6382
diff
changeset
|
327 |
def test_true(self): |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
328 |
with self.admin_access.repo_cnx() as cnx: |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
329 |
fsimport = storages.fsimport |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
330 |
td = cnx.transaction_data |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
331 |
td['fs_importing'] = True |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
332 |
with fsimport(cnx): |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
333 |
self.assertIn('fs_importing', td) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
334 |
self.assertTrue(td['fs_importing']) |
6383
19ebe0b994d6
Add a fsimport context manage to localy enable fsimporting.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6382
diff
changeset
|
335 |
self.assertTrue(td['fs_importing']) |
19ebe0b994d6
Add a fsimport context manage to localy enable fsimporting.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6382
diff
changeset
|
336 |
|
19ebe0b994d6
Add a fsimport context manage to localy enable fsimporting.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6382
diff
changeset
|
337 |
@tag('fsimport') |
19ebe0b994d6
Add a fsimport context manage to localy enable fsimporting.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6382
diff
changeset
|
338 |
def test_False(self): |
9783
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
339 |
with self.admin_access.repo_cnx() as cnx: |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
340 |
fsimport = storages.fsimport |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
341 |
td = cnx.transaction_data |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
342 |
td['fs_importing'] = False |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
343 |
with fsimport(cnx): |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
344 |
self.assertIn('fs_importing', td) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
345 |
self.assertTrue(td['fs_importing']) |
59c582ce68c8
[tests/storage] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9267
diff
changeset
|
346 |
self.assertFalse(td['fs_importing']) |
5183
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
347 |
|
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
348 |
if __name__ == '__main__': |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
349 |
unittest_main() |