author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 07 Mar 2011 17:15:06 +0100 | |
branch | stable |
changeset 7041 | 5a6fd60f7617 |
parent 7032 | b712477ae286 |
child 7056 | 51f88f13d6f3 |
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:
5267
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:
5267
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:
5267
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:
5267
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:
5267
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:
5267
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:
5267
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:
5267
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:
5267
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:
5267
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:
5267
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:
5267
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:
5267
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:
5267
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:
5267
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:
5267
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
6315
8ca3ee849bee
[test] fix broken tests and minor cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6281
diff
changeset
|
18 |
"""Test tools for cubicweb""" |
0 | 19 |
|
20 |
__docformat__ = "restructuredtext en" |
|
21 |
||
22 |
import os |
|
5754
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
23 |
import sys |
0 | 24 |
import logging |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
937
diff
changeset
|
25 |
from datetime import timedelta |
0 | 26 |
from os.path import (abspath, join, exists, basename, dirname, normpath, split, |
6749
48f468f33704
[config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6729
diff
changeset
|
27 |
isfile, isabs, splitext) |
0 | 28 |
|
4466
8b0ca7904820
moved generic datetime manipulation function to lgc
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4436
diff
changeset
|
29 |
from logilab.common.date import strptime |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
30 |
from cubicweb import CW_SOFTWARE_ROOT, ConfigurationError, schema, cwconfig |
0 | 31 |
from cubicweb.server.serverconfig import ServerConfiguration |
32 |
from cubicweb.etwist.twconfig import TwistedConfiguration |
|
33 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
34 |
cwconfig.CubicWebConfiguration.cls_adjust_sys_path() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
35 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
36 |
# db auto-population configuration ############################################# |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
37 |
|
6377
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
38 |
SYSTEM_ENTITIES = (schema.SCHEMA_TYPES |
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
39 |
| schema.INTERNAL_TYPES |
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
40 |
| schema.WORKFLOW_TYPES |
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
41 |
| set(('CWGroup', 'CWUser',)) |
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
42 |
) |
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
43 |
SYSTEM_RELATIONS = (schema.META_RTYPES |
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
44 |
| schema.WORKFLOW_RTYPES |
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
45 |
| schema.WORKFLOW_DEF_RTYPES |
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
46 |
| schema.SYSTEM_RTYPES |
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
47 |
| schema.SCHEMA_TYPES |
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
48 |
| set(('primary_email', # deducted from other relations |
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
49 |
)) |
3bb415310d4f
[schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
50 |
) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
51 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
52 |
# content validation configuration ############################################# |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
53 |
|
0 | 54 |
# validators are used to validate (XML, DTD, whatever) view's content |
55 |
# validators availables are : |
|
56 |
# 'dtd' : validates XML + declared DTD |
|
57 |
# 'xml' : guarantees XML is well formed |
|
58 |
# None : do not try to validate anything |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
59 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
60 |
# {'vid': validator} |
0 | 61 |
VIEW_VALIDATORS = {} |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
62 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
63 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
64 |
# cubicweb test configuration ################################################## |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
65 |
|
0 | 66 |
BASE_URL = 'http://testing.fr/cubicweb/' |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
67 |
|
0 | 68 |
DEFAULT_SOURCES = {'system': {'adapter' : 'native', |
69 |
'db-encoding' : 'UTF-8', #'ISO-8859-1', |
|
70 |
'db-user' : u'admin', |
|
71 |
'db-password' : 'gingkow', |
|
72 |
'db-name' : 'tmpdb', |
|
73 |
'db-driver' : 'sqlite', |
|
74 |
'db-host' : None, |
|
75 |
}, |
|
76 |
'admin' : {'login': u'admin', |
|
77 |
'password': u'gingkow', |
|
78 |
}, |
|
79 |
} |
|
80 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
81 |
|
0 | 82 |
class TestServerConfiguration(ServerConfiguration): |
83 |
mode = 'test' |
|
84 |
set_language = False |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1978
diff
changeset
|
85 |
read_instance_schema = False |
0 | 86 |
init_repository = True |
6164
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
87 |
db_require_setup = True |
7032
b712477ae286
[config] fix option group clash causing anonymous user configuration to end in the MAIN section instead of the WEB section if cubicweb-dev is installed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6843
diff
changeset
|
88 |
options = cwconfig.merge_options( |
b712477ae286
[config] fix option group clash causing anonymous user configuration to end in the MAIN section instead of the WEB section if cubicweb-dev is installed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6843
diff
changeset
|
89 |
ServerConfiguration.options + |
b712477ae286
[config] fix option group clash causing anonymous user configuration to end in the MAIN section instead of the WEB section if cubicweb-dev is installed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6843
diff
changeset
|
90 |
tuple((opt, optdict) for opt, optdict in TwistedConfiguration.options |
b712477ae286
[config] fix option group clash causing anonymous user configuration to end in the MAIN section instead of the WEB section if cubicweb-dev is installed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6843
diff
changeset
|
91 |
if opt in ('anonymous-user', 'anonymous-password'))) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
92 |
|
6585
9af22f2c0c4c
[test] start to make tests independant from cwd (more to do for tests which don't inherit from CubicWebTC
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6441
diff
changeset
|
93 |
def __init__(self, appid, apphome=None, log_threshold=logging.CRITICAL+10): |
9af22f2c0c4c
[test] start to make tests independant from cwd (more to do for tests which don't inherit from CubicWebTC
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6441
diff
changeset
|
94 |
# must be set before calling parent __init__ |
9af22f2c0c4c
[test] start to make tests independant from cwd (more to do for tests which don't inherit from CubicWebTC
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6441
diff
changeset
|
95 |
if apphome is None: |
6593
0fd8792c9c8a
[testlib] self.appid not yet defined
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6585
diff
changeset
|
96 |
if exists(appid): |
0fd8792c9c8a
[testlib] self.appid not yet defined
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6585
diff
changeset
|
97 |
apphome = abspath(appid) |
6585
9af22f2c0c4c
[test] start to make tests independant from cwd (more to do for tests which don't inherit from CubicWebTC
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6441
diff
changeset
|
98 |
else: # cube test |
9af22f2c0c4c
[test] start to make tests independant from cwd (more to do for tests which don't inherit from CubicWebTC
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6441
diff
changeset
|
99 |
apphome = abspath('..') |
9af22f2c0c4c
[test] start to make tests independant from cwd (more to do for tests which don't inherit from CubicWebTC
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6441
diff
changeset
|
100 |
self._apphome = apphome |
0 | 101 |
ServerConfiguration.__init__(self, appid) |
102 |
self.init_log(log_threshold, force=True) |
|
103 |
# need this, usually triggered by cubicweb-ctl |
|
104 |
self.load_cwctl_plugins() |
|
105 |
||
106 |
anonymous_user = TwistedConfiguration.anonymous_user.im_func |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
107 |
|
0 | 108 |
@property |
109 |
def apphome(self): |
|
6585
9af22f2c0c4c
[test] start to make tests independant from cwd (more to do for tests which don't inherit from CubicWebTC
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6441
diff
changeset
|
110 |
return self._apphome |
0 | 111 |
appdatahome = apphome |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
112 |
|
3435
84036ad2c82d
add anon user for TestServerConfiguration, no only AppTestConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3163
diff
changeset
|
113 |
def load_configuration(self): |
84036ad2c82d
add anon user for TestServerConfiguration, no only AppTestConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3163
diff
changeset
|
114 |
super(TestServerConfiguration, self).load_configuration() |
84036ad2c82d
add anon user for TestServerConfiguration, no only AppTestConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3163
diff
changeset
|
115 |
self.global_set_option('anonymous-user', 'anon') |
84036ad2c82d
add anon user for TestServerConfiguration, no only AppTestConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3163
diff
changeset
|
116 |
self.global_set_option('anonymous-password', 'anon') |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4761
diff
changeset
|
117 |
# no undo support in tests |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4761
diff
changeset
|
118 |
self.global_set_option('undo-support', '') |
3435
84036ad2c82d
add anon user for TestServerConfiguration, no only AppTestConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3163
diff
changeset
|
119 |
|
0 | 120 |
def main_config_file(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1978
diff
changeset
|
121 |
"""return instance's control configuration file""" |
0 | 122 |
return join(self.apphome, '%s.conf' % self.name) |
123 |
||
124 |
def bootstrap_cubes(self): |
|
125 |
try: |
|
126 |
super(TestServerConfiguration, self).bootstrap_cubes() |
|
127 |
except IOError: |
|
128 |
# no cubes |
|
129 |
self.init_cubes( () ) |
|
130 |
||
131 |
sourcefile = None |
|
132 |
def sources_file(self): |
|
133 |
"""define in subclasses self.sourcefile if necessary""" |
|
134 |
if self.sourcefile: |
|
135 |
print 'Reading sources from', self.sourcefile |
|
136 |
sourcefile = self.sourcefile |
|
137 |
if not isabs(sourcefile): |
|
138 |
sourcefile = join(self.apphome, sourcefile) |
|
139 |
else: |
|
140 |
sourcefile = super(TestServerConfiguration, self).sources_file() |
|
141 |
return sourcefile |
|
142 |
||
143 |
def sources(self): |
|
144 |
"""By default, we run tests with the sqlite DB backend. One may use its |
|
145 |
own configuration by just creating a 'sources' file in the test |
|
146 |
directory from wich tests are launched or by specifying an alternative |
|
147 |
sources file using self.sourcefile. |
|
148 |
""" |
|
149 |
sources = super(TestServerConfiguration, self).sources() |
|
150 |
if not sources: |
|
151 |
sources = DEFAULT_SOURCES |
|
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6425
diff
changeset
|
152 |
if 'admin' not in sources: |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6425
diff
changeset
|
153 |
sources['admin'] = DEFAULT_SOURCES['admin'] |
0 | 154 |
return sources |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
155 |
|
6441
adbce42ff1b5
TestServerConfig needs default_base_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
156 |
# web config methods needed here for cases when we use this config as a web |
adbce42ff1b5
TestServerConfig needs default_base_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
157 |
# config |
adbce42ff1b5
TestServerConfig needs default_base_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
158 |
|
adbce42ff1b5
TestServerConfig needs default_base_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
159 |
def instance_md5_version(self): |
adbce42ff1b5
TestServerConfig needs default_base_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
160 |
return '' |
adbce42ff1b5
TestServerConfig needs default_base_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
161 |
|
adbce42ff1b5
TestServerConfig needs default_base_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
162 |
def default_base_url(self): |
adbce42ff1b5
TestServerConfig needs default_base_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
163 |
return BASE_URL |
adbce42ff1b5
TestServerConfig needs default_base_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
164 |
|
0 | 165 |
|
166 |
class BaseApptestConfiguration(TestServerConfiguration, TwistedConfiguration): |
|
167 |
repo_method = 'inmemory' |
|
6843
b70a26ca271c
[devtools] set configuration name to all-in-one so test/data/all-in-one.conf file will be loaded as one may expected
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
168 |
name = 'all-in-one' # so it search for all-in-one.conf, not repository.conf |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
169 |
options = cwconfig.merge_options(TestServerConfiguration.options |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
170 |
+ TwistedConfiguration.options) |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
171 |
cubicweb_appobject_path = TestServerConfiguration.cubicweb_appobject_path | TwistedConfiguration.cubicweb_appobject_path |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
172 |
cube_appobject_path = TestServerConfiguration.cube_appobject_path | TwistedConfiguration.cube_appobject_path |
0 | 173 |
|
174 |
def available_languages(self, *args): |
|
6749
48f468f33704
[config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6729
diff
changeset
|
175 |
return self.cw_languages() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
176 |
|
0 | 177 |
def pyro_enabled(self): |
5754
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
178 |
# but export PYRO_MULTITHREAD=0 or you get problems with sqlite and |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
179 |
# threads |
0 | 180 |
return True |
181 |
||
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6315
diff
changeset
|
182 |
# XXX merge with BaseApptestConfiguration ? |
0 | 183 |
class ApptestConfiguration(BaseApptestConfiguration): |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
184 |
|
6585
9af22f2c0c4c
[test] start to make tests independant from cwd (more to do for tests which don't inherit from CubicWebTC
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6441
diff
changeset
|
185 |
def __init__(self, appid, apphome=None, |
9af22f2c0c4c
[test] start to make tests independant from cwd (more to do for tests which don't inherit from CubicWebTC
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6441
diff
changeset
|
186 |
log_threshold=logging.CRITICAL, sourcefile=None): |
9af22f2c0c4c
[test] start to make tests independant from cwd (more to do for tests which don't inherit from CubicWebTC
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6441
diff
changeset
|
187 |
BaseApptestConfiguration.__init__(self, appid, apphome, |
9af22f2c0c4c
[test] start to make tests independant from cwd (more to do for tests which don't inherit from CubicWebTC
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6441
diff
changeset
|
188 |
log_threshold=log_threshold) |
0 | 189 |
self.init_repository = sourcefile is None |
190 |
self.sourcefile = sourcefile |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
191 |
|
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6315
diff
changeset
|
192 |
|
6164
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
193 |
class RealDatabaseConfiguration(ApptestConfiguration): |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
194 |
"""configuration class for tests to run on a real database. |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
195 |
|
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
196 |
The intialization is done by specifying a source file path. |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
197 |
|
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
198 |
Important note: init_test_database / reset_test_database steps are |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
199 |
skipped. It's thus up to the test developer to implement setUp/tearDown |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
200 |
accordingly. |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
201 |
|
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
202 |
Example usage:: |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
203 |
|
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
204 |
class MyTests(CubicWebTC): |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
205 |
_config = RealDatabseConfiguration('myapp', |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
206 |
sourcefile='/path/to/sources') |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
207 |
def test_something(self): |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
208 |
rset = self.execute('Any X WHERE X is CWUser') |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
209 |
self.view('foaf', rset) |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
210 |
|
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
211 |
""" |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
212 |
db_require_setup = False # skip init_db / reset_db steps |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
213 |
read_instance_schema = True # read schema from database |
0 | 214 |
|
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6315
diff
changeset
|
215 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
216 |
# test database handling ####################################################### |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
217 |
|
6631
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6594
diff
changeset
|
218 |
def init_test_database(config=None, appid='data', apphome=None): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
219 |
"""init a test database for a specific driver""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
220 |
from cubicweb.dbapi import in_memory_cnx |
6631
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6594
diff
changeset
|
221 |
config = config or TestServerConfiguration(appid, apphome=apphome) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
222 |
sources = config.sources() |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
223 |
driver = sources['system']['db-driver'] |
6164
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
224 |
if config.db_require_setup: |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
225 |
if driver == 'sqlite': |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
226 |
init_test_database_sqlite(config) |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
227 |
elif driver == 'postgres': |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
228 |
init_test_database_postgres(config) |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
229 |
else: |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
230 |
raise ValueError('no initialization function for driver %r' % driver) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
231 |
config._cubes = None # avoid assertion error |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
232 |
repo, cnx = in_memory_cnx(config, unicode(sources['admin']['login']), |
3647
2941f4a0aab9
refactor repo authentication to allow pluggable authentifier to login with something else than a password
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3435
diff
changeset
|
233 |
password=sources['admin']['password'] or 'xxx') |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
234 |
if driver == 'sqlite': |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
235 |
install_sqlite_patch(repo.querier) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
236 |
return repo, cnx |
0 | 237 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
238 |
def reset_test_database(config): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
239 |
"""init a test database for a specific driver""" |
6164
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
240 |
if not config.db_require_setup: |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
241 |
return |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
242 |
driver = config.sources()['system']['db-driver'] |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
243 |
if driver == 'sqlite': |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
244 |
reset_test_database_sqlite(config) |
5754
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
245 |
elif driver == 'postgres': |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
246 |
init_test_database_postgres(config) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
247 |
else: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
248 |
raise ValueError('no reset function for driver %r' % driver) |
0 | 249 |
|
250 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
251 |
### postgres test database handling ############################################ |
0 | 252 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
253 |
def init_test_database_postgres(config): |
5166
1e96d01728c4
enable live test against sqlserver 2005 database
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5043
diff
changeset
|
254 |
"""initialize a fresh postgresql databse used for testing purpose""" |
5754
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
255 |
from logilab.database import get_db_helper |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
256 |
from cubicweb.server import init_repository |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
257 |
from cubicweb.server.serverctl import (createdb, system_source_cnx, |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
258 |
_db_sys_cnx) |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
259 |
source = config.sources()['system'] |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
260 |
dbname = source['db-name'] |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
261 |
templdbname = dbname + '_template' |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
262 |
helper = get_db_helper('postgres') |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
263 |
# connect on the dbms system base to create our base |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
264 |
dbcnx = _db_sys_cnx(source, 'CREATE DATABASE and / or USER', verbose=0) |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
265 |
cursor = dbcnx.cursor() |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
266 |
try: |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
267 |
if dbname in helper.list_databases(cursor): |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
268 |
cursor.execute('DROP DATABASE %s' % dbname) |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
269 |
if not templdbname in helper.list_databases(cursor): |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
270 |
source['db-name'] = templdbname |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
271 |
createdb(helper, source, dbcnx, cursor) |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
272 |
dbcnx.commit() |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
273 |
cnx = system_source_cnx(source, special_privs='LANGUAGE C', verbose=0) |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
274 |
templcursor = cnx.cursor() |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
275 |
# XXX factorize with db-create code |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
276 |
helper.init_fti_extensions(templcursor) |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
277 |
# install plpythonu/plpgsql language if not installed by the cube |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
278 |
langs = sys.platform == 'win32' and ('plpgsql',) or ('plpythonu', 'plpgsql') |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
279 |
for extlang in langs: |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
280 |
helper.create_language(templcursor, extlang) |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
281 |
cnx.commit() |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
282 |
templcursor.close() |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
283 |
cnx.close() |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
284 |
init_repository(config, interactive=False) |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
285 |
source['db-name'] = dbname |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
286 |
except: |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
287 |
dbcnx.rollback() |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
288 |
# XXX drop template |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
289 |
raise |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
290 |
createdb(helper, source, dbcnx, cursor, template=templdbname) |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
291 |
dbcnx.commit() |
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
292 |
dbcnx.close() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
293 |
|
5754
51179e0bb250
[test] support for test on postgres database using the same mecanism as sqlite: one template database generated when necessary + actual test database created from the template
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5696
diff
changeset
|
294 |
### sqlserver2005 test database handling ####################################### |
5166
1e96d01728c4
enable live test against sqlserver 2005 database
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5043
diff
changeset
|
295 |
|
1e96d01728c4
enable live test against sqlserver 2005 database
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5043
diff
changeset
|
296 |
def init_test_database_sqlserver2005(config): |
1e96d01728c4
enable live test against sqlserver 2005 database
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5043
diff
changeset
|
297 |
"""initialize a fresh sqlserver databse used for testing purpose""" |
5169
240e21b94a28
fixed indentation error in devtools/__init__.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5166
diff
changeset
|
298 |
if config.init_repository: |
240e21b94a28
fixed indentation error in devtools/__init__.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5166
diff
changeset
|
299 |
from cubicweb.server import init_repository |
5693
8af6623f3d4e
[pylint] fix detected name errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5541
diff
changeset
|
300 |
init_repository(config, interactive=False, drop=True) |
5212
a545eb9add6f
[testlib] fix dummy bug in reset_test_database(): s/if/elif
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5210
diff
changeset
|
301 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
302 |
### sqlite test database handling ############################################## |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
303 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
304 |
def cleanup_sqlite(dbfile, removetemplate=False): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
305 |
try: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
306 |
os.remove(dbfile) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
307 |
os.remove('%s-journal' % dbfile) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
308 |
except OSError: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
309 |
pass |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
310 |
if removetemplate: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
311 |
try: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
312 |
os.remove('%s-template' % dbfile) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
313 |
except OSError: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
314 |
pass |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
315 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
316 |
def reset_test_database_sqlite(config): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
317 |
import shutil |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
318 |
dbfile = config.sources()['system']['db-name'] |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
319 |
cleanup_sqlite(dbfile) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
320 |
template = '%s-template' % dbfile |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
321 |
if exists(template): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
322 |
shutil.copy(template, dbfile) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
323 |
return True |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
324 |
return False |
0 | 325 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
326 |
def init_test_database_sqlite(config): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
327 |
"""initialize a fresh sqlite databse used for testing purpose""" |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
328 |
# remove database file if it exists |
6631
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6594
diff
changeset
|
329 |
dbfile = join(config.apphome, config.sources()['system']['db-name']) |
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6594
diff
changeset
|
330 |
config.sources()['system']['db-name'] = dbfile |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
331 |
if not reset_test_database_sqlite(config): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
332 |
# initialize the database |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
333 |
import shutil |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
334 |
from cubicweb.server import init_repository |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
335 |
init_repository(config, interactive=False) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
336 |
shutil.copy(dbfile, '%s-template' % dbfile) |
0 | 337 |
|
2732 | 338 |
def install_sqlite_patch(querier): |
0 | 339 |
"""This patch hotfixes the following sqlite bug : |
298
3e6d32667140
[doc] Fix docstring indentation.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
0
diff
changeset
|
340 |
- http://www.sqlite.org/cvstrac/tktview?tn=1327,33 |
3e6d32667140
[doc] Fix docstring indentation.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
0
diff
changeset
|
341 |
(some dates are returned as strings rather thant date objects) |
0 | 342 |
""" |
937 | 343 |
if hasattr(querier.__class__, '_devtools_sqlite_patched'): |
344 |
return # already monkey patched |
|
0 | 345 |
def wrap_execute(base_execute): |
346 |
def new_execute(*args, **kwargs): |
|
347 |
rset = base_execute(*args, **kwargs) |
|
348 |
if rset.description: |
|
349 |
found_date = False |
|
350 |
for row, rowdesc in zip(rset, rset.description): |
|
351 |
for cellindex, (value, vtype) in enumerate(zip(row, rowdesc)): |
|
352 |
if vtype in ('Date', 'Datetime') and type(value) is unicode: |
|
353 |
found_date = True |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
937
diff
changeset
|
354 |
value = value.rsplit('.', 1)[0] |
0 | 355 |
try: |
356 |
row[cellindex] = strptime(value, '%Y-%m-%d %H:%M:%S') |
|
357 |
except: |
|
358 |
row[cellindex] = strptime(value, '%Y-%m-%d') |
|
359 |
if vtype == 'Time' and type(value) is unicode: |
|
360 |
found_date = True |
|
361 |
try: |
|
362 |
row[cellindex] = strptime(value, '%H:%M:%S') |
|
363 |
except: |
|
364 |
# DateTime used as Time? |
|
365 |
row[cellindex] = strptime(value, '%Y-%m-%d %H:%M:%S') |
|
366 |
if vtype == 'Interval' and type(value) is int: |
|
367 |
found_date = True |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
937
diff
changeset
|
368 |
row[cellindex] = timedelta(0, value, 0) # XXX value is in number of seconds? |
0 | 369 |
if not found_date: |
370 |
break |
|
371 |
return rset |
|
372 |
return new_execute |
|
373 |
querier.__class__.execute = wrap_execute(querier.__class__.execute) |
|
937 | 374 |
querier.__class__._devtools_sqlite_patched = True |