def setUp(self): config = deepcopy(self.config) # Add the appropriate connection string to the app config. config['sqlalchemy'] = { 'url': '%s/%s' % (__bind__, TestModel.__db__), 'encoding': 'utf-8', 'poolclass': NullPool } # Set up a fake app self.app = self.load_test_app(config) dcmodel.clear()
def setUpClass(cls): if TestModel.__db__ is None: TestModel.__db__ = 'draughtcrafttest' # Connect and create the temporary database print "=" * 80 print "CREATING TEMPORARY DATABASE FOR TESTS" print "=" * 80 subprocess.call(['createdb', TestModel.__db__]) # Bind and create the database tables dcmodel.clear() dcmodel.bind( create_engine('%s/%s' % (__bind__, TestModel.__db__), **{ 'encoding': 'utf-8', 'poolclass': NullPool })) dcmodel.metadata.create_all() dcmodel.commit() dcmodel.clear()
def setUpClass(cls): if TestModel.__db__ is None: TestModel.__db__ = 'draughtcrafttest' # Connect and create the temporary database print "=" * 80 print "CREATING TEMPORARY DATABASE FOR TESTS" print "=" * 80 subprocess.call(['createdb', TestModel.__db__]) # Bind and create the database tables dcmodel.clear() dcmodel.bind(create_engine( '%s/%s' % (__bind__, TestModel.__db__), **{ 'encoding': 'utf-8', 'poolclass': NullPool } )) dcmodel.metadata.create_all() dcmodel.commit() dcmodel.clear()
def tearDown(self): from sqlalchemy.engine import reflection # Tear down and dispose the DB binding dcmodel.clear() # start a transaction engine = conf.sqlalchemy.sa_engine conn = engine.connect() trans = conn.begin() inspector = reflection.Inspector.from_engine(engine) # gather all data first before dropping anything. # some DBs lock after things have been dropped in # a transaction. conn.execute("TRUNCATE TABLE %s RESTART IDENTITY CASCADE" % (', '.join(inspector.get_table_names()))) trans.commit() conn.close()
def tearDown(self): from sqlalchemy.engine import reflection # Tear down and dispose the DB binding dcmodel.clear() # start a transaction engine = conf.sqlalchemy.sa_engine conn = engine.connect() trans = conn.begin() inspector = reflection.Inspector.from_engine(engine) # gather all data first before dropping anything. # some DBs lock after things have been dropped in # a transaction. conn.execute("TRUNCATE TABLE %s RESTART IDENTITY CASCADE" % ( ', '.join(inspector.get_table_names()) )) trans.commit() conn.close()