def set_forced_variation(self, experiment_key, user_id, variation_key):
    """ Sets users to a map of experiments to forced variations.

      Args:
        experiment_key: Key for experiment.
        user_id: The user ID.
        variation_key: Key for variation. If None, then clear the existing experiment-to-variation mapping.

      Returns:
        A boolean value that indicates if the set completed successfully.
    """
    experiment = self.get_experiment_from_key(experiment_key)
    if not experiment:
      # The invalid experiment key will be logged inside this call.
      return False

    experiment_id = experiment.id
    if variation_key is None:
      if user_id in self.forced_variation_map:
        experiment_to_variation_map = self.forced_variation_map.get(user_id)
        if experiment_id in experiment_to_variation_map:
          del(self.forced_variation_map[user_id][experiment_id])
          self.logger.debug('Variation mapped to experiment "%s" has been removed for user "%s".' % (
            experiment_key,
            user_id
          ))
        else:
          self.logger.debug('Nothing to remove. Variation mapped to experiment "%s" for user "%s" does not exist.' % (
            experiment_key,
            user_id
          ))
      else:
        self.logger.debug('Nothing to remove. User "%s" does not exist in the forced variation map.' % user_id)
      return True

    if not validator.is_non_empty_string(variation_key):
      self.logger.debug('Variation key is invalid.')
      return False

    forced_variation = self.get_variation_from_key(experiment_key, variation_key)
    if not forced_variation:
      # The invalid variation key will be logged inside this call.
      return False

    variation_id = forced_variation.id

    if user_id not in self.forced_variation_map:
      self.forced_variation_map[user_id] = {experiment_id: variation_id}
    else:
      self.forced_variation_map[user_id][experiment_id] = variation_id

    self.logger.debug('Set variation "%s" for experiment "%s" and user "%s" in the forced variation map.' % (
      variation_id,
      experiment_id,
      user_id
    ))
    return True
def set_forced_variation ( self , experiment_key , user_id , variation_key ) : experiment = self . get_experiment_from_key ( experiment_key ) if not experiment : return False experiment_id = experiment . id if variation_key is None : if user_id in self . forced_variation_map : experiment_to_variation_map = self . forced_variation_map . get ( user_id ) if experiment_id in experiment_to_variation_map : del ( self . forced_variation_map [ user_id ] [ experiment_id ] ) self . logger . debug ( 'Variation mapped to experiment "%s" has been removed for user "%s".' % ( experiment_key , user_id ) ) else : self . logger . debug ( 'Nothing to remove. Variation mapped to experiment "%s" for user "%s" does not exist.' % ( experiment_key , user_id ) ) else : self . logger . debug ( 'Nothing to remove. User "%s" does not exist in the forced variation map.' % user_id ) return True if not validator . is_non_empty_string ( variation_key ) : self . logger . debug ( 'Variation key is invalid.' ) return False forced_variation = self . get_variation_from_key ( experiment_key , variation_key ) if not forced_variation : return False variation_id = forced_variation . id if user_id not in self . forced_variation_map : self . forced_variation_map [ user_id ] = { experiment_id : variation_id } else : self . forced_variation_map [ user_id ] [ experiment_id ] = variation_id self . logger . debug ( 'Set variation "%s" for experiment "%s" and user "%s" in the forced variation map.' % ( variation_id , experiment_id , user_id ) ) return True
Sets users to a map of experiments to forced variations.

      Args:
        experiment_key: Key for experiment.
        user_id: The user ID.
        variation_key: Key for variation. If None, then clear the existing experiment-to-variation mapping.

      Returns:
        A boolean value that indicates if the set completed successfully.