Exemplo n.º 1
0
    def setUp(self) -> None:
        super().setUp()
        mongo.cache.clear()
        self.database = mongo.NoPiiMongoDatabase(mongomock.MongoClient().test)
        self.database.diagnostic_main_challenges.insert_many([
            {
                'categoryId': 'women',
                'strategiesIntroduction': 'Voici vos strats',
                'filters': ['for-women'],
                'order': 1,
            },
            {
                'categoryId': 'bravo',
                'strategiesIntroduction': 'Voici vos stratégies',
                'order': 2,
            },
        ])
        self.database.action_templates.insert_one({
            '_id': 'rec1CWahSiEtlwEHW',
            'goal': 'Reorientation !',
        })

        self.user = user_pb2.User(
            features_enabled=features_pb2.Features(
                advisor=features_pb2.ACTIVE, workbench=features_pb2.ACTIVE),
            profile=user_profile_pb2.UserProfile(name='Margaux', gender=user_profile_pb2.FEMININE))
        proto.CachedCollection.update_cache_version()
Exemplo n.º 2
0
    def test_error_in_json(self) -> None:
        """No assignment of features if we have a JSON error in the env var."""

        features_enabled = features_pb2.Features()
        features.assign_features(features_enabled, is_new=True)
        self._assert_is_empty(features_enabled)

        self._assert_logging_error('EXPERIMENTS_ROLLOUTS env')
Exemplo n.º 3
0
    def test_assign_random_existing(self) -> None:
        """Assign randomly in two branches and unassigned depending on thresholds for old users."""

        with mock.patch('random.random', new=lambda: .1):
            features_enabled = features_pb2.Features()
            features.assign_features(features_enabled, is_new=False)
            self.assertEqual(features_pb2.CONTROL,
                             features_enabled.action_plan)

        with mock.patch('random.random', new=lambda: .5):
            features_enabled = features_pb2.Features()
            features.assign_features(features_enabled, is_new=False)
            self.assertEqual(features_pb2.ACTIVE, features_enabled.action_plan)

        with mock.patch('random.random', new=lambda: .8):
            features_enabled = features_pb2.Features()
            features.assign_features(features_enabled, is_new=False)
            self._assert_is_empty(features_enabled)
Exemplo n.º 4
0
    def test_assign_more_than_100_percent(self) -> None:
        """Trying to assign more than 100% of users."""

        features_enabled = features_pb2.Features()
        features.assign_features(features_enabled, is_new=True)
        self._assert_is_empty(features_enabled)

        self._assert_logging_error(
            'Config for feature "action_plan" is invalid in EXPERIMENTS_ROLLOUTS env var:'
        )
Exemplo n.º 5
0
    def test_not_a_binary_experiment(self) -> None:
        """Does not work (but no crash) if we use a feature that is not an experiment."""

        features_enabled = features_pb2.Features()
        features.assign_features(features_enabled, is_new=True)
        self._assert_is_empty(features_enabled)

        self._assert_logging_error(
            'Feature configured in EXPERIMENTS_ROLLOUTS env var is not a binary experiment: '
            'follow_up_long_term')
Exemplo n.º 6
0
    def test_error_in_other_feature_name(self) -> None:
        """Still apply an experiment if another one use the wrong env var."""

        features_enabled = features_pb2.Features()
        features.assign_features(features_enabled, is_new=True)
        self.assertEqual(features_pb2.ACTIVE, features_enabled.action_plan)

        self._assert_logging_error(
            'Feature configured in EXPERIMENTS_ROLLOUTS env var does not exist: b'
        )
Exemplo n.º 7
0
    def test_error_in_feature_name(self) -> None:
        """Does not crash if we use the wrong env var."""

        features_enabled = features_pb2.Features()
        features.assign_features(features_enabled, is_new=True)
        self._assert_is_empty(features_enabled)

        self._assert_logging_error(
            'Feature configured in EXPERIMENTS_ROLLOUTS env var does not exist: actionPlan'
        )
Exemplo n.º 8
0
    def setUp(self) -> None:
        super().setUp()
        self.database = mongo.NoPiiMongoDatabase(mongomock.MongoClient().test)
        i18n.cache.clear()

        self.user = user_pb2.User(
            features_enabled=features_pb2.Features(
                advisor=features_pb2.ACTIVE, workbench=features_pb2.ACTIVE),
            profile=user_profile_pb2.UserProfile(
                name='Margaux', gender=user_profile_pb2.FEMININE, email='*****@*****.**',
                locale='fr@tu'))
        proto.CachedCollection.update_cache_version()
Exemplo n.º 9
0
    def test_assign_all_new(self) -> None:
        """Assignment of an experiment to all new users."""

        features_enabled = features_pb2.Features()
        features.assign_features(features_enabled, is_new=True)
        self.assertEqual(features_pb2.ACTIVE, features_enabled.action_plan)
Exemplo n.º 10
0
    def test_assign_no_env_var(self) -> None:
        """No assignment of features when no env var."""

        features_enabled = features_pb2.Features()
        features.assign_features(features_enabled, is_new=True)
        self._assert_is_empty(features_enabled)