Exemple #1
0
def test_ageRuleGetDepends():
    agerule = AgeRule("test", "test1", "%d-%m-%Y", "-")
    assert agerule.getDepends() == "test1"
Exemple #2
0
def test_ageRuleBool():
    agerule = AgeRule("test", "test1", "%d-%m-%Y", "-")
    assert agerule.validate(True) == None
Exemple #3
0
def test_ageRuleNone():
    agerule = AgeRule("test", "test1", "%d-%m-%Y", "-")
    assert agerule.validate(None) == None
Exemple #4
0
def test_ageRuleInt():
    agerule = AgeRule("test", "test1", "%d-%m-%Y", "-")
    assert agerule.validate(22091999) == None
Exemple #5
0
def test_ageRuleWrongSeperator():
    agerule = AgeRule("test", "test1", "%d-%m-%Y", "-")
    assert agerule.validate("22/09/1999") == None
Exemple #6
0
def test_ageRuleWrongPattern():
    agerule = AgeRule("test", "test1", "%d-%m-%Y", "-")
    assert agerule.validate("09-22-1999") == None
Exemple #7
0
def test_ageRule():
    agerule = AgeRule("test", "test1", "%d-%m-%Y", "-")
    assert agerule.validate("22-09-1999") == 19
    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"])))