|
6 | 6 |
|
7 | 7 | from flag_engine.context.types import EvaluationContext |
8 | 8 | from flag_engine.segments import constants |
9 | | -from flag_engine.segments.evaluator import _matches_context_value, is_context_in_segment |
| 9 | +from flag_engine.segments.evaluator import ( |
| 10 | + _matches_context_value, |
| 11 | + context_matches_condition, |
| 12 | + is_context_in_segment, |
| 13 | +) |
10 | 14 | from flag_engine.segments.models import ( |
11 | 15 | SegmentConditionModel, |
12 | 16 | SegmentModel, |
@@ -479,6 +483,63 @@ def test_segment_condition_matches_context_value_for_semver( |
479 | 483 | assert result == expected_result |
480 | 484 |
|
481 | 485 |
|
| 486 | +@pytest.mark.parametrize( |
| 487 | + "context,condition,segment_key,expected_result", |
| 488 | + ( |
| 489 | + ( |
| 490 | + {"identity": {"traits": {trait_key_1: False}}}, |
| 491 | + SegmentConditionModel( |
| 492 | + operator=constants.EQUAL, |
| 493 | + property_=trait_key_1, |
| 494 | + value="false", |
| 495 | + ), |
| 496 | + "segment_key", |
| 497 | + True, |
| 498 | + ), |
| 499 | + ( |
| 500 | + {"identity": {"traits": {trait_key_1: True}}}, |
| 501 | + SegmentConditionModel( |
| 502 | + operator=constants.EQUAL, |
| 503 | + property_=trait_key_1, |
| 504 | + value="true", |
| 505 | + ), |
| 506 | + "segment_key", |
| 507 | + True, |
| 508 | + ), |
| 509 | + ( |
| 510 | + {"identity": {"traits": {trait_key_1: 12}}}, |
| 511 | + SegmentConditionModel( |
| 512 | + operator=constants.EQUAL, |
| 513 | + property_=trait_key_1, |
| 514 | + value="12", |
| 515 | + ), |
| 516 | + "segment_key", |
| 517 | + True, |
| 518 | + ), |
| 519 | + ( |
| 520 | + {"identity": {"traits": {trait_key_1: None}}}, |
| 521 | + SegmentConditionModel( |
| 522 | + operator=constants.IS_SET, |
| 523 | + property_=trait_key_1, |
| 524 | + value="false", |
| 525 | + ), |
| 526 | + "segment_key", |
| 527 | + False, |
| 528 | + ), |
| 529 | + ), |
| 530 | +) |
| 531 | +def test_context_matches_condition( |
| 532 | + context: EvaluationContext, |
| 533 | + condition: SegmentConditionModel, |
| 534 | + segment_key: str, |
| 535 | + expected_result: bool, |
| 536 | +) -> None: |
| 537 | + # Given / When |
| 538 | + result = context_matches_condition(context, condition, segment_key) |
| 539 | + # Then |
| 540 | + assert result == expected_result |
| 541 | + |
| 542 | + |
482 | 543 | @pytest.mark.parametrize( |
483 | 544 | "trait_value, condition_value, expected_result", |
484 | 545 | [ |
|
0 commit comments