author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 01 Oct 2010 17:27:54 +0200 | |
changeset 6384 | 89d5b339ebdd |
parent 6340 | 470d8e828fda |
child 6382 | 4efd0f07fd53 |
permissions | -rw-r--r-- |
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
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
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 |
|
5109
5cf83b9356d5
[test] use the new temporary_appojects CM to simplfy unittest_storage
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5013
diff
changeset
|
20 |
from __future__ import with_statement |
5cf83b9356d5
[test] use the new temporary_appojects CM to simplfy unittest_storage
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5013
diff
changeset
|
21 |
|
5599
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
22 |
from logilab.common.testlib import unittest_main, tag |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
23 |
from cubicweb.devtools.testlib import CubicWebTC |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
24 |
|
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 |
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
|
30 |
from cubicweb.selectors 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 |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
32 |
from cubicweb.server.hook import Hook, Operation |
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): |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
54 |
|
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
55 |
def setup_database(self): |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
56 |
self.tempdir = tempfile.mkdtemp() |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
57 |
bfs_storage = storages.BytesFileSystemStorage(self.tempdir) |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
58 |
storages.set_attribute_storage(self.repo, 'File', 'data', bfs_storage) |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
59 |
|
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
60 |
def tearDown(self): |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
61 |
super(CubicWebTC, self).tearDown() |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
62 |
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
|
63 |
shutil.rmtree(self.tempdir) |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
64 |
|
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
65 |
|
5008
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
66 |
def create_file(self, content='the-data'): |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
67 |
req = self.request() |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
68 |
return req.create_entity('File', data=Binary(content), |
5240
2af0427e8ead
[tests] fix bfss tests to match new uniquify implementation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5183
diff
changeset
|
69 |
data_format=u'text/plain', data_name=u'foo.pdf') |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
70 |
|
5183
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
71 |
def fspath(self, entity): |
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
72 |
fspath = self.execute('Any fspath(D) WHERE F eid %(f)s, F data D', |
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
73 |
{'f': entity.eid})[0][0] |
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
74 |
return fspath.getvalue() |
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
75 |
|
5008
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
76 |
def test_bfss_storage(self): |
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
77 |
f1 = self.create_file() |
5240
2af0427e8ead
[tests] fix bfss tests to match new uniquify implementation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5183
diff
changeset
|
78 |
expected_filepath = osp.join(self.tempdir, '%s_data_%s' % |
2af0427e8ead
[tests] fix bfss tests to match new uniquify implementation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5183
diff
changeset
|
79 |
(f1.eid, f1.data_name)) |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
80 |
self.failUnless(osp.isfile(expected_filepath)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
81 |
self.assertEqual(file(expected_filepath).read(), 'the-data') |
5008
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
82 |
self.rollback() |
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
83 |
self.failIf(osp.isfile(expected_filepath)) |
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
84 |
f1 = self.create_file() |
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
85 |
self.commit() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
86 |
self.assertEqual(file(expected_filepath).read(), 'the-data') |
5008
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
87 |
f1.set_attributes(data=Binary('the new data')) |
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
88 |
self.rollback() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
89 |
self.assertEqual(file(expected_filepath).read(), 'the-data') |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
90 |
f1.cw_delete() |
5008
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
91 |
self.failUnless(osp.isfile(expected_filepath)) |
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
92 |
self.rollback() |
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
93 |
self.failUnless(osp.isfile(expected_filepath)) |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
94 |
f1.cw_delete() |
5008
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
95 |
self.commit() |
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
96 |
self.failIf(osp.isfile(expected_filepath)) |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
97 |
|
5008
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
98 |
def test_bfss_sqlite_fspath(self): |
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
99 |
f1 = self.create_file() |
5240
2af0427e8ead
[tests] fix bfss tests to match new uniquify implementation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5183
diff
changeset
|
100 |
expected_filepath = osp.join(self.tempdir, '%s_data_%s' % (f1.eid, f1.data_name)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
101 |
self.assertEqual(self.fspath(f1), expected_filepath) |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
102 |
|
5008
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
103 |
def test_bfss_fs_importing_doesnt_touch_path(self): |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
104 |
self.session.transaction_data['fs_importing'] = True |
5131
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
105 |
filepath = osp.abspath(__file__) |
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
106 |
f1 = self.session.create_entity('File', data=Binary(filepath), |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
107 |
data_format=u'text/plain', data_name=u'foo') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
108 |
self.assertEqual(self.fspath(f1), filepath) |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
109 |
|
5008
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
110 |
def test_source_storage_transparency(self): |
5109
5cf83b9356d5
[test] use the new temporary_appojects CM to simplfy unittest_storage
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5013
diff
changeset
|
111 |
with self.temporary_appobjects(DummyBeforeHook, DummyAfterHook): |
5008
385bf22e3c12
[bfss test] some minor refactoring. Test deletion + creation/update/deletion rollback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4967
diff
changeset
|
112 |
self.create_file() |
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
113 |
|
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
|
114 |
def test_source_mapped_attribute_error_cases(self): |
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
|
115 |
ex = self.assertRaises(QueryError, self.execute, |
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
|
116 |
'Any X WHERE X data ~= "hop", X is File') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
117 |
self.assertEqual(str(ex), 'can\'t use File.data (X data ILIKE "hop") in restriction') |
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
|
118 |
ex = self.assertRaises(QueryError, self.execute, |
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
|
119 |
'Any X, Y WHERE X data D, Y data D, ' |
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
|
120 |
'NOT X identity Y, X is File, Y is File') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
121 |
self.assertEqual(str(ex), "can't use D as a restriction variable") |
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
|
122 |
# query returning mix of mapped / regular attributes (only file.data |
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
|
123 |
# mapped, not image.data for instance) |
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
|
124 |
ex = self.assertRaises(QueryError, self.execute, |
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
|
125 |
'Any X WITH X BEING (' |
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
|
126 |
' (Any NULL)' |
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
|
127 |
' UNION ' |
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
|
128 |
' (Any D WHERE X data D, X is File)' |
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
|
129 |
')') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
130 |
self.assertEqual(str(ex), 'query fetch some source mapped attribute, some not') |
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
|
131 |
ex = self.assertRaises(QueryError, self.execute, |
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
|
132 |
'(Any D WHERE X data D, X is File)' |
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
|
133 |
' UNION ' |
5575
8a531340c3ef
no more Image type w/ cw 3.9
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
134 |
'(Any D WHERE X title D, X is Bookmark)') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
135 |
self.assertEqual(str(ex), '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
|
136 |
|
3c281b6f16c6
[3.9] fix tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5627
diff
changeset
|
137 |
storages.set_attribute_storage(self.repo, 'State', 'name', |
3c281b6f16c6
[3.9] fix tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5627
diff
changeset
|
138 |
storages.BytesFileSystemStorage(self.tempdir)) |
3c281b6f16c6
[3.9] fix tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5627
diff
changeset
|
139 |
try: |
3c281b6f16c6
[3.9] fix tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5627
diff
changeset
|
140 |
ex = self.assertRaises(QueryError, |
3c281b6f16c6
[3.9] fix tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5627
diff
changeset
|
141 |
self.execute, 'Any D WHERE X name D, X is IN (State, Transition)') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
142 |
self.assertEqual(str(ex), '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
|
143 |
finally: |
3c281b6f16c6
[3.9] fix tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5627
diff
changeset
|
144 |
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
|
145 |
|
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
|
146 |
def test_source_mapped_attribute_advanced(self): |
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
|
147 |
f1 = self.create_file() |
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
|
148 |
rset = self.execute('Any X,D WITH D,X BEING (' |
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
|
149 |
' (Any D, X WHERE X eid %(x)s, X data D)' |
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
|
150 |
' UNION ' |
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
|
151 |
' (Any D, X WHERE X eid %(x)s, X data D)' |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5131
diff
changeset
|
152 |
')', {'x': f1.eid}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
153 |
self.assertEqual(len(rset), 2) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
154 |
self.assertEqual(rset[0][0], f1.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
155 |
self.assertEqual(rset[1][0], f1.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
156 |
self.assertEqual(rset[0][1].getvalue(), 'the-data') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
157 |
self.assertEqual(rset[1][1].getvalue(), 'the-data') |
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
|
158 |
rset = self.execute('Any X,LENGTH(D) WHERE X eid %(x)s, X data D', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5131
diff
changeset
|
159 |
{'x': f1.eid}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
160 |
self.assertEqual(len(rset), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
161 |
self.assertEqual(rset[0][0], f1.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
162 |
self.assertEqual(rset[0][1], len('the-data')) |
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
|
163 |
rset = self.execute('Any X,LENGTH(D) WITH D,X BEING (' |
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
|
164 |
' (Any D, X WHERE X eid %(x)s, X data D)' |
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
|
165 |
' UNION ' |
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
|
166 |
' (Any D, X WHERE X eid %(x)s, X data D)' |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5131
diff
changeset
|
167 |
')', {'x': f1.eid}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
168 |
self.assertEqual(len(rset), 2) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
169 |
self.assertEqual(rset[0][0], f1.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
170 |
self.assertEqual(rset[1][0], f1.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
171 |
self.assertEqual(rset[0][1], len('the-data')) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
172 |
self.assertEqual(rset[1][1], len('the-data')) |
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
|
173 |
ex = self.assertRaises(QueryError, self.execute, |
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
|
174 |
'Any X,UPPER(D) WHERE X eid %(x)s, X data D', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5131
diff
changeset
|
175 |
{'x': f1.eid}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
176 |
self.assertEqual(str(ex), '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
|
177 |
|
5131
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
178 |
|
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
179 |
def test_bfss_fs_importing_transparency(self): |
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
180 |
self.session.transaction_data['fs_importing'] = True |
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
181 |
filepath = osp.abspath(__file__) |
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
182 |
f1 = self.session.create_entity('File', data=Binary(filepath), |
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
183 |
data_format=u'text/plain', data_name=u'foo') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
184 |
self.assertEqual(f1.data.getvalue(), file(filepath).read(), |
5131
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
185 |
'files content differ') |
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
186 |
|
5599
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
187 |
@tag('Storage', 'BFSS', 'update') |
5131
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
188 |
def test_bfss_update_with_existing_data(self): |
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
189 |
# use self.session to use server-side cache |
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
190 |
f1 = self.session.create_entity('File', data=Binary('some data'), |
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
191 |
data_format=u'text/plain', data_name=u'foo') |
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
192 |
# NOTE: do not use set_attributes() which would automatically |
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
193 |
# update f1's local dict. We want the pure rql version to work |
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
194 |
self.execute('SET F data %(d)s WHERE F eid %(f)s', |
88b5ca8da928
[storages] fix fs_importing side-effect on entity.data
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5109
diff
changeset
|
195 |
{'d': Binary('some other data'), 'f': f1.eid}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
196 |
self.assertEqual(f1.data.getvalue(), '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
|
197 |
self.commit() |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5131
diff
changeset
|
198 |
f2 = self.execute('Any F WHERE F eid %(f)s, F is File', {'f': f1.eid}).get_entity(0, 0) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
199 |
self.assertEqual(f2.data.getvalue(), '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
|
200 |
|
5599
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
201 |
@tag('Storage', 'BFSS', 'update', 'extension', 'commit') |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
202 |
def test_bfss_update_with_different_extension_commited(self): |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
203 |
# use self.session to use server-side cache |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
204 |
f1 = self.session.create_entity('File', data=Binary('some data'), |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
205 |
data_format=u'text/plain', data_name=u'foo.txt') |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
206 |
# NOTE: do not use set_attributes() which would automatically |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
207 |
# update f1's local dict. We want the pure rql version to work |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
208 |
self.commit() |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
209 |
old_path = self.fspath(f1) |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
210 |
self.failUnless(osp.isfile(old_path)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
211 |
self.assertEqual(osp.splitext(old_path)[1], '.txt') |
5599
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
212 |
self.execute('SET F data %(d)s, F data_name %(dn)s, F data_format %(df)s WHERE F eid %(f)s', |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
213 |
{'d': Binary('some other data'), 'f': f1.eid, 'dn': u'bar.jpg', 'df': u'image/jpeg'}) |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
214 |
self.commit() |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
215 |
# the new file exists with correct extension |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
216 |
# the old file is dead |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
217 |
f2 = self.execute('Any F WHERE F eid %(f)s, F is File', {'f': f1.eid}).get_entity(0, 0) |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
218 |
new_path = self.fspath(f2) |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
219 |
self.failIf(osp.isfile(old_path)) |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
220 |
self.failUnless(osp.isfile(new_path)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
221 |
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
|
222 |
|
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
223 |
@tag('Storage', 'BFSS', 'update', 'extension', 'rollback') |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
224 |
def test_bfss_update_with_different_extension_rollbacked(self): |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
225 |
# use self.session to use server-side cache |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
226 |
f1 = self.session.create_entity('File', data=Binary('some data'), |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
227 |
data_format=u'text/plain', data_name=u'foo.txt') |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
228 |
# NOTE: do not use set_attributes() which would automatically |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
229 |
# update f1's local dict. We want the pure rql version to work |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
230 |
self.commit() |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
231 |
old_path = self.fspath(f1) |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
232 |
old_data = f1.data.getvalue() |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
233 |
self.failUnless(osp.isfile(old_path)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
234 |
self.assertEqual(osp.splitext(old_path)[1], '.txt') |
5599
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
235 |
self.execute('SET F data %(d)s, F data_name %(dn)s, F data_format %(df)s WHERE F eid %(f)s', |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
236 |
{'d': Binary('some other data'), 'f': f1.eid, 'dn': u'bar.jpg', 'df': u'image/jpeg'}) |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
237 |
self.rollback() |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
238 |
# the new file exists with correct extension |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
239 |
# the old file is dead |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
240 |
f2 = self.execute('Any F WHERE F eid %(f)s, F is File', {'f': f1.eid}).get_entity(0, 0) |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
241 |
new_path = self.fspath(f2) |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
242 |
new_data = f2.data.getvalue() |
be94157bd754
[bfss] Rename filenames according to their metadata on entity update.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5426
diff
changeset
|
243 |
self.failUnless(osp.isfile(new_path)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
244 |
self.assertEqual(osp.splitext(new_path)[1], '.txt') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
245 |
self.assertEqual(old_path, new_path) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
246 |
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
|
247 |
|
5183
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
248 |
def test_bfss_update_with_fs_importing(self): |
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
249 |
# use self.session to use server-side cache |
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
250 |
f1 = self.session.create_entity('File', data=Binary('some data'), |
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
251 |
data_format=u'text/plain', data_name=u'foo') |
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
252 |
old_fspath = self.fspath(f1) |
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
253 |
self.session.transaction_data['fs_importing'] = True |
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
254 |
new_fspath = osp.join(self.tempdir, 'newfile.txt') |
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
255 |
file(new_fspath, 'w').write('the new data') |
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
256 |
self.execute('SET F data %(d)s WHERE F eid %(f)s', |
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
257 |
{'d': Binary(new_fspath), 'f': f1.eid}) |
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
258 |
self.commit() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
259 |
self.assertEqual(f1.data.getvalue(), 'the new data') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
260 |
self.assertEqual(self.fspath(f1), new_fspath) |
5183
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
261 |
self.failIf(osp.isfile(old_fspath)) |
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
262 |
|
8d66003351f8
[storage] consider fs_importing on update operations too
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5131
diff
changeset
|
263 |
|
4967
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
264 |
if __name__ == '__main__': |
236f1fde6dd0
[server] add unit tests for storages
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
265 |
unittest_main() |