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()
Beispiel #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
Beispiel #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()
Beispiel #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
Beispiel #5
0
    def testExperimentLoader(self):
        filename1 = get_experiments("test_experiments.json")
        filename2 = get_experiments("test_experiments2.json")

        count = Experiment.objects.all().count()

        ExperimentLoader.load_experiments(filename1)

        new_count = Experiment.objects.all().count()
        self.assertEquals(count + 3, new_count)

        experiment1 = Experiment.objects.get(name="Test Experiment #1")
        experiment2 = Experiment.objects.get(name="Test Experiment #2")
        experiment3 = Experiment.objects.get(name="Test Experiment #3")
        self.assertEquals(
            0,
            Experiment.objects.filter(name="Test Experiment #4").count())

        self.assertEquals(experiment1.state, Experiment.DISABLED_STATE)
        self.assertEquals(experiment1.start_date, None)
        self.assertEquals(experiment1.end_date, None)

        experiment1.state = Experiment.ENABLED_STATE
        experiment1.save()

        self.assertNotEquals(experiment1.start_date, None)

        ExperimentLoader.load_experiments(filename1)

        # assert no new experiments loaded
        new_count = Experiment.objects.all().count()
        self.assertEquals(count + 3, new_count)

        # make sure that experiment1 is still enabled
        experiment1 = Experiment.objects.get(name="Test Experiment #1")
        self.assertEquals(experiment1.state, Experiment.ENABLED_STATE)
        self.assertNotEquals(experiment1.start_date, None)
        self.assertEquals(experiment1.end_date, None)

        ExperimentLoader.load_experiments(filename2)
        # assert 1 new experiment loaded
        new_count = Experiment.objects.all().count()
        self.assertEquals(count + 4, new_count)
        experiment4 = Experiment.objects.get(name="Test Experiment #4")
 def testExperimentLoader(self):
     filename1 = get_experiments("test_experiments.json")
     filename2 = get_experiments("test_experiments2.json")
     
     count = Experiment.objects.all().count()
     
     ExperimentLoader.load_experiments(filename1)
     
     new_count = Experiment.objects.all().count()
     self.assertEquals(count+3, new_count)
     
     experiment1 = Experiment.objects.get(name="Test Experiment #1")
     experiment2 = Experiment.objects.get(name="Test Experiment #2")
     experiment3 = Experiment.objects.get(name="Test Experiment #3")
     self.assertEquals(0, Experiment.objects.filter(
                       name="Test Experiment #4").count())
     
     self.assertEquals(experiment1.state, Experiment.DISABLED_STATE)
     self.assertEquals(experiment1.start_date, None)
     self.assertEquals(experiment1.end_date, None)
     
     experiment1.state = Experiment.ENABLED_STATE
     experiment1.save()
     
     self.assertNotEquals(experiment1.start_date, None)
     
     ExperimentLoader.load_experiments(filename1)
     
     # assert no new experiments loaded
     new_count = Experiment.objects.all().count()
     self.assertEquals(count+3, new_count)
     
     # make sure that experiment1 is still enabled
     experiment1 = Experiment.objects.get(name="Test Experiment #1")
     self.assertEquals(experiment1.state, Experiment.ENABLED_STATE)
     self.assertNotEquals(experiment1.start_date, None)
     self.assertEquals(experiment1.end_date, None)
     
     ExperimentLoader.load_experiments(filename2)
     # assert 1 new experiment loaded
     new_count = Experiment.objects.all().count()
     self.assertEquals(count+4, new_count)
     experiment4 = Experiment.objects.get(name="Test Experiment #4")
 def testMissingExperimentDefinition(self):
     filename = get_experiments("non_existant_file.json")
     self.assertRaises(Exception, lambda: ExperimentLoader.load_experiments(filename))
 def testInvalidExperimentDefinition(self):
     filename = get_experiments("test_invalid_experiments.json")
     ExperimentLoader.load_experiments(filename)
Beispiel #9
0
 def testMissingExperimentDefinition(self):
     filename = get_experiments("non_existant_file.json")
     self.assertRaises(Exception,
                       lambda: ExperimentLoader.load_experiments(filename))
Beispiel #10
0
 def testInvalidExperimentDefinition(self):
     filename = get_experiments("test_invalid_experiments.json")
     ExperimentLoader.load_experiments(filename)