def test_evaluate_second_variation_no_target_match(): feature = copy(minimal_feature) hash_value = long(hashlib.sha1('feature.key.abc.xyz').hexdigest()[:15], 16) / float(0xFFFFFFFFFFFFFFF) feature['variations'] = [ { u'value': True, u'weight': floor(hash_value) - 1, u'targets': [ { u'attribute': u'bizzle', u'op': u'in', u'values': [ u'defg' ] } ] }, { u'value': False, u'weight': 100 - (floor(hash_value) - 1), u'targets': [ { u'attribute': u'bazzle', u'op': u'in', u'values': [ u'zyx' ] }, { u'attribute': u'bizzle', u'op': u'in', u'values': [ u'defg' ] } ] } ] assert ldclient._evaluate(feature, user) == False
def test_evaluate_second_variation_target_match(): feature = copy(minimal_feature) feature['variations'] = [ { u'value': True, u'weight': 0, u'targets': [ { u'attribute': u'bizzle', u'op': u'in', u'values': [ u'defg' ] } ] }, { u'value': False, u'weight': 100, u'targets': [ { u'attribute': u'bazzle', u'op': u'in', u'values': [ u'zyx' ] }, { u'attribute': u'bizzle', u'op': u'in', u'values': [ u'def' ] } ] } ] assert ldclient._evaluate(feature, user) == False
def test_evaluate_first_variation_both_targets_match_user_key_match_no_user_target(): feature = copy(minimal_feature) feature['variations'] = [ { u'value': True, u'weight': 0, u'targets': [ { u'attribute': u'key', u'op': u'in', u'values': [ 'xyz' ] }, ] }, { u'value': False, u'weight': 100, u'targets': [ { u'attribute': u'bazzle', u'op': u'in', u'values': [ u'zyx' ] }, { u'attribute': u'bizzle', u'op': u'in', u'values': [ u'def' ] } ] } ] assert ldclient._evaluate(feature, user) == True
def mock_toggle(key, user, default): hash = minimal_feature = { u'key': u'feature.key', u'salt': u'abc', u'on': True, u'variations': [ { u'value': True, u'weight': 100, u'targets': [] }, { u'value': False, u'weight': 0, u'targets': [] } ] } val = ldclient._evaluate(hash, user) if val is None: return defer.succeed(default) return defer.succeed(val)
def _toggle(self, key, user, default): self._toggle_count += 1 hash = minimal_feature = { u'key': u'feature.key', u'salt': u'abc', u'on': True, u'variations': [ { u'value': True, u'weight': 100, u'targets': [] }, { u'value': False, u'weight': 0, u'targets': [] } ] } val = ldclient._evaluate(hash, user) if val is None: return default return val
def test_evaluate_feature_off(): feature = copy(minimal_feature) feature['on'] = False assert ldclient._evaluate(feature, user) == None