@@ -984,7 +984,7 @@ def test_get_evaluation_result__identity_override__returns_expected(
984984 ),
985985 ),
986986)
987- def test_get_flag_result_from_feature_context__call_return_expected (
987+ def test_get_flag_result_from_feature_context__calls_returns_expected (
988988 percentage_value : int ,
989989 expected_result : FlagResult ,
990990 mocker : MockerFixture ,
@@ -1031,6 +1031,50 @@ def test_get_flag_result_from_feature_context__call_return_expected(
10311031 )
10321032
10331033
1034+ def test_get_flag_result_from_feature_context__null_key__calls_returns_expected (
1035+ mocker : MockerFixture ,
1036+ ) -> None :
1037+ # Given
1038+ expected_feature_context_key = "2"
1039+ # a None key is provided (no identity context present)
1040+ expected_key = None
1041+
1042+ get_hashed_percentage_for_object_ids_mock = mocker .patch (
1043+ "flag_engine.segments.evaluator.get_hashed_percentage_for_object_ids" ,
1044+ )
1045+
1046+ feature_context : FeatureContext = {
1047+ "key" : expected_feature_context_key ,
1048+ "feature_key" : "1" ,
1049+ "enabled" : False ,
1050+ "name" : "my_feature" ,
1051+ "value" : "control" ,
1052+ "variants" : [
1053+ {"value" : "foo" , "weight" : 30 },
1054+ {"value" : "bar" , "weight" : 30 },
1055+ ],
1056+ }
1057+
1058+ # When
1059+ result = get_flag_result_from_feature_context (
1060+ feature_context = feature_context ,
1061+ key = expected_key ,
1062+ )
1063+
1064+ # Then
1065+ # the value of the feature state is the default one
1066+ assert result == {
1067+ "enabled" : False ,
1068+ "feature_key" : "1" ,
1069+ "name" : "my_feature" ,
1070+ "reason" : "DEFAULT" ,
1071+ "value" : "control" ,
1072+ }
1073+
1074+ # the function is not called as there is no key to hash against
1075+ get_hashed_percentage_for_object_ids_mock .assert_not_called ()
1076+
1077+
10341078@pytest .mark .parametrize (
10351079 "property" ,
10361080 [
0 commit comments