@@ -664,7 +664,7 @@ def test_segment_condition_matches_context_value_for_modulo(
664664 ),
665665 ),
666666)
667- def test_get_flag_result_from_feature_context__call_returns_expected (
667+ def test_get_flag_result_from_feature_context__calls_returns_expected (
668668 percentage_value : int ,
669669 expected_result : FlagResult ,
670670 mocker : MockerFixture ,
@@ -711,6 +711,50 @@ def test_get_flag_result_from_feature_context__call_returns_expected(
711711 )
712712
713713
714+ def test_get_flag_result_from_feature_context__null_key__calls_returns_expected (
715+ mocker : MockerFixture ,
716+ ) -> None :
717+ # Given
718+ expected_feature_context_key = "2"
719+ # a None key is provided (no identity context present)
720+ expected_key = None
721+
722+ get_hashed_percentage_for_object_ids_mock = mocker .patch (
723+ "flag_engine.segments.evaluator.get_hashed_percentage_for_object_ids" ,
724+ )
725+
726+ feature_context : FeatureContext = {
727+ "key" : expected_feature_context_key ,
728+ "feature_key" : "1" ,
729+ "enabled" : False ,
730+ "name" : "my_feature" ,
731+ "value" : "control" ,
732+ "variants" : [
733+ {"value" : "foo" , "weight" : 30 },
734+ {"value" : "bar" , "weight" : 30 },
735+ ],
736+ }
737+
738+ # When
739+ result = get_flag_result_from_feature_context (
740+ feature_context = feature_context ,
741+ key = expected_key ,
742+ )
743+
744+ # Then
745+ # the value of the feature state is the default one
746+ assert result == {
747+ "enabled" : False ,
748+ "feature_key" : "1" ,
749+ "name" : "my_feature" ,
750+ "reason" : "DEFAULT" ,
751+ "value" : "control" ,
752+ }
753+
754+ # the function is not called as there is no key to hash against
755+ get_hashed_percentage_for_object_ids_mock .assert_not_called ()
756+
757+
714758@pytest .mark .parametrize (
715759 "property" ,
716760 [
0 commit comments