Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ldclient/integrations/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ldclient/integrations/test_datav2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
17 changes: 17 additions & 0 deletions ldclient/testing/integrations/test_test_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions ldclient/testing/integrations/test_test_data_sourcev2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand Down
Loading