def setUp(self):
     self.experiment = Experiment(name="test_experiment")
     self.experiment.save()
     self.experiment.state = Experiment.ENABLED_STATE
     self.experiment.save()
     self.experiment.start_date = (self.experiment.start_date -
                                   timedelta(days=5))
     self.experiment.save()
     
     anonymous_visitor = AnonymousVisitor()
     anonymous_visitor.save()
     anonymous_participant = Participant(anonymous_visitor=anonymous_visitor,
                                         experiment=self.experiment,
                                         group=Participant.TEST_GROUP)
     anonymous_participant.save()
     anonymous_participant.enrollment_date = self.experiment.start_date
     anonymous_participant.save()
     
     self.other_experiment = Experiment(name="test_experiment2")
     self.other_experiment.save()
     self.other_experiment.state = Experiment.DISABLED_STATE
     self.other_experiment.save()
     self.other_experiment.start_date = (date.today() -
                                   timedelta(days=7))
     self.other_experiment.end_date = (date.today() -
                                   timedelta(days=3))
     self.other_experiment.save()
Ejemplo n.º 2
0
    def setUp(self):
        self.experiment = Experiment(name="test_experiment")
        self.experiment.save()
        self.experiment.state = Experiment.ENABLED_STATE
        self.experiment.save()
        self.experiment.start_date = (self.experiment.start_date -
                                      timedelta(days=5))
        self.experiment.save()

        anonymous_visitor = AnonymousVisitor()
        anonymous_visitor.save()
        anonymous_participant = Participant(
            anonymous_visitor=anonymous_visitor,
            experiment=self.experiment,
            group=Participant.TEST_GROUP)
        anonymous_participant.save()
        anonymous_participant.enrollment_date = self.experiment.start_date
        anonymous_participant.save()

        self.other_experiment = Experiment(name="test_experiment2")
        self.other_experiment.save()
        self.other_experiment.state = Experiment.DISABLED_STATE
        self.other_experiment.save()
        self.other_experiment.start_date = (date.today() - timedelta(days=7))
        self.other_experiment.end_date = (date.today() - timedelta(days=3))
        self.other_experiment.save()
Ejemplo n.º 3
0
def create_user_in_group(experiment, i, group, enrollment_date):
    user = User(username="******" % (i, group), email="*****@*****.**" % (i, group))
    user.save()
    experiment_participant = Participant(user=user, experiment=experiment, group=group)
    experiment_participant.save()
    experiment_participant.enrollment_date = enrollment_date
    experiment_participant.save()
    return user
Ejemplo n.º 4
0
def create_user_in_group(experiment, i, group, enrollment_date):
    user = User(username="******" % (i, group),
                email="*****@*****.**" % (i, group))
    user.save()
    experiment_participant = Participant(user=user,
                                         experiment=experiment,
                                         group=group)
    experiment_participant.save()
    experiment_participant.enrollment_date = enrollment_date
    experiment_participant.save()
    return user
 def testParticipants(self):
     user1 = User(username="******", email="*****@*****.**")
     user1.save()
     user2 = User(username="******", email="*****@*****.**")
     user2.save()
     user3 = User(username="******", email="*****@*****.**")
     user3.save()
     
     anonymous_visitor1 = AnonymousVisitor()
     anonymous_visitor1.save()
     anonymous_visitor2 = AnonymousVisitor()
     anonymous_visitor2.save()
     anonymous_visitor3 = AnonymousVisitor()
     anonymous_visitor3.save()
     
     experiment1 = Experiment(name="Experiment 1")
     experiment1.save()
     experiment2 = Experiment(name="Experiment 2")
     experiment2.save()
     
     participant11 = Participant(user=user1,
                                 experiment= experiment1,
                                 group=Participant.CONTROL_GROUP)
     participant11.save()
     participant12 = Participant(user=user1,
                                 experiment= experiment2,
                                 group=Participant.TEST_GROUP)
     participant12.save()
     participant21 = Participant(user=user2,
                                 experiment= experiment1,
                                 group=Participant.CONTROL_GROUP)
     participant21.save()
     participant22 = Participant(user=user2,
                                 experiment= experiment2,
                                 group=Participant.CONTROL_GROUP)
     participant22.save()
     
     self.assertRaises(Exception,
                       lambda: Participant(user=user2,
                                           experiment= experiment2,
                                           group=Participant.TEST_GROUP).save())
     
     # create anonymous participants
     participant31 = Participant(anonymous_visitor=anonymous_visitor1,
                                 experiment=experiment1,
                                 group=Participant.CONTROL_GROUP)
     participant31.save()
     participant32 = Participant(anonymous_visitor=anonymous_visitor1,
                                 experiment=experiment2,
                                 group=Participant.TEST_GROUP)
     participant32.save()
     participant42 = Participant(anonymous_visitor=anonymous_visitor2,
                                 experiment=experiment2,
                                 group=Participant.CONTROL_GROUP)
     participant42.save()
     
     self.assertRaises(Exception,
                       lambda: Participant(anonymous_visitor=anonymous_visitor1,
                                           experiment=experiment1,
                                           group=Participant.TEST_GROUP).save())
     
     self.assertRaises(Exception,
                       lambda: Participant(experiment=experiment1,
                                           group=Participant.TEST_GROUP).save())
     
     self.assertRaises(Exception,
                       lambda: Participant(user=user3,
                                           anonymous_visitor=anonymous_visitor3,
                                           experiment=experiment1,
                                           group=Participant.TEST_GROUP))
     self.assertRaises(Exception,
                       lambda: Participant(user=user3,
                                           experiment=experiment1).save())
     
     self.assertNotEquals(participant11.enrollment_date, None)
     
     participant11.enrollment_date = None
     self.assertRaises(Exception,
                       lambda: participant11.save())
     
     participant12.group = None
     self.assertRaises(Exception,
                       lambda: participant12.save())
