def createTestRunDatabase(srcDatabaseName, destDatabaseName, srcTestsuiteId, infoDict): """ Create a database file for the test run. srcDatabaseName is the filename of the database with the testsuite and testcases destDatabaseName is the filename of the database to be created srcTestsuiteId is the id of the testsuite in srcDatabaseName to be run """ # get the columns of testcases columnNames = nafdb.getColumnNames("testcases") columnNamesList = ",".join(columnNames) # createTestRunTables(destDatabaseName) conn = sqlite3.connect(destDatabaseName) cursor = conn.cursor() cursorProxy = CursorProxy(cursor) createTestRunTables(cursorProxy) cursor.execute("ATTACH DATABASE ? AS srcdb", (srcDatabaseName,)) # --- create lookup tables for enumeration types for name, values in LOOKUP_TABLES.iteritems(): cursor.execute("CREATE TABLE %s (key INTEGER, value TEXT);" % name) for value in values: cursor.execute("INSERT INTO %s VALUES (?, ?);" % name, (values.index(value), value)) # --- populate artifact tables command = ( "INSERT INTO testruns (%s) select * from srcdb.testcases where id in (select relatedid from relations where id=?)" % columnNamesList ) cursor.execute(command, (srcTestsuiteId,)) # copy images referenced by any testcases from src into dest # --- first, identifiy table columns which may reference an image testcaseTable = nafdb.getTableForTypeId(nafdb.TYPE_TESTCASE) columns = [c.name for c in testcaseTable.columns if c.view == nafdb.VIEW_MULTI_LINE] # --- next, read all fields containing an img tag imageIds = set() pattern = re.compile(r'<img src="#(\d+)"') command = """select %s from testcases where %s like '%%<img src="%%'""" for c in columns: # iterate all fields which references an image and extract the image id's cursor.execute(command % (c, c)) row = cursor.fetchone() if row is None: continue result = pattern.findall(row[0]) map(imageIds.add, [int(r) for r in result]) cursor.execute("INSERT INTO images SELECT * FROM srcdb.images WHERE id IN %s" % str(tuple(imageIds))) # copy testsuite table from src to dest cursor.execute("INSERT INTO testsuites SELECT * FROM srcdb.testsuites WHERE id=?", (srcTestsuiteId,)) # populate info table columnNames = getColumnNames(TESTRUNINFO_TABLE) columnNamesList = ",".join(columnNames) command = "insert into testruninfo (%s) values (%s)" % (columnNamesList, ",".join(["?"] * len(columnNames))) values = [infoDict[k] for k in columnNames] cursor.execute(command, values) # done everything, commit and close conn.commit() conn.close()
def resetData(self): self.rowCount = 0 self.columnCount = 0 self.columns = nafdb.getColumnNames(self.tableName) self.columnCount = len(self.columns) if nafdb.connection is not None: self.cur = nafdb.connection.cursor() # here rowCount actually means the largest requirement id, not the number of requirements self.cur.execute("select max(id) from %s;" % self.tableName) n = self.cur.fetchone()[0] if n is not None: self.rowCount = int(n) + 1 else: self.rowCount = 0 for lutTableName, lookupModel in self.lookupModel.iteritems(): lutTableRows = [self._translate(item) for item in nafdb.getLookupTableRows(lutTableName)] lookupModel.setStringList(lutTableRows) for historyTableName, historyModel in self.historyModel.iteritems(): historyModel.setStringList(nafdb.getHistoryTableRows(historyTableName))
def resetData(self): self.rowCount = 0 self.columnCount = 0 self.columns = nafdb.getColumnNames(self.tableName) self.columnCount = len(self.columns) if nafdb.connection is not None: self.cur = nafdb.connection.cursor() # here rowCount actually means the largest requirement id, not the number of requirements self.cur.execute('select max(id) from %s;' % self.tableName) n = self.cur.fetchone()[0] if n is not None: self.rowCount = int(n)+1 else: self.rowCount = 0 for lutTableName, lookupModel in self.lookupModel.iteritems(): lutTableRows = [self._translate(item) for item in nafdb.getLookupTableRows(lutTableName)] lookupModel.setStringList(lutTableRows) for historyTableName, historyModel in self.historyModel.iteritems(): historyModel.setStringList(nafdb.getHistoryTableRows(historyTableName))
def createTestRunDatabase(srcDatabaseName, destDatabaseName, srcTestsuiteId, infoDict): """ Create a database file for the test run. srcDatabaseName is the filename of the database with the testsuite and testcases destDatabaseName is the filename of the database to be created srcTestsuiteId is the id of the testsuite in srcDatabaseName to be run """ # get the columns of testcases columnNames = nafdb.getColumnNames('testcases') columnNamesList = ','.join(columnNames) #createTestRunTables(destDatabaseName) conn = sqlite3.connect(destDatabaseName) cursor = conn.cursor() cursorProxy = CursorProxy(cursor) createTestRunTables(cursorProxy) cursor.execute("ATTACH DATABASE ? AS srcdb", (srcDatabaseName, )) #--- create lookup tables for enumeration types for name, values in LOOKUP_TABLES.iteritems(): cursor.execute("CREATE TABLE %s (key INTEGER, value TEXT);" % name) for value in values: cursor.execute("INSERT INTO %s VALUES (?, ?);" % name, (values.index(value), value)) #--- populate artifact tables command = 'INSERT INTO testruns (%s) select * from srcdb.testcases where id in (select relatedid from relations where id=?)' % columnNamesList cursor.execute(command, (srcTestsuiteId, )) # copy images referenced by any testcases from src into dest # --- first, identifiy table columns which may reference an image testcaseTable = nafdb.getTableForTypeId(nafdb.TYPE_TESTCASE) columns = [ c.name for c in testcaseTable.columns if c.view == nafdb.VIEW_MULTI_LINE ] # --- next, read all fields containing an img tag imageIds = set() pattern = re.compile(r'<img src="#(\d+)"') command = """select %s from testcases where %s like '%%<img src="%%'""" for c in columns: # iterate all fields which references an image and extract the image id's cursor.execute(command % (c, c)) row = cursor.fetchone() if row is None: continue result = pattern.findall(row[0]) map(imageIds.add, [int(r) for r in result]) cursor.execute( "INSERT INTO images SELECT * FROM srcdb.images WHERE id IN %s" % str(tuple(imageIds))) # copy testsuite table from src to dest cursor.execute( 'INSERT INTO testsuites SELECT * FROM srcdb.testsuites WHERE id=?', (srcTestsuiteId, )) # populate info table columnNames = getColumnNames(TESTRUNINFO_TABLE) columnNamesList = ','.join(columnNames) command = 'insert into testruninfo (%s) values (%s)' % ( columnNamesList, ','.join(['?'] * len(columnNames))) values = [infoDict[k] for k in columnNames] cursor.execute(command, values) # done everything, commit and close conn.commit() conn.close()