@@ -45,3 +45,64 @@ def test_matches_rules_true_with_numeric_value_and_regex():
45
45
)
46
46
rule = Rule (conditions = [condition ])
47
47
assert matches_any_rule ({"age" : 99 }, [rule ]) is True
48
+
49
+
50
+ def test_one_of_operator_with_boolean ():
51
+ oneOfRule = Rule (
52
+ conditions = [
53
+ Condition (operator = OperatorType .ONE_OF , value = ["True" ], attribute = "enabled" )
54
+ ]
55
+ )
56
+ notOneOfRule = Rule (
57
+ conditions = [
58
+ Condition (
59
+ operator = OperatorType .NOT_ONE_OF , value = ["True" ], attribute = "enabled"
60
+ )
61
+ ]
62
+ )
63
+ assert matches_any_rule ({"enabled" : True }, [oneOfRule ]) is True
64
+ assert matches_any_rule ({"enabled" : False }, [oneOfRule ]) is False
65
+ assert matches_any_rule ({"enabled" : True }, [notOneOfRule ]) is False
66
+ assert matches_any_rule ({"enabled" : False }, [notOneOfRule ]) is True
67
+
68
+
69
+ def test_one_of_operator_with_string ():
70
+ oneOfRule = Rule (
71
+ conditions = [
72
+ Condition (
73
+ operator = OperatorType .ONE_OF , value = ["john" , "ron" ], attribute = "name"
74
+ )
75
+ ]
76
+ )
77
+ notOneOfRule = Rule (
78
+ conditions = [
79
+ Condition (operator = OperatorType .NOT_ONE_OF , value = ["ron" ], attribute = "name" )
80
+ ]
81
+ )
82
+ assert matches_any_rule ({"name" : "john" }, [oneOfRule ]) is True
83
+ assert matches_any_rule ({"name" : "ron" }, [oneOfRule ]) is True
84
+ assert matches_any_rule ({"name" : "sam" }, [oneOfRule ]) is False
85
+ assert matches_any_rule ({"name" : "ron" }, [notOneOfRule ]) is False
86
+ assert matches_any_rule ({"name" : "sam" }, [notOneOfRule ]) is True
87
+
88
+
89
+ def test_one_of_operator_with_number ():
90
+ oneOfRule = Rule (
91
+ conditions = [
92
+ Condition (
93
+ operator = OperatorType .ONE_OF , value = ["14" , "15.11" ], attribute = "number"
94
+ )
95
+ ]
96
+ )
97
+ notOneOfRule = Rule (
98
+ conditions = [
99
+ Condition (
100
+ operator = OperatorType .NOT_ONE_OF , value = ["10" ], attribute = "number"
101
+ )
102
+ ]
103
+ )
104
+ assert matches_any_rule ({"number" : "14" }, [oneOfRule ]) is True
105
+ assert matches_any_rule ({"number" : 15.11 }, [oneOfRule ]) is True
106
+ assert matches_any_rule ({"number" : "10" }, [oneOfRule ]) is False
107
+ assert matches_any_rule ({"number" : "10" }, [notOneOfRule ]) is False
108
+ assert matches_any_rule ({"number" : 11 }, [notOneOfRule ]) is True
0 commit comments