cubicweb/devtools/__init__.py
changeset 12567 26744ad37953
parent 12549 e2db422752b4
child 12884 9754c40c732a
equal deleted inserted replaced
12566:6b3523f81f42 12567:26744ad37953
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    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/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """Test tools for cubicweb"""
    18 """Test tools for cubicweb"""
    19 
    19 
    20 from __future__ import print_function
       
    21 
       
    22 import os
    20 import os
    23 import sys
    21 import sys
    24 import errno
    22 import errno
    25 import logging
    23 import logging
    26 import shutil
    24 import shutil
    29 import tempfile
    27 import tempfile
    30 import getpass
    28 import getpass
    31 from hashlib import sha1  # pylint: disable=E0611
    29 from hashlib import sha1  # pylint: disable=E0611
    32 from os.path import abspath, join, exists, split, isdir, dirname
    30 from os.path import abspath, join, exists, split, isdir, dirname
    33 from functools import partial
    31 from functools import partial
       
    32 import pickle
    34 
    33 
    35 import filelock
    34 import filelock
    36 from six import text_type
       
    37 from six.moves import cPickle as pickle
       
    38 
    35 
    39 from logilab.common.decorators import cached, clear_cache
    36 from logilab.common.decorators import cached, clear_cache
    40 
    37 
    41 from cubicweb import ExecutionError
    38 from cubicweb import ExecutionError
    42 from cubicweb import schema, cwconfig
    39 from cubicweb import schema, cwconfig
    91     },
    88     },
    92 }
    89 }
    93 DEFAULT_PSQL_SOURCES = DEFAULT_SOURCES.copy()
    90 DEFAULT_PSQL_SOURCES = DEFAULT_SOURCES.copy()
    94 DEFAULT_PSQL_SOURCES['system'] = DEFAULT_SOURCES['system'].copy()
    91 DEFAULT_PSQL_SOURCES['system'] = DEFAULT_SOURCES['system'].copy()
    95 DEFAULT_PSQL_SOURCES['system']['db-driver'] = 'postgres'
    92 DEFAULT_PSQL_SOURCES['system']['db-driver'] = 'postgres'
    96 DEFAULT_PSQL_SOURCES['system']['db-user'] = text_type(getpass.getuser())
    93 DEFAULT_PSQL_SOURCES['system']['db-user'] = getpass.getuser()
    97 DEFAULT_PSQL_SOURCES['system']['db-password'] = None
    94 DEFAULT_PSQL_SOURCES['system']['db-password'] = None
    98 # insert a dumb value as db-host to avoid unexpected connection to local server
    95 # insert a dumb value as db-host to avoid unexpected connection to local server
    99 DEFAULT_PSQL_SOURCES['system']['db-host'] = 'REPLACEME'
    96 DEFAULT_PSQL_SOURCES['system']['db-host'] = 'REPLACEME'
   100 
    97 
   101 
    98 
   393     def get_cnx(self):
   390     def get_cnx(self):
   394         """return Connection object on the current repository"""
   391         """return Connection object on the current repository"""
   395         from cubicweb.repoapi import connect
   392         from cubicweb.repoapi import connect
   396         repo = self.get_repo()
   393         repo = self.get_repo()
   397         sources = self.config.read_sources_file()
   394         sources = self.config.read_sources_file()
   398         login = text_type(sources['admin']['login'])
   395         login = sources['admin']['login']
   399         password = sources['admin']['password'] or 'xxx'
   396         password = sources['admin']['password'] or 'xxx'
   400         cnx = connect(repo, login, password=password)
   397         cnx = connect(repo, login, password=password)
   401         return cnx
   398         return cnx
   402 
   399 
   403     def get_repo_and_cnx(self, db_id=DEFAULT_EMPTY_DB_ID):
   400     def get_repo_and_cnx(self, db_id=DEFAULT_EMPTY_DB_ID):