Exemplo n.º 1
0
    def test_external_course_updates(self, bucket):
        """Confirm that we exclude enrollments in the external course updates experiment"""
        user = UserFactory()
        overview1 = CourseOverviewFactory(
            has_highlights=False
        )  # set has_highlights just to avoid a modulestore lookup
        overview2 = CourseOverviewFactory(has_highlights=False)

        # We need to enroll with a request, because our specific experiment code expects it
        self.addCleanup(crum.set_current_request, None)
        request = RequestFactory().get(self.site)
        request.user = user
        crum.set_current_request(request)
        enrollment1 = CourseEnrollment.enroll(user, overview1.id)
        with override_experiment_waffle_flag(_EXTERNAL_COURSE_UPDATES_FLAG,
                                             bucket=bucket):
            enrollment2 = CourseEnrollment.enroll(user, overview2.id)

        # OK, at this point, we'd expect course1 to be returned, but course2's enrollment to be excluded by the
        # experiment. Note that the experiment waffle is currently inactive, but they should still be excluded because
        # they were bucketed at enrollment time.
        bin_num = BinnedSchedulesBaseResolver.bin_num_for_user_id(user.id)
        resolver = BinnedSchedulesBaseResolver(None, self.site,
                                               datetime.datetime.now(pytz.UTC),
                                               0, bin_num)
        resolver.schedule_date_field = 'created'
        schedules = resolver.get_schedules_with_target_date_by_bin_and_orgs()

        if bucket == 1:
            assert len(schedules) == 1
            assert schedules[0].enrollment == enrollment1
        else:
            assert len(schedules) == 2
            assert {s.enrollment
                    for s in schedules} == {enrollment1, enrollment2}
Exemplo n.º 2
0
 def test_streak_data_in_response(self):
     """ Test that metadata endpoint returns data for the streak celebration """
     CourseEnrollment.enroll(self.user, self.course.id, 'audit')
     with override_experiment_waffle_flag(STREAK_DISCOUNT_EXPERIMENT_FLAG, active=True):
         with mock.patch('common.djangoapps.student.models.UserCelebration.perform_streak_updates', return_value=3):
             response = self.client.get(self.url, content_type='application/json')
             celebrations = response.json()['celebrations']
             assert celebrations['streak_length_to_celebrate'] == 3
             assert celebrations['streak_discount_experiment_enabled'] is True
    def test_override_enabled_for(self, active):
        with override_experiment_waffle_flag(RELATIVE_DATES_FLAG,
                                             active=active):
            # Instructor paced course will just have the default value
            ip_course = self.setup_course()
            course_module = self.get_course_module(ip_course)
            assert course_module.showanswer == SHOWANSWER.FINISHED

            # This should be updated to not explicitly add in the showanswer so it can test the
            # default case of never touching showanswer. Reference ticket AA-307 (if that's closed,
            # this can be updated!)
            sp_course = self.setup_course(self_paced=True,
                                          showanswer=SHOWANSWER.FINISHED)
            course_module = self.get_course_module(sp_course)
            if active:
                assert course_module.showanswer == SHOWANSWER.AFTER_ALL_ATTEMPTS_OR_CORRECT
            else:
                assert course_module.showanswer == SHOWANSWER.FINISHED
Exemplo n.º 4
0
 def test_override_method(self, active, bucket_override, expected_bucket):
     with override_experiment_waffle_flag(self.flag,
                                          active=active,
                                          bucket=bucket_override):
         self.assertEqual(self.flag.get_bucket(), expected_bucket)
         self.assertEqual(self.flag.is_experiment_on(), active)
 def set_up_updates(self, active=True, bucket=1):
     """Sets up the external updates experiment data, with the given bucket"""
     with override_experiment_waffle_flag(_EXTERNAL_COURSE_UPDATES_FLAG, active=active, bucket=bucket):
         return set_up_external_updates_for_enrollment(self.user, self.course_key)