author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 17 Jan 2011 12:42:27 +0100 | |
branch | stable |
changeset 6834 | b4befa12bbcc |
parent 6750 | ef513c03a224 |
child 6843 | b70a26ca271c |
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 |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
88 |
options = cwconfig.merge_options(ServerConfiguration.options + ( |
0 | 89 |
('anonymous-user', |
90 |
{'type' : 'string', |
|
91 |
'default': None, |
|
92 |
'help': 'login of the CubicWeb user account to use for anonymous user (if you want to allow anonymous)', |
|
5323
329b4f6d18b4
[config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5274
diff
changeset
|
93 |
'group': 'main', 'level': 1, |
0 | 94 |
}), |
95 |
('anonymous-password', |
|
96 |
{'type' : 'string', |
|
97 |
'default': None, |
|
98 |
'help': 'password of the CubicWeb user account matching login', |
|
5323
329b4f6d18b4
[config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5274
diff
changeset
|
99 |
'group': 'main', 'level': 1, |
0 | 100 |
}), |
101 |
)) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
102 |
|
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
|
103 |
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
|
104 |
# 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
|
105 |
if apphome is None: |
6593
0fd8792c9c8a
[testlib] self.appid not yet defined
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6585
diff
changeset
|
106 |
if exists(appid): |
0fd8792c9c8a
[testlib] self.appid not yet defined
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6585
diff
changeset
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
self._apphome = apphome |
0 | 111 |
ServerConfiguration.__init__(self, appid) |
112 |
self.init_log(log_threshold, force=True) |
|
113 |
# need this, usually triggered by cubicweb-ctl |
|
114 |
self.load_cwctl_plugins() |
|
115 |
||
116 |
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
|
117 |
|
0 | 118 |
@property |
119 |
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
|
120 |
return self._apphome |
0 | 121 |
appdatahome = apphome |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
122 |
|
3435
84036ad2c82d
add anon user for TestServerConfiguration, no only AppTestConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3163
diff
changeset
|
123 |
def load_configuration(self): |
84036ad2c82d
add anon user for TestServerConfiguration, no only AppTestConfiguration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3163
diff
changeset
|
124 |
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
|
125 |
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
|
126 |
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
|
127 |
# no undo support in tests |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4761
diff
changeset
|
128 |
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
|
129 |
|
0 | 130 |
def main_config_file(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1978
diff
changeset
|
131 |
"""return instance's control configuration file""" |
0 | 132 |
return join(self.apphome, '%s.conf' % self.name) |
133 |
||
134 |
def bootstrap_cubes(self): |
|
135 |
try: |
|
136 |
super(TestServerConfiguration, self).bootstrap_cubes() |
|
137 |
except IOError: |
|
138 |
# no cubes |
|
139 |
self.init_cubes( () ) |
|
140 |
||
141 |
sourcefile = None |
|
142 |
def sources_file(self): |
|
143 |
"""define in subclasses self.sourcefile if necessary""" |
|
144 |
if self.sourcefile: |
|
145 |
print 'Reading sources from', self.sourcefile |
|
146 |
sourcefile = self.sourcefile |
|
147 |
if not isabs(sourcefile): |
|
148 |
sourcefile = join(self.apphome, sourcefile) |
|
149 |
else: |
|
150 |
sourcefile = super(TestServerConfiguration, self).sources_file() |
|
151 |
return sourcefile |
|
152 |
||
153 |
def sources(self): |
|
154 |
"""By default, we run tests with the sqlite DB backend. One may use its |
|
155 |
own configuration by just creating a 'sources' file in the test |
|
156 |
directory from wich tests are launched or by specifying an alternative |
|
157 |
sources file using self.sourcefile. |
|
158 |
""" |
|
159 |
sources = super(TestServerConfiguration, self).sources() |
|
160 |
if not sources: |
|
161 |
sources = DEFAULT_SOURCES |
|
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6425
diff
changeset
|
162 |
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
|
163 |
sources['admin'] = DEFAULT_SOURCES['admin'] |
0 | 164 |
return sources |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
165 |
|
6441
adbce42ff1b5
TestServerConfig needs default_base_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
166 |
# 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
|
167 |
# config |
adbce42ff1b5
TestServerConfig needs default_base_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
168 |
|
adbce42ff1b5
TestServerConfig needs default_base_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
169 |
def instance_md5_version(self): |
adbce42ff1b5
TestServerConfig needs default_base_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
170 |
return '' |
adbce42ff1b5
TestServerConfig needs default_base_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
171 |
|
adbce42ff1b5
TestServerConfig needs default_base_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
172 |
def default_base_url(self): |
adbce42ff1b5
TestServerConfig needs default_base_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
173 |
return BASE_URL |
adbce42ff1b5
TestServerConfig needs default_base_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
174 |
|
0 | 175 |
|
176 |
class BaseApptestConfiguration(TestServerConfiguration, TwistedConfiguration): |
|
177 |
repo_method = 'inmemory' |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
178 |
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
|
179 |
+ 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
|
180 |
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
|
181 |
cube_appobject_path = TestServerConfiguration.cube_appobject_path | TwistedConfiguration.cube_appobject_path |
0 | 182 |
|
183 |
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
|
184 |
return self.cw_languages() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
185 |
|
0 | 186 |
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
|
187 |
# 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
|
188 |
# threads |
0 | 189 |
return True |
190 |
||
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6315
diff
changeset
|
191 |
# XXX merge with BaseApptestConfiguration ? |
0 | 192 |
class ApptestConfiguration(BaseApptestConfiguration): |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
193 |
|
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
|
194 |
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
|
195 |
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
|
196 |
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
|
197 |
log_threshold=log_threshold) |
0 | 198 |
self.init_repository = sourcefile is None |
199 |
self.sourcefile = sourcefile |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
200 |
|
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6315
diff
changeset
|
201 |
|
6164
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
202 |
class RealDatabaseConfiguration(ApptestConfiguration): |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
203 |
"""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
|
204 |
|
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
205 |
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
|
206 |
|
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
207 |
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
|
208 |
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
|
209 |
accordingly. |
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 |
Example usage:: |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
212 |
|
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
213 |
class MyTests(CubicWebTC): |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
214 |
_config = RealDatabseConfiguration('myapp', |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
215 |
sourcefile='/path/to/sources') |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
216 |
def test_something(self): |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
217 |
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
|
218 |
self.view('foaf', rset) |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
219 |
|
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
220 |
""" |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
221 |
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
|
222 |
read_instance_schema = True # read schema from database |
0 | 223 |
|
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6315
diff
changeset
|
224 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
225 |
# test database handling ####################################################### |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
226 |
|
6631
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6594
diff
changeset
|
227 |
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
|
228 |
"""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
|
229 |
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
|
230 |
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
|
231 |
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
|
232 |
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
|
233 |
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
|
234 |
if driver == 'sqlite': |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
235 |
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
|
236 |
elif driver == 'postgres': |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
237 |
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
|
238 |
else: |
ceb6951f9d2f
[devtools] restore ability to test on real databases
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5754
diff
changeset
|
239 |
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
|
240 |
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
|
241 |
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
|
242 |
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
|
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 |
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
|
245 |
return repo, cnx |
0 | 246 |
|
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 |
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
|
248 |
"""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
|
249 |
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
|
250 |
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
|
251 |
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
|
252 |
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
|
253 |
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
|
254 |
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
|
255 |
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
|
256 |
else: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
257 |
raise ValueError('no reset function for driver %r' % driver) |
0 | 258 |
|
259 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
260 |
### postgres test database handling ############################################ |
0 | 261 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
262 |
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
|
263 |
"""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
|
264 |
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
|
265 |
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
|
266 |
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
|
267 |
_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
|
268 |
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
|
269 |
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
|
270 |
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
|
271 |
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
|
272 |
# 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
|
273 |
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
|
274 |
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
|
275 |
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
|
276 |
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
|
277 |
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
|
278 |
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
|
279 |
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
|
280 |
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
|
281 |
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
|
282 |
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
|
283 |
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
|
284 |
# 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
|
285 |
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
|
286 |
# 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
|
287 |
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
|
288 |
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
|
289 |
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
|
290 |
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
|
291 |
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
|
292 |
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
|
293 |
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
|
294 |
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
|
295 |
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
|
296 |
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
|
297 |
# 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
|
298 |
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
|
299 |
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
|
300 |
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
|
301 |
dbcnx.close() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
302 |
|
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
|
303 |
### sqlserver2005 test database handling ####################################### |
5166
1e96d01728c4
enable live test against sqlserver 2005 database
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5043
diff
changeset
|
304 |
|
1e96d01728c4
enable live test against sqlserver 2005 database
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5043
diff
changeset
|
305 |
def init_test_database_sqlserver2005(config): |
1e96d01728c4
enable live test against sqlserver 2005 database
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5043
diff
changeset
|
306 |
"""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
|
307 |
if config.init_repository: |
240e21b94a28
fixed indentation error in devtools/__init__.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5166
diff
changeset
|
308 |
from cubicweb.server import init_repository |
5693
8af6623f3d4e
[pylint] fix detected name errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5541
diff
changeset
|
309 |
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
|
310 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
311 |
### 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
|
312 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
313 |
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
|
314 |
try: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
315 |
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
|
316 |
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
|
317 |
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
|
318 |
pass |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
319 |
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
|
320 |
try: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
321 |
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
|
322 |
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
|
323 |
pass |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
324 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
325 |
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
|
326 |
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
|
327 |
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
|
328 |
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
|
329 |
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
|
330 |
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
|
331 |
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
|
332 |
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
|
333 |
return False |
0 | 334 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2732
diff
changeset
|
335 |
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
|
336 |
"""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
|
337 |
# 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
|
338 |
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
|
339 |
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
|
340 |
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
|
341 |
# 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
|
342 |
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
|
343 |
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
|
344 |
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
|
345 |
shutil.copy(dbfile, '%s-template' % dbfile) |
0 | 346 |
|
2732 | 347 |
def install_sqlite_patch(querier): |
0 | 348 |
"""This patch hotfixes the following sqlite bug : |
298
3e6d32667140
[doc] Fix docstring indentation.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
0
diff
changeset
|
349 |
- http://www.sqlite.org/cvstrac/tktview?tn=1327,33 |
3e6d32667140
[doc] Fix docstring indentation.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
0
diff
changeset
|
350 |
(some dates are returned as strings rather thant date objects) |
0 | 351 |
""" |
937 | 352 |
if hasattr(querier.__class__, '_devtools_sqlite_patched'): |
353 |
return # already monkey patched |
|
0 | 354 |
def wrap_execute(base_execute): |
355 |
def new_execute(*args, **kwargs): |
|
356 |
rset = base_execute(*args, **kwargs) |
|
357 |
if rset.description: |
|
358 |
found_date = False |
|
359 |
for row, rowdesc in zip(rset, rset.description): |
|
360 |
for cellindex, (value, vtype) in enumerate(zip(row, rowdesc)): |
|
361 |
if vtype in ('Date', 'Datetime') and type(value) is unicode: |
|
362 |
found_date = True |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
937
diff
changeset
|
363 |
value = value.rsplit('.', 1)[0] |
0 | 364 |
try: |
365 |
row[cellindex] = strptime(value, '%Y-%m-%d %H:%M:%S') |
|
366 |
except: |
|
367 |
row[cellindex] = strptime(value, '%Y-%m-%d') |
|
368 |
if vtype == 'Time' and type(value) is unicode: |
|
369 |
found_date = True |
|
370 |
try: |
|
371 |
row[cellindex] = strptime(value, '%H:%M:%S') |
|
372 |
except: |
|
373 |
# DateTime used as Time? |
|
374 |
row[cellindex] = strptime(value, '%Y-%m-%d %H:%M:%S') |
|
375 |
if vtype == 'Interval' and type(value) is int: |
|
376 |
found_date = True |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
937
diff
changeset
|
377 |
row[cellindex] = timedelta(0, value, 0) # XXX value is in number of seconds? |
0 | 378 |
if not found_date: |
379 |
break |
|
380 |
return rset |
|
381 |
return new_execute |
|
382 |
querier.__class__.execute = wrap_execute(querier.__class__.execute) |
|
937 | 383 |
querier.__class__._devtools_sqlite_patched = True |