|
1 import logging |
|
2 from cubicweb import toolsutils |
|
3 from cubicweb.devtools import DEFAULT_SOURCES, BaseApptestConfiguration |
|
4 |
|
5 class RealDatabaseConfiguration(BaseApptestConfiguration): |
|
6 init_repository = False |
|
7 sourcesdef = DEFAULT_SOURCES.copy() |
|
8 |
|
9 def sources(self): |
|
10 """ |
|
11 By default, we run tests with the sqlite DB backend. |
|
12 One may use its own configuration by just creating a |
|
13 'sources' file in the test directory from wich tests are |
|
14 launched. |
|
15 """ |
|
16 self._sources = self.sourcesdef |
|
17 return self._sources |
|
18 |
|
19 |
|
20 def buildconfig(dbuser, dbpassword, dbname, adminuser, adminpassword, dbhost=None): |
|
21 """convenience function that builds a real-db configuration class""" |
|
22 sourcesdef = {'system': {'adapter' : 'native', |
|
23 'db-encoding' : 'UTF-8', #'ISO-8859-1', |
|
24 'db-user' : dbuser, |
|
25 'db-password' : dbpassword, |
|
26 'db-name' : dbname, |
|
27 'db-driver' : 'postgres', |
|
28 'db-host' : dbhost, |
|
29 }, |
|
30 'admin' : {'login': adminuser, |
|
31 'password': adminpassword, |
|
32 }, |
|
33 } |
|
34 return type('MyRealDBConfig', (RealDatabaseConfiguration,), |
|
35 {'sourcesdef': sourcesdef}) |
|
36 |
|
37 |
|
38 def loadconfig(filename): |
|
39 """convenience function that builds a real-db configuration class |
|
40 from a file |
|
41 """ |
|
42 return type('MyRealDBConfig', (RealDatabaseConfiguration,), |
|
43 {'sourcesdef': toolsutils.read_config(filename)}) |