|
4 | 4 | Condition,
|
5 | 5 | evaluate_condition,
|
6 | 6 | matches_rule,
|
| 7 | + to_string, |
7 | 8 | )
|
8 | 9 |
|
9 | 10 | greater_than_condition = Condition(operator=OperatorType.GT, value=10, attribute="age")
|
@@ -137,10 +138,22 @@ def test_evaluate_condition_matches():
|
137 | 138 | Condition(operator=OperatorType.MATCHES, value="^test.*", attribute="email"),
|
138 | 139 |
|
139 | 140 | )
|
| 141 | + assert evaluate_condition( |
| 142 | + Condition(operator=OperatorType.MATCHES, value="true", attribute="flag"), |
| 143 | + {"flag": True}, |
| 144 | + ) |
| 145 | + assert evaluate_condition( |
| 146 | + Condition(operator=OperatorType.MATCHES, value="false", attribute="flag"), |
| 147 | + {"flag": False}, |
| 148 | + ) |
140 | 149 | assert not evaluate_condition(
|
141 | 150 | Condition(operator=OperatorType.MATCHES, value="^test.*", attribute="email"),
|
142 | 151 |
|
143 | 152 | )
|
| 153 | + assert not evaluate_condition( |
| 154 | + Condition(operator=OperatorType.MATCHES, value="False", attribute="flag"), |
| 155 | + {"flag": False}, |
| 156 | + ) |
144 | 157 |
|
145 | 158 |
|
146 | 159 | def test_evaluate_condition_matches_partial():
|
@@ -348,10 +361,10 @@ def test_evaluate_condition_one_of_int():
|
348 | 361 |
|
349 | 362 | def test_evaluate_condition_one_of_boolean():
|
350 | 363 | one_of_condition_boolean = Condition(
|
351 |
| - operator=OperatorType.ONE_OF, value=[True, False], attribute="status" |
| 364 | + operator=OperatorType.ONE_OF, value=["true", "false"], attribute="status" |
352 | 365 | )
|
353 | 366 | assert evaluate_condition(one_of_condition_boolean, {"status": False})
|
354 |
| - assert evaluate_condition(one_of_condition_boolean, {"status": "False"}) |
| 367 | + assert evaluate_condition(one_of_condition_boolean, {"status": "false"}) |
355 | 368 | assert not evaluate_condition(one_of_condition_boolean, {"status": "Maybe"})
|
356 | 369 | assert not evaluate_condition(one_of_condition_boolean, {"status": 0})
|
357 | 370 | assert not evaluate_condition(one_of_condition_boolean, {"status": 1})
|
@@ -391,3 +404,26 @@ def test_is_not_null_operator():
|
391 | 404 | assert not evaluate_condition(is_not_null_condition, {"size": None})
|
392 | 405 | assert evaluate_condition(is_not_null_condition, {"size": 10})
|
393 | 406 | assert not evaluate_condition(is_not_null_condition, {})
|
| 407 | + |
| 408 | + |
| 409 | +def test_to_string_string(): |
| 410 | + assert to_string("test") == "test" |
| 411 | + |
| 412 | + |
| 413 | +def test_to_string_int(): |
| 414 | + assert to_string(10) == "10" |
| 415 | + |
| 416 | + |
| 417 | +def test_to_string_float(): |
| 418 | + assert to_string(10.5) == "10.5" |
| 419 | + assert to_string(10.0) == "10" |
| 420 | + assert to_string(123456789.0) == "123456789" |
| 421 | + |
| 422 | + |
| 423 | +def test_to_string_bool(): |
| 424 | + assert to_string(True) == "true" |
| 425 | + assert to_string(False) == "false" |
| 426 | + |
| 427 | + |
| 428 | +def test_to_string_null(): |
| 429 | + assert to_string(None) == "null" |
0 commit comments