Esempio n. 1
0
def main():
    print "Start"
    container = ValidatorContainer()
    file = sys.argv[1]  #first argument csv file name
    ls = getCsvContaint(file)
    header = ls.pop(0)
    invalidLines = list()
    validLine = list()
    validLines = list()

    print header

    for row in ls:  #for each row in csv files excluding header
        for i in range(len(row)):  #for each element in an row
            validator = container.getElement(
                header[i])  #getting the appropiate
            if validator is not None:
                if not validator.isValid(row[i]):
                    validateValue = validator.validate(
                        row[i])  #try to validate
                    if validateValue is None:
                        invalidElement = "Invalid " + header[i] + str(row)
                        invalidLines.append(
                            invalidElement)  #append the invalid element
                    else:
                        validLine.append(str(validateValue))
                else:
                    validLine.append(row[i])  #append valid element
            else:
                validLine.append(
                    row[i]
                )  #if a validator does't exist elements are not validated
        if len(validLine) == len(
                row):  #append validated row, only if all items where valid
            validLines.append(validLine)
        validLine = list()  # get clear list

    dbLoaderContainer = DatabaseLoaderContainer()  #get database container
    dbLoader = dbLoaderContainer.getElement(
        str(header).lower())  #get database loader for csv based on header.
    print "Start to load: " + dbLoader.getKey()
    dbLoader.load(validLines)
    print "Load succesfull"

    #show invalid files
    for line in validLines:
        print line

    print "-----------INVALID------------"
    print header
    for line in invalidLines:
        print line
Esempio n. 2
0
def main():
    print "Start"
    container = ValidatorContainer()
    file = sys.argv[1] #first argument csv file name
    ls = getCsvContaint(file)
    header = ls.pop(0) 
    invalidLines = list() 
    validLine = list()
    validLines = list()
    
    print header
    
    for row in ls: #for each row in csv files excluding header
        for i in range(len(row)): #for each element in an row
            validator = container.getElement(header[i]) #getting the appropiate
            if validator is not None:    
                if not validator.isValid(row[i]):
                    validateValue = validator.validate(row[i]) #try to validate
                    if validateValue is None:
                        invalidElement = "Invalid "+header[i]+str(row) 
                        invalidLines.append(invalidElement) #append the invalid element
                    else:
                        validLine.append(str(validateValue))
                else:
                    validLine.append(row[i]) #append valid element
            else: validLine.append(row[i]) #if a validator does't exist elements are not validated
        if len(validLine)==len(row): #append validated row, only if all items where valid
            validLines.append(validLine)
        validLine=list() # get clear list
       
    dbLoaderContainer = DatabaseLoaderContainer() #get database container
    dbLoader = dbLoaderContainer.getElement(str(header).lower()) #get database loader for csv based on header.
    print "Start to load: " + dbLoader.getKey()
    dbLoader.load(validLines)
    print "Load succesfull"
    
    #show invalid files
    for line in validLines:
        print line
        
    print "-----------INVALID------------"
    print header
    for line in invalidLines:
        print line
Esempio n. 3
0
def main():
    print "Start"
    container = ValidatorContainer()
    ls = getCsvContaint()
    header = ls.pop(0)
    invalidLines = list()
    validLine = list()
    validLines = list()

    print header
    for row in ls:
        for i in range(len(row)):
            validator = container.getElement(header[i])
            if validator is not None:
                if not validator.isValid(row[i]):
                    validateValue = validator.validate(row[i])
                    if validateValue is None:
                        invalidElement = "Invalid " + header[i] + str(row)
                        invalidLines.append(invalidElement)
                    else:
                        validLine.append(str(validateValue))
                else:
                    validLine.append(row[i])
            else:
                validLine.append(row[i])
        if len(validLine) == len(row):
            validLines.append(validLine)
        validLine = list()

    dbLoaderContainer = DatabaseLoaderContainer()
    dbLoader = dbLoaderContainer.getElement(str(header).lower())
    dbLoader.load(validLines)

    for line in validLines:
        print line

    print "-----------INVALID------------"
    print header
    for line in invalidLines:
        print line
Esempio n. 4
0
def main():
    print "Start"
    container = ValidatorContainer()
    ls = getCsvContaint()
    header = ls.pop(0)
    invalidLines = list()
    validLine = list()
    validLines = list()
    
    print header
    for row in ls:
        for i in range(len(row)):
            validator = container.getElement(header[i])
            if validator is not None:    
                if not validator.isValid(row[i]):
                    validateValue = validator.validate(row[i])
                    if validateValue is None:
                        invalidElement = "Invalid "+header[i]+str(row)
                        invalidLines.append(invalidElement)
                    else:
                        validLine.append(str(validateValue))
                else:
                    validLine.append(row[i])
            else: validLine.append(row[i])
        if len(validLine)==len(row):
            validLines.append(validLine)
        validLine=list()
        
    dbLoaderContainer = DatabaseLoaderContainer()
    dbLoader = dbLoaderContainer.getElement(str(header).lower())
    dbLoader.load(validLines)

    
    for line in validLines:
        print line
        
    print "-----------INVALID------------"
    print header
    for line in invalidLines:
        print line
Esempio n. 5
0
class Test(unittest.TestCase):
    validatorContainer =ValidatorContainer()

    def testValidatorConainer(self):
        validator  = self.validatorContainer.getElement("Mail")
        self.assertEquals(validator.isValid("*****@*****.**"),True)
        
    def testValidatorContainerGetNonExistingElement(self):
        self.assertEquals(self.validatorContainer.getElement("NotExisting"), None)
        
    
    def testRegisterValidator(self):
        validator = BooleanValidator()
        self.validatorContainer.registerElement("vypredane",validator)
        self.assertEquals(self.validatorContainer.getElement("vypredane"),validator)
        
    def testRegisterInvalidValidator(self):
        self.validatorContainer.registerElement("thing", dict())
        self.assertEquals(self.validatorContainer.getElement("thing"), None)