Ejemplo n.º 1
0
Archivo: gen.py Proyecto: rafoul/pytest
 def copy(self, tabname):
     LOG.debug('received copy request for %s', tabname)
     schema, table = self._get_schema_and_table(tabname)
     
     # generate data for reference tables if necessary.
     self._check_references(schema, table)
         
     cols = self.meta.columns(schema, table)
     sample = self.sample(schema, table)
     col_vals = {}
     
     print 'Use sample value for general columns?'
     general_cols = cols['general']
     if yes_or_no():            
         cols.pop('general')
         general_col_names = []
         for col in general_cols:
             col_name = col['COLNAME']
             col_vals[col_name] = sample[col_name]    
             general_col_names.append(col_name)    
         LOG.debug('use sample data for general columns: %s', ', '.join(general_col_names))    
     
     # collect values for columns.
     for cat in cols:
         if len(cols[cat]) > 0:               
             for col in cols[cat]:   
                 col_name = col['COLNAME']
                 col_vals[col_name] = self._get_column_value(cat, col, sample)
     
     print 'Do you want to customize values for general columns?'
     if yes_or_no():
         self._customize_column_values(general_cols, col_vals, sample)
     
     col_names = col_vals.keys()                
     sql = 'INSERT INTO %s.%s(%s) VALUES(%s)' % \
                      (schema, table, ', '.join(col_names), ', '.join(list('?' * len(col_names))))
     self.db2.execute(sql, [tuple(col_vals.values())])
     self.db2.commit()
             
     id_cols = self._identity_cols(cols, col_vals)
     newly_added = self._verify_exist(schema, table, id_cols)    
     self._add_modification(schema, table, newly_added)
     LOG.debug('successful generated a new row for table %s.', tabname)
Ejemplo n.º 2
0
Archivo: gen.py Proyecto: rafoul/pytest
 def _check_references(self, schema, table):
     # Check references.
     refs = self.meta.references(schema, table)
     if len(refs) > 0:
         print '%s.%s has the following references, do we need to add references first?' % (schema, table)
         for ref in refs:
             refname = '.'.join(ref)
             print '\t', refname
             if yes_or_no():
                 LOG.debug('generate data for reference table: %s', refname)
                 self.copy(refname)