def addFileColumn(fileId, fieldTypeId, columnName, description, required, session): column = FileColumn(file_id=fileId, field_types_id=fieldTypeId, name=columnName, description=description, required=required) session.add(column) session.commit() return column
def addColumnByFileType(self, fileType, fieldName, required, field_type): """ Adds a new column to the schema Args: fileType -- One of the set of valid types of files (e.g. Award, AwardFinancial) fieldName -- The name of the scheam column required -- marks the column if data is allways required field_type -- sets the type of data allowed in the column Returns: ID of new column """ fileId = self.getFileId(fileType) if (fileId is None): raise ValueError("Filetype does not exist") newColumn = FileColumn() newColumn.required = False newColumn.name = fieldName newColumn.file_id = fileId field_type = field_type.upper() types = self.getDataTypes() #Allow for other names if (field_type == "STR"): field_type = "STRING" elif (field_type == "FLOAT"): field_type = "DECIMAL" elif (field_type == "BOOL"): field_type = "BOOLEAN" #Check types if field_type in types: newColumn.field_types_id = types[field_type] else: raise ValueError("".join( ["Type ", field_type, " is not vaild for ", str(fieldName)])) #Check Required required = required.upper() if (required in ["TRUE", "FALSE"]): if (required == "TRUE"): newColumn.required = True else: raise ValueError("".join( ["Required is not boolean for ", str(fieldName)])) # Save self.session.add(newColumn) self.session.commit() return newColumn.file_column_id
def addColumnByFileType(self,fileType,fieldName,required,field_type): """ Adds a new column to the schema Args: fileType -- One of the set of valid types of files (e.g. Award, AwardFinancial) fieldName -- The name of the scheam column required -- marks the column if data is allways required field_type -- sets the type of data allowed in the column Returns: ID of new column """ fileId = self.getFileId(fileType) if(fileId is None) : raise ValueError("Filetype does not exist") newColumn = FileColumn() newColumn.required = False newColumn.name = fieldName newColumn.file_id = fileId field_type = field_type.upper() types = self.getDataTypes() #Allow for other names if(field_type == "STR") : field_type = "STRING" elif(field_type == "FLOAT") : field_type = "DECIMAL" elif(field_type == "BOOL"): field_type = "BOOLEAN" #Check types if field_type in types : newColumn.field_types_id = types[field_type] else : raise ValueError("".join(["Type ",field_type," is not vaild for ",str(fieldName)])) #Check Required required = required.upper() if( required in ["TRUE","FALSE"]) : if( required == "TRUE") : newColumn.required = True else : raise ValueError("".join(["Required is not boolean for ",str(fieldName)])) # Save self.session.add(newColumn) self.session.commit() return newColumn.file_column_id
def setUpClass(cls): """Set up class-wide resources (test data)""" super(ValidatorTests, cls).setUpClass() #TODO: refactor into a pytest fixture # create test schema stringType = FieldType() stringType.field_type_id = 1 stringType.name = "STRING" intType = FieldType() intType.field_type_id = 2 intType.name = "INT" floatType = FieldType() floatType.field_type_id = 3 floatType.name = "DECIMAL" booleanType = FieldType() booleanType.field_type_id = 4 booleanType.name = "BOOLEAN" longType = FieldType() longType.field_type_id = 5 longType.name = "LONG" column1 = FileColumn() column1.file_column_id = 1 column1.name = "test1" column1.required = True column1.field_type = stringType column1.file_id = 1 cls.interfaces.validationDb.populateFile(column1) column2 = FileColumn() column2.file_column_id = 2 column2.name = "test2" column2.required = True column2.field_type = floatType column2.file_id = 1 cls.interfaces.validationDb.populateFile(column2) column3 = FileColumn() column3.file_column_id = 3 column3.name = "test3" column3.required = True column3.field_type = booleanType column3.file_id = 1 cls.interfaces.validationDb.populateFile(column3) column4 = FileColumn() column4.file_column_id = 3 column4.name = "test4" column4.required = True column4.field_type = intType column4.file_id = 1 cls.interfaces.validationDb.populateFile(column4) column5 = FileColumn() column5.file_column_id = 3 column5.name = "test5" column5.required = False column5.field_type = intType column5.file_id = 1 cls.interfaces.validationDb.populateFile(column5) column6 = FileColumn() column6.file_column_id = 6 column6.name = "test6" column6.required = False column6.field_type = stringType column6.file_id = 1 cls.interfaces.validationDb.populateFile(column6) column7 = FileColumn() column7.file_column_id = 7 column7.name = "test7" column7.required = False column7.field_type = longType column7.file_id = 1 cls.interfaces.validationDb.populateFile(column7) cls.schema = { "test1": column1, "test2": column2, "test3": column3, "test4": column4, "test5": column5, "test6": column6, "test7": column7 }