Skip to content

Commit d9958e4

Browse files
committed
fix: Make TestData value_for_all return its value when targeting is off
Generated-by: termag
1 parent ca34aad commit d9958e4

4 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎ldclient/integrations/test_data.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def value_for_all(self, value: Any) -> 'FlagBuilder':
296296
:param value the desired value to be returned for all users
297297
:return the flag builder
298298
"""
299-
return self.variations(value).variation_for_all(0)
299+
return self.variations(value).variation_for_all(0).off_variation(0)
300300

301301
def variation_for_user(self, user_key: str, variation: Union[bool, int]) -> 'FlagBuilder':
302302
"""Sets the flag to return the specified variation for a specific user key when targeting

‎ldclient/integrations/test_datav2.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def value_for_all(self, value: Any) -> FlagBuilderV2:
334334
:param value the desired value to be returned for all users
335335
:return the flag builder
336336
"""
337-
return self.variations(value).variation_for_all(0)
337+
return self.variations(value).variation_for_all(0).off_variation(0)
338338

339339
def variation_for_user(self, user_key: str, variation: Union[bool, int]) -> FlagBuilderV2:
340340
"""

‎ldclient/testing/integrations/test_test_data_source.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ def verify_flag_builder(desc: str, expected_props: dict, builder_actions: Callab
6363
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'),
6464
pytest.param({'offVariation': 0}, lambda f: f.off_variation(True), id='set off variation boolean'),
6565
pytest.param({'variations': ['a', 'b', 'c'], 'offVariation': 2}, lambda f: f.variations('a', 'b', 'c').off_variation(2), id='set off variation index'),
66+
pytest.param({'variations': ['x'], 'offVariation': 0}, lambda f: f.value_for_all('x'), id='value for all'),
67+
pytest.param({'on': False, 'variations': ['x'], 'offVariation': 0}, lambda f: f.value_for_all('x').on(False), id='value for all with targeting off'),
6668
pytest.param(
6769
{
6870
'targets': [
@@ -280,6 +282,21 @@ def test_flag_evaluation_with_client():
280282
assert eval2.reason['kind'] == 'FALLTHROUGH'
281283

282284

285+
def test_value_for_all_evaluates_to_value_when_targeting_is_off():
286+
td = TestData.data_source()
287+
store = InMemoryFeatureStore()
288+
289+
client = LDClient(config=Config('SDK_KEY', update_processor_class=td, send_events=False, feature_store=store))
290+
291+
td.update(td.flag(key='test-flag').value_for_all('x').on(False))
292+
293+
detail = client.variation_detail('test-flag', Context.create('user1'), default='default')
294+
295+
assert detail.value == 'x'
296+
assert detail.variation_index == 0
297+
assert detail.reason['kind'] == 'OFF'
298+
299+
283300
def test_flag_can_evaluate_all_flags():
284301
td = TestData.data_source()
285302
store = InMemoryFeatureStore()

‎ldclient/testing/integrations/test_test_data_sourcev2.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ def verify_flag_builder_v2(desc: str, expected_props: dict, builder_actions: Cal
116116
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'),
117117
pytest.param({'offVariation': 0}, lambda f: f.off_variation(True), id='set off variation boolean'),
118118
pytest.param({'variations': ['a', 'b', 'c'], 'offVariation': 2}, lambda f: f.variations('a', 'b', 'c').off_variation(2), id='set off variation index'),
119+
pytest.param({'variations': ['x'], 'offVariation': 0}, lambda f: f.value_for_all('x'), id='value for all'),
120+
pytest.param({'on': False, 'variations': ['x'], 'offVariation': 0}, lambda f: f.value_for_all('x').on(False), id='value for all with targeting off'),
119121
pytest.param(
120122
{
121123
'targets': [

0 commit comments

Comments
 (0)