def test_visit_incorporate(self):
        alternative = participant(self.request).enroll(self.experiment.name,
                                                       ['alternative'])

        ExperimentsRetentionMiddleware().process_response(
            self.request, HttpResponse())

        self.assertEqual(
            dict(
                self.experiment_counter.participant_goal_frequencies(
                    self.experiment, alternative,
                    participant(self.request)._participant_identifier()))[
                        conf.VISIT_NOT_PRESENT_COUNT_GOAL], 1)

        self.assertFalse(Enrollment.objects.all().exists())
        self._login()

        self.assertTrue(Enrollment.objects.all().exists())
        self.assertIsNotNone(Enrollment.objects.all()[0].last_seen)
        self.assertEqual(
            dict(
                self.experiment_counter.participant_goal_frequencies(
                    self.experiment, alternative,
                    participant(self.request)._participant_identifier()))[
                        conf.VISIT_NOT_PRESENT_COUNT_GOAL], 1)
        self.assertEqual(
            self.experiment_counter.goal_count(
                self.experiment, alternative,
                conf.VISIT_NOT_PRESENT_COUNT_GOAL), 1)
        self.assertEqual(
            self.experiment_counter.participant_count(self.experiment,
                                                      alternative), 1)
예제 #2
0
 def test_transfer_enrollments(self):
     User = get_user_model()
     user = User.objects.create(username='******')
     request = request_factory.get('/')
     request.session = DatabaseSession()
     participant(request).enroll('test_experiment1', ['alternative'])
     request.user = user
     transfer_enrollments_to_user(None, request, user)
     # the call to the middleware will set last_seen on the experiment
     # if the participant cache hasn't been wiped appropriately then the
     # session experiment user will be impacted instead of the authenticated
     # experiment user
     ExperimentsRetentionMiddleware().process_response(request, HttpResponse())
     self.assertIsNotNone(Enrollment.objects.all()[0].last_seen)