old_contents: from __future__ import absolute_import
  import collections
  import random
  
  from dimagi.utils.decorators.memoized import memoized
  
  ABTestConfig = collections.namedtuple('ABTestConfig', ('name', 'slug', 'options'))
  
  
  class ABTest(object):
      """
      Initialize A/B test with an ABTestConfig.
      """
  
      def __init__(self, config, request):
          self.name = config.name
          self.slug = config.slug
          self.options = config.options
          self.request = request
  
      @property
      def _cookie_id(self):
          return "{}_ab".format(self.slug)
  
      @property
      @memoized
      def version(self):
          if self._cookie_id not in self.request.COOKIES:
              version = random.sample(self.options, 1)[0]  # todo weighted options
          else:
              version = self.request.COOKIES[self._cookie_id]
          return version
  
      def update_response(self, response):
          response.set_cookie(self._cookie_id, self.version)
  
      @property
      def context(self):
          return {
              'name': self.name,
              'version': self.version,
          }
  
  
  NEW_USER_NUMBER_OPTION_SHOW_NUM = 'show_number'
  NEW_USER_NUMBER_OPTION_HIDE_NUM = 'hide_number'
  
  
  NEW_USER_NUMBER = ABTestConfig(
      'New User Phone Number',
      'new_phone_jan2016',
      (NEW_USER_NUMBER_OPTION_SHOW_NUM, NEW_USER_NUMBER_OPTION_HIDE_NUM)
  )
  
  
  APP_BUILDER_VIDEO_ON = 'on'
  APP_BUILDER_VIDEO_OFF = 'off'
  
  
  APP_BUILDER_VIDEO = ABTestConfig(
      'Onboarding Video Inside App Builder',
      'app_builder_video_aug2017',
      (APP_BUILDER_VIDEO_ON, APP_BUILDER_VIDEO_OFF)
  )
  
new_contents: from __future__ import absolute_import
  import collections
  import random
  
  from dimagi.utils.decorators.memoized import memoized
  
  ABTestConfig = collections.namedtuple('ABTestConfig', ('name', 'slug', 'options'))
  
  
  class ABTest(object):
      """
      Initialize A/B test with an ABTestConfig.
      """
  
      def __init__(self, config, request):
          self.name = config.name
          self.slug = config.slug
          self.options = config.options
          self.request = request
  
      @property
      def _cookie_id(self):
          return "{}_ab".format(self.slug)
  
      @property
      @memoized
      def version(self):
          if self._cookie_id not in self.request.COOKIES:
              version = random.sample(self.options, 1)[0]  # todo weighted options
          else:
              version = self.request.COOKIES[self._cookie_id]
          return version
  
      def update_response(self, response):
          response.set_cookie(self._cookie_id, self.version)
  
      @property
      def context(self):
          return {
              'name': self.name,
              'version': self.version,
          }
  
  
  NEW_USER_NUMBER_OPTION_SHOW_NUM = 'show_number'
  NEW_USER_NUMBER_OPTION_HIDE_NUM = 'hide_number'
  
  
  NEW_USER_NUMBER = ABTestConfig(
      'New User Phone Number',
      'new_phone_jan2016',
      (NEW_USER_NUMBER_OPTION_SHOW_NUM, NEW_USER_NUMBER_OPTION_HIDE_NUM)
  )
  
  
  APP_BUILDER_VIDEO_ON = 'on'
  APP_BUILDER_VIDEO_OFF = 'off'
  
  
  APP_BUILDER_VIDEO = ABTestConfig(
      'Onboarding Video Inside App Builder',
      'app_builder_video_aug2017',
      (APP_BUILDER_VIDEO_ON, APP_BUILDER_VIDEO_OFF)
  )
  
  NEW_USER_PERSONA_OPTION_SHOW = 'show_persona'
  NEW_USER_PERSONA_OPTION_HIDE = 'hide_persona'
  
  
  NEW_USER_PERSONA_FIELD = ABTestConfig(
      'New User Persona Field',
      'new_user_persona_field_nov2017',
      (NEW_USER_PERSONA_OPTION_SHOW, NEW_USER_PERSONA_OPTION_HIDE)
  )
  
subject: add user persona field ab test