1 from base_test import DakTestCase, fixture
3 from daklib.config import Config
4 from daklib.dbconn import DBConn
6 from sqlalchemy import create_engine, __version__
7 from sqlalchemy.exc import SADeprecationWarning
12 # suppress some deprecation warnings in squeeze related to sqlalchemy
13 warnings.filterwarnings('ignore', \
14 "The SQLAlchemy PostgreSQL dialect has been renamed from 'postgres' to 'postgresql'.*", \
17 class DBDakTestCase(DakTestCase):
20 if cnf["DB::Name"] in ('backports', 'obscurity', 'projectb'):
21 self.fail("You have configured an invalid database name: '%s'." % \
25 connstr = "postgres://%s" % cnf["DB::Host"]
26 if cnf["DB::Port"] and cnf["DB::Port"] != "-1":
27 connstr += ":%s" % cnf["DB::Port"]
28 connstr += "/%s" % cnf["DB::Name"]
31 connstr = "postgres:///%s" % cnf["DB::Name"]
32 if cnf["DB::Port"] and cnf["DB::Port"] != "-1":
33 connstr += "?port=%s" % cnf["DB::Port"]
35 pickle_filename = 'db-metadata-%s.pkl' % __version__
36 pickle_file = open(fixture(pickle_filename), 'r')
37 self.metadata = pickle.load(pickle_file)
38 self.metadata.ddl_listeners = pickle.load(pickle_file)
40 self.metadata.bind = create_engine(connstr)
41 self.metadata.create_all()
42 self.session = DBConn().session()
46 self.metadata.drop_all()