Beispiel #1
0
    def test_match_comparison(self):
        schema = Schema().with_rule(ValueComparisonRule("LIKE", "A.*"))
        results = schema.validate("ABC")
        assert 0 == len(results)

        results = schema.validate("XYZ")
        assert 1 == len(results)
Beispiel #2
0
    def test_excluded_rule(self):
        schema = Schema().with_rule(ExcludedRule("AAA", "BBB", "CCC", None))
        results = schema.validate("AAA")
        assert 1 == len(results)

        results = schema.validate("ABC")
        assert 0 == len(results)
    def test_only_one_exist_rule(self):
        obj = ObjectTest()
        schema = Schema().with_rule(OnlyOneExistRule("Missing_Property", "String_Property", "Null_Property"))
        results = schema.validate(obj)
        assert 0 == len(results)

        schema = Schema().with_rule(OnlyOneExistRule("String_Property", "Null_Property", "int_Field"))
        results = schema.validate(obj)
        assert 1 == len(results)
Beispiel #4
0
    def test_more_comparison(self):
        schema = Schema().with_rule(ValueComparisonRule("GE", 123))
        results = schema.validate(123)
        assert 0 == len(results)

        results = schema.validate(432)
        assert 0 == len(results)

        schema = Schema().with_rule(ValueComparisonRule("GT", 123))
        results = schema.validate(123)
        assert 1 == len(results)
Beispiel #5
0
    def test_not_equal_comparison(self):
        schema = Schema().with_rule(ValueComparisonRule("NE", 123))
        results = schema.validate(123)
        assert 1 == len(results)

        results = schema.validate(432)
        assert 0 == len(results)

        schema = Schema().with_rule(ValueComparisonRule("NE", "ABC"))
        results = schema.validate("XYZ")
        assert 0 == len(results)
Beispiel #6
0
    def test_or_rule(self):
        schema = Schema().with_rule(
            OrRule(ValueComparisonRule("=", 1), ValueComparisonRule("=", 2)))
        result = schema.validate(-100)
        assert 2 == len(result)

        result = schema.validate(1)
        assert 0 == len(result)

        result = schema.validate(200)
        assert 2 == len(result)
Beispiel #7
0
    def test_and_rule(self):
        schema = Schema().with_rule(
            AndRule(ValueComparisonRule(">", 0), ValueComparisonRule("<",
                                                                     200)))
        result = schema.validate(-100)
        assert 1 == len(result)

        result = schema.validate(100)
        assert 0 == len(result)

        result = schema.validate(200)
        assert 1 == len(result)
    def test_properties_comparison(self):
        obj = TestObject()
        schema = Schema().with_rule(
            PropertiesComparisonRule("String_Property", "EQ", "Null_Property"))

        obj.string_property = "ABC"
        obj.null_property = "ABC"
        results = schema.validate(obj)
        assert 0 == len(results)

        obj.null_property = "XYZ"
        results = schema.validate(obj)
        assert 1 == len(results)
    def test_and_rule(self):
        obj = ObjectTest()

        schema = Schema().with_rule(
            AndRule(
                AtLeastOneExistsRule("missing_property", "string_property",
                                     "null_property"),
                AtLeastOneExistsRule("string_property", "null_property",
                                     "int_field")))

        results = schema.validate(obj)
        assert len(results) == 0

        schema = Schema().with_rule(
            AndRule(
                AtLeastOneExistsRule("missing_property", "string_property",
                                     "null_property"),
                AtLeastOneExistsRule("missing_property", "null_property")))
        results = schema.validate(obj)
        assert len(results) == 1
Beispiel #10
0
 def test_required(self):
     schema = Schema().make_required()
     results = schema.validate(None)
     assert 1 == len(results)