def __assignResource(self, cfgOb, sectionName="site_info_configuration", resourceName="MYSQL_DB"): cn = Connection(cfgOb=cfgOb) return cn.assignResource(resourceName=resourceName, sectionName=sectionName)
def __open(self, infoD): cObj = Connection() cObj.setPreferences(infoD) ok = cObj.openConnection() if ok: return cObj else: return None
def __schemaCreate(self, schemaDefObj): """Create table schema using schema definition""" try: tableIdList = schemaDefObj.getSchemaIdList() sqlGen = SqlGenAdmin(self.__verbose) sqlL = sqlGen.createDatabaseSQL(schemaDefObj.getDatabaseName()) for tableId in tableIdList: tableDefObj = schemaDefObj.getSchemaObject(tableId) sqlL.extend( sqlGen.createTableSQL( databaseName=schemaDefObj.getDatabaseName(), tableDefObj=tableDefObj)) logger.debug("Schema creation SQL string\n %s\n\n", "\n".join(sqlL)) with Connection(cfgOb=self.__cfgOb, resourceName=self.__resourceName) as client: myQ = MyDbQuery(dbcon=client, verbose=self.__verbose) # # Permit warnings to support "drop table if exists" for missing tables. # myQ.setWarning("ignore") ret = myQ.sqlCommand(sqlCommandList=sqlL) logger.debug("\n\n+INFO mysql server returns %r\n", ret) self.assertTrue(ret) except Exception as e: logger.exception("Failing with %s", str(e)) self.fail()
def testLoadPdbxFiles(self): try: cD = self.__schP.makeSchemaDef("pdbx", dataTyping="SQL", saveSchema=True) sd = SchemaDefAccess(cD) self.__schemaCreate(sd) inputPathList = self.__rpP.getLocatorObjList(contentType="pdbx") logger.debug("Input path list %r", inputPathList) with Connection(cfgOb=self.__cfgOb, resourceName=self.__resourceName) as client: sdl = SchemaDefLoader( self.__cfgOb, schemaDefObj=sd, dbCon=client, cachePath=self.__cachePath, workPath=self.__workPath, cleanUp=False, warnings="error", verbose=self.__verbose, restoreUseStash=False, restoreUseGit=True, providerTypeExclude=self.__excludeType, ) ok = sdl.load(inputPathList=inputPathList, loadType="batch-insert", deleteOpt="all") self.assertTrue(ok) except Exception as e: logger.exception("Failing with %s", str(e)) self.fail()
def testLoadBirdReference(self): try: cD = self.__schP.makeSchemaDef("bird", dataTyping="SQL", saveSchema=True) sd = SchemaDefAccess(cD) self.__schemaCreate(sd) inputPathList = self.__rpP.getLocatorObjList(contentType="bird") inputPathList.extend( self.__rpP.getLocatorObjList(contentType="bird_family")) # with Connection(cfgOb=self.__cfgOb, resourceName=self.__resourceName) as client: sdl = SchemaDefLoader( self.__cfgOb, schemaDefObj=sd, dbCon=client, cachePath=self.__cachePath, workPath=self.__workPath, cleanUp=False, warnings="error", verbose=self.__verbose, restoreUseStash=False, restoreUseGit=True, providerTypeExclude=self.__excludeType, ) ok = sdl.load(inputPathList=inputPathList, loadType="batch-file") self.assertTrue(ok) except Exception as e: logger.exception("Failing with %s", str(e)) self.fail()
def testLoadChemCompReference(self): try: cD = self.__schP.makeSchemaDef("chem_comp", dataTyping="SQL", saveSchema=True) sd = SchemaDefAccess(cD) self.__schemaCreate(sd) inputPathList = self.__rpP.getLocatorObjList( contentType="chem_comp") with Connection(cfgOb=self.__cfgOb, resourceName=self.__resourceName) as client: sdl = SchemaDefLoader(self.__cfgOb, schemaDefObj=sd, dbCon=client, cachePath=self.__cachePath, workPath=self.__workPath, cleanUp=False, warnings="error", verbose=self.__verbose) ok = sdl.load(inputPathList=inputPathList, loadType="batch-file") self.assertTrue(ok) except Exception as e: logger.exception("Failing with %s", str(e)) self.fail()
def testCreateConnectionContext(self): """Test case - connection creation using context manager""" try: with Connection(cfgOb=self.__cfgOb, resourceName="MYSQL_DB") as client: self.assertNotEqual(client, None) except Exception as e: logger.exception("Failing with %s", str(e)) self.fail()
def testCreateMultipleConnectionsContext(self): """Test case - multiple connection creation""" try: for _ in range(100): with Connection(cfgOb=self.__cfgOb, resourceName="MYSQL_DB") as client: self.assertNotEqual(client, None) except Exception as e: logger.exception("Failing with %s", str(e)) self.fail()
def testCreateMultipleConnWithQueryContext(self): """Test case - multiple connection creation""" try: for ii in range(100): with Connection(cfgOb=self.__cfgOb, resourceName="MYSQL_DB") as client: self.assertNotEqual(client, None) for jj in range(100): my = MyDbQuery(dbcon=client) ok = my.testSelectQuery(count=ii + jj) self.assertTrue(ok) except Exception as e: logger.exception("Failing with %s", str(e)) self.fail()
def testReLoadBirdReference(self): try: cD = self.__schP.makeSchemaDef("bird", dataTyping="SQL", saveSchema=True) sd = SchemaDefAccess(cD) self.__schemaCreate(sd) inputPathList = self.__rpP.getLocatorObjList(contentType="bird") inputPathList.extend( self.__rpP.getLocatorObjList(contentType="bird_family")) # with Connection(cfgOb=self.__cfgOb, resourceName=self.__resourceName) as client: sdl = SchemaDefLoader(self.__cfgOb, schemaDefObj=sd, dbCon=client, cachePath=self.__cachePath, workPath=self.__workPath, cleanUp=False, warnings="error", verbose=self.__verbose) sdl.load(inputPathList=inputPathList, loadType="batch-file") # logger.debug( "INFO BATCH FILE RELOAD TEST --------------------------------------------\n" ) ok = sdl.load(inputPathList=inputPathList, loadType="batch-file", deleteOpt="all") self.assertTrue(ok) # logger.debug( "\n\n\n+INFO BATCH INSERT RELOAD TEST --------------------------------------------\n" ) ok = sdl.load(inputPathList=inputPathList, loadType="batch-file", deleteOpt="selected") self.assertTrue(ok) except Exception as e: logger.exception("Failing with %s", str(e)) self.fail()