def test_emailRuleGetLabel(): emailrule = EmailRule("test", "at") assert emailrule.getLabel() == "test"
def test_emailRuleBool(): emailrule = EmailRule("test", "at") assert emailrule.validate(True) == False
def test_emailRuleNone(): emailrule = EmailRule("test", "at") assert emailrule.validate(None) == False
def test_emailRuleInt(): emailrule = EmailRule("test", "at") assert emailrule.validate(10) == False
def test_emailRuleInvalidEmail(): emailrule = EmailRule("test", "at") assert emailrule.validate("michael.wintersperger.chello.at") == False
def test_emailRuleWrongDomain(): emailrule = EmailRule("test", "at") assert emailrule.validate("*****@*****.**") == False
def test_emailRule(): emailrule = EmailRule("test", "at") assert emailrule.validate("*****@*****.**") == True
def loadRules(self, filename): """ This functions reads the rules applied to a data file out of the rule file applied to it, creates instances of the rule classes and saves them in a list :param filename: the name/path of the data file :type: string :return: void """ self.rules = [] # get the rule file applied to this data file rulename = self.getRule(filename) filelen = self.fileLength(rulename) with open(rulename, "r") as f: f.readline() # we ignore the 'header' and the closing line for i in range(1, filelen - 1): rule = json.loads(f.readline().rstrip(",\n")) if rule["rule"] == "text": self.rules.append( TextRule(str(rule["label"]), int(rule["minlength"]), int(rule["maxlength"]), str(rule["letters"]))) elif rule["rule"] == "number": self.rules.append( NumberRule(str(rule["label"]), int(rule["upper"]), int(rule["lower"]))) elif rule["rule"] == "email": self.rules.append( EmailRule(str(rule["label"]), str(rule["domain"]))) elif rule["rule"] == "date": self.rules.append( DateRule(str(rule["label"]), str(rule["pattern"]), str(rule["separator"]))) elif rule["rule"] == "pattern": self.rules.append( PatternRule(str(rule["label"]), str(rule["pattern"]))) elif rule["rule"] == "list": self.rules.append( ListRule(str(rule["label"]), rule["list"])) elif rule["rule"] == "dependency": self.rules.append( DependencyRule(str(rule["label"]), rule["dict"], rule["depends"])) elif rule["rule"] == "age": self.rules.append( AgeRule(str(rule["label"]), rule["depends"], str(rule["pattern"]), str(rule["separator"]))) elif rule["rule"] == "deadline": self.rules.append( DeadlineRule(str(rule["label"]), rule["depends"], str(rule["pattern"]), str(rule["separator"]))) elif rule["rule"] == "id": self.rules.append( IdRule(str(rule["label"]), int(rule["digits"]))) elif rule["rule"] == "blank": self.rules.append(BlankRule(str(rule["label"])))