예제 #1
0
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
예제 #2
0
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
예제 #3
0
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
예제 #4
0
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)
예제 #5
0
 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
예제 #6
0
def test_evaluate_feature_off():
  feature = copy(minimal_feature)
  feature['on'] = False
  assert ldclient._evaluate(feature, user) == None