diff --git a/ldclient/integrations/test_data.py b/ldclient/integrations/test_data.py index 1aff86f2..591b2f2b 100644 --- a/ldclient/integrations/test_data.py +++ b/ldclient/integrations/test_data.py @@ -296,7 +296,7 @@ def value_for_all(self, value: Any) -> 'FlagBuilder': :param value the desired value to be returned for all users :return the flag builder """ - return self.variations(value).variation_for_all(0) + return self.variations(value).variation_for_all(0).off_variation(0) def variation_for_user(self, user_key: str, variation: Union[bool, int]) -> 'FlagBuilder': """Sets the flag to return the specified variation for a specific user key when targeting diff --git a/ldclient/integrations/test_datav2.py b/ldclient/integrations/test_datav2.py index 5c13dc45..3f68bdbf 100644 --- a/ldclient/integrations/test_datav2.py +++ b/ldclient/integrations/test_datav2.py @@ -334,7 +334,7 @@ def value_for_all(self, value: Any) -> FlagBuilderV2: :param value the desired value to be returned for all users :return the flag builder """ - return self.variations(value).variation_for_all(0) + return self.variations(value).variation_for_all(0).off_variation(0) def variation_for_user(self, user_key: str, variation: Union[bool, int]) -> FlagBuilderV2: """ diff --git a/ldclient/testing/integrations/test_test_data_source.py b/ldclient/testing/integrations/test_test_data_source.py index e12f2f72..ddadeb39 100644 --- a/ldclient/testing/integrations/test_test_data_source.py +++ b/ldclient/testing/integrations/test_test_data_source.py @@ -63,6 +63,8 @@ def verify_flag_builder(desc: str, expected_props: dict, builder_actions: Callab pytest.param({'variations': ['a', 'b', 'c'], 'fallthrough': {'variation': 2}}, lambda f: f.variations('a', 'b', 'c').variation_for_all(2), id='set variation index for all'), pytest.param({'offVariation': 0}, lambda f: f.off_variation(True), id='set off variation boolean'), pytest.param({'variations': ['a', 'b', 'c'], 'offVariation': 2}, lambda f: f.variations('a', 'b', 'c').off_variation(2), id='set off variation index'), + pytest.param({'variations': ['x'], 'offVariation': 0}, lambda f: f.value_for_all('x'), id='value for all'), + pytest.param({'on': False, 'variations': ['x'], 'offVariation': 0}, lambda f: f.value_for_all('x').on(False), id='value for all with targeting off'), pytest.param( { 'targets': [ @@ -280,6 +282,21 @@ def test_flag_evaluation_with_client(): assert eval2.reason['kind'] == 'FALLTHROUGH' +def test_value_for_all_evaluates_to_value_when_targeting_is_off(): + td = TestData.data_source() + store = InMemoryFeatureStore() + + client = LDClient(config=Config('SDK_KEY', update_processor_class=td, send_events=False, feature_store=store)) + + td.update(td.flag(key='test-flag').value_for_all('x').on(False)) + + detail = client.variation_detail('test-flag', Context.create('user1'), default='default') + + assert detail.value == 'x' + assert detail.variation_index == 0 + assert detail.reason['kind'] == 'OFF' + + def test_flag_can_evaluate_all_flags(): td = TestData.data_source() store = InMemoryFeatureStore() diff --git a/ldclient/testing/integrations/test_test_data_sourcev2.py b/ldclient/testing/integrations/test_test_data_sourcev2.py index a0ad4c27..e56e3ce8 100644 --- a/ldclient/testing/integrations/test_test_data_sourcev2.py +++ b/ldclient/testing/integrations/test_test_data_sourcev2.py @@ -116,6 +116,8 @@ def verify_flag_builder_v2(desc: str, expected_props: dict, builder_actions: Cal pytest.param({'variations': ['a', 'b', 'c'], 'fallthrough': {'variation': 2}}, lambda f: f.variations('a', 'b', 'c').variation_for_all(2), id='set variation index for all'), pytest.param({'offVariation': 0}, lambda f: f.off_variation(True), id='set off variation boolean'), pytest.param({'variations': ['a', 'b', 'c'], 'offVariation': 2}, lambda f: f.variations('a', 'b', 'c').off_variation(2), id='set off variation index'), + pytest.param({'variations': ['x'], 'offVariation': 0}, lambda f: f.value_for_all('x'), id='value for all'), + pytest.param({'on': False, 'variations': ['x'], 'offVariation': 0}, lambda f: f.value_for_all('x').on(False), id='value for all with targeting off'), pytest.param( { 'targets': [