def _pre_setup(self):
     super(TestCase, self)._pre_setup()
     experiments = getattr(self, 'experiments', [])
     ExperimentLoader.load_all_experiments(apps=experiments)
     self.original_LEAN_ANALYTICS = settings.LEAN_ANALYTICS
     settings.LEAN_ANALYTICS = []
     reset_caches()
Esempio n. 2
0
    def __test_group(cls, experiment_name, experiment_user, queried_group):
        """does the real work"""
        from django_lean.experiments.loader import ExperimentLoader
        ExperimentLoader.load_all_experiments()

        experiment = None
        try:
            experiment = Experiment.objects.get(name=experiment_name)
        except Experiment.DoesNotExist:
            l.warning("Creating New Experiment named %s" % experiment_name)
            experiment = Experiment(name=experiment_name,
                                    state=Experiment.ENABLED_STATE,
                                    start_date=date.today(),
                                    end_date=None)
            experiment.save()

        if experiment.state == Experiment.DISABLED_STATE:
            return queried_group == Participant.CONTROL_GROUP
        elif experiment.state == Experiment.PROMOTED_STATE:
            return queried_group == Participant.TEST_GROUP

        if experiment.state != Experiment.ENABLED_STATE:
            raise Exception("Invalid experiment state !")

        user = cls.__create_user(experiment_user)
        assigned_group = user.get_enrollment(experiment)

        if assigned_group == None:
            assigned_group = random.choice(
                (Participant.CONTROL_GROUP, Participant.TEST_GROUP))
            user.set_enrollment(experiment, assigned_group)

        return queried_group == assigned_group
Esempio n. 3
0
 def _pre_setup(self):
     super(TestCase, self)._pre_setup()
     experiments = getattr(self, 'experiments', [])
     ExperimentLoader.load_all_experiments(apps=experiments)
     self.original_LEAN_ANALYTICS = getattr(settings, 'LEAN_ANALYTICS', [])
     settings.LEAN_ANALYTICS = []
     reset_caches()
Esempio n. 4
0
    def __test_group(cls, experiment_name, experiment_user, queried_group):
        """does the real work"""
        from django_lean.experiments.loader import ExperimentLoader
        ExperimentLoader.load_all_experiments()

        experiment = None
        try:
            experiment = Experiment.objects.get(name=experiment_name)
        except Experiment.DoesNotExist:
            if settings.DEBUG:
                raise Exception("Can't find the Experiment named %s" %
                                experiment_name)
            else:
                l.warning("Can't find the Experiment named %s" %
                          experiment_name)
                return queried_group == Participant.CONTROL_GROUP
        if experiment.state == Experiment.DISABLED_STATE:
            return queried_group == Participant.CONTROL_GROUP
        elif experiment.state == Experiment.PROMOTED_STATE:
            return queried_group == Participant.TEST_GROUP

        if experiment.state != Experiment.ENABLED_STATE:
            raise Exception("Invalid experiment state !")

        user = cls.__create_user(experiment_user)

        assigned_group = user.get_enrollment(experiment)

        if assigned_group == None:
            assigned_group = random.choice((Participant.CONTROL_GROUP,
                                            Participant.TEST_GROUP))
            user.set_enrollment(experiment, assigned_group)

        return queried_group == assigned_group