devtools/realdbtest.py
changeset 11057 0b59724cb3f2
parent 11052 058bb3dc685f
child 11058 23eb30449fe5
equal deleted inserted replaced
11052:058bb3dc685f 11057:0b59724cb3f2
     1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     3 #
       
     4 # This file is part of CubicWeb.
       
     5 #
       
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
       
     7 # terms of the GNU Lesser General Public License as published by the Free
       
     8 # Software Foundation, either version 2.1 of the License, or (at your option)
       
     9 # any later version.
       
    10 #
       
    11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
       
    14 # details.
       
    15 #
       
    16 # You should have received a copy of the GNU Lesser General Public License along
       
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
       
    18 from cubicweb import toolsutils
       
    19 from cubicweb.devtools import DEFAULT_SOURCES, BaseApptestConfiguration
       
    20 
       
    21 class RealDatabaseConfiguration(BaseApptestConfiguration):
       
    22     init_repository = False
       
    23     sourcesdef =  DEFAULT_SOURCES.copy()
       
    24 
       
    25     def sources(self):
       
    26         """
       
    27         By default, we run tests with the sqlite DB backend.
       
    28         One may use its own configuration by just creating a
       
    29         'sources' file in the test directory from wich tests are
       
    30         launched.
       
    31         """
       
    32         self._sources = self.sourcesdef
       
    33         return self._sources
       
    34 
       
    35 
       
    36 def buildconfig(dbuser, dbpassword, dbname, adminuser, adminpassword, dbhost=None):
       
    37     """convenience function that builds a real-db configuration class"""
       
    38     sourcesdef =  {'system': {'adapter' : 'native',
       
    39                               'db-encoding' : 'UTF-8', #'ISO-8859-1',
       
    40                               'db-user' : dbuser,
       
    41                               'db-password' : dbpassword,
       
    42                               'db-name' : dbname,
       
    43                               'db-driver' : 'postgres',
       
    44                               'db-host' : dbhost,
       
    45                               },
       
    46                    'admin' : {'login': adminuser,
       
    47                               'password': adminpassword,
       
    48                               },
       
    49                    }
       
    50     return type('MyRealDBConfig', (RealDatabaseConfiguration,),
       
    51                 {'sourcesdef': sourcesdef})
       
    52 
       
    53 
       
    54 def loadconfig(filename):
       
    55     """convenience function that builds a real-db configuration class
       
    56     from a file
       
    57     """
       
    58     return type('MyRealDBConfig', (RealDatabaseConfiguration,),
       
    59                 {'sourcesdef': toolsutils.read_config(filename)})