示例#1
0
def test_emailRuleGetLabel():
    emailrule = EmailRule("test", "at")
    assert emailrule.getLabel() == "test"
示例#2
0
def test_emailRuleBool():
    emailrule = EmailRule("test", "at")
    assert emailrule.validate(True) == False
示例#3
0
def test_emailRuleNone():
    emailrule = EmailRule("test", "at")
    assert emailrule.validate(None) == False
示例#4
0
def test_emailRuleInt():
    emailrule = EmailRule("test", "at")
    assert emailrule.validate(10) == False
示例#5
0
def test_emailRuleInvalidEmail():
    emailrule = EmailRule("test", "at")
    assert emailrule.validate("michael.wintersperger.chello.at") == False
示例#6
0
def test_emailRuleWrongDomain():
    emailrule = EmailRule("test", "at")
    assert emailrule.validate("*****@*****.**") == False
示例#7
0
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"])))