Ejemplo n.º 6
0
    def testParticipants(self):
        user1 = User(username="******", email="*****@*****.**")
        user1.save()
        user2 = User(username="******", email="*****@*****.**")
        user2.save()
        user3 = User(username="******", email="*****@*****.**")
        user3.save()

        anonymous_visitor1 = AnonymousVisitor()
        anonymous_visitor1.save()
        anonymous_visitor2 = AnonymousVisitor()
        anonymous_visitor2.save()
        anonymous_visitor3 = AnonymousVisitor()
        anonymous_visitor3.save()

        experiment1 = Experiment(name="Experiment 1")
        experiment1.save()
        experiment2 = Experiment(name="Experiment 2")
        experiment2.save()

        participant11 = Participant(user=user1,
                                    experiment=experiment1,
                                    group=Participant.CONTROL_GROUP)
        participant11.save()
        participant12 = Participant(user=user1,
                                    experiment=experiment2,
                                    group=Participant.TEST_GROUP)
        participant12.save()
        participant21 = Participant(user=user2,
                                    experiment=experiment1,
                                    group=Participant.CONTROL_GROUP)
        participant21.save()
        participant22 = Participant(user=user2,
                                    experiment=experiment2,
                                    group=Participant.CONTROL_GROUP)
        participant22.save()

        self.assertRaises(
            Exception,
            lambda: Participant(user=user2,
                                experiment=experiment2,
                                group=Participant.TEST_GROUP).save())

        # create anonymous participants
        participant31 = Participant(anonymous_visitor=anonymous_visitor1,
                                    experiment=experiment1,
                                    group=Participant.CONTROL_GROUP)
        participant31.save()
        participant32 = Participant(anonymous_visitor=anonymous_visitor1,
                                    experiment=experiment2,
                                    group=Participant.TEST_GROUP)
        participant32.save()
        participant42 = Participant(anonymous_visitor=anonymous_visitor2,
                                    experiment=experiment2,
                                    group=Participant.CONTROL_GROUP)
        participant42.save()

        self.assertRaises(
            Exception,
            lambda: Participant(anonymous_visitor=anonymous_visitor1,
                                experiment=experiment1,
                                group=Participant.TEST_GROUP).save())

        self.assertRaises(
            Exception,
            lambda: Participant(experiment=experiment1,
                                group=Participant.TEST_GROUP).save())

        self.assertRaises(
            Exception,
            lambda: Participant(user=user3,
                                anonymous_visitor=anonymous_visitor3,
                                experiment=experiment1,
                                group=Participant.TEST_GROUP))
        self.assertRaises(
            Exception,
            lambda: Participant(user=user3, experiment=experiment1).save())

        self.assertNotEquals(participant11.enrollment_date, None)

        participant11.enrollment_date = None
        self.assertRaises(Exception, lambda: participant11.save())

        participant12.group = None
        self.assertRaises(Exception, lambda: participant12.save())