Пример #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}
Пример #2
0
    def setUp(self):
        super().setUp()

        self.resolver = BinnedSchedulesBaseResolver(
            async_send_task=Mock(name='async_send_task'),
            site=self.site,
            target_datetime=datetime.datetime.now(),
            day_offset=3,
            bin_num=2,
        )
Пример #3
0
class TestBinnedSchedulesBaseResolver(SchedulesResolverTestMixin, TestCase):
    """
    Tests the BinnedSchedulesBaseResolver.
    """
    def setUp(self):
        super(TestBinnedSchedulesBaseResolver, self).setUp()

        self.resolver = BinnedSchedulesBaseResolver(
            async_send_task=Mock(name='async_send_task'),
            site=self.site,
            target_datetime=datetime.datetime.now(),
            day_offset=3,
            bin_num=2,
        )

    @ddt.data(
        'course1'
    )
    def test_get_course_org_filter_equal(self, course_org_filter):
        self.site_config.values['course_org_filter'] = course_org_filter
        self.site_config.save()
        mock_query = Mock()
        result = self.resolver.filter_by_org(mock_query)
        self.assertEqual(result, mock_query.filter.return_value)
        mock_query.filter.assert_called_once_with(enrollment__course__org=course_org_filter)

    @ddt.unpack
    @ddt.data(
        (['course1', 'course2'], ['course1', 'course2'])
    )
    def test_get_course_org_filter_include__in(self, course_org_filter, expected_org_list):
        self.site_config.values['course_org_filter'] = course_org_filter
        self.site_config.save()
        mock_query = Mock()
        result = self.resolver.filter_by_org(mock_query)
        self.assertEqual(result, mock_query.filter.return_value)
        mock_query.filter.assert_called_once_with(enrollment__course__org__in=expected_org_list)

    @ddt.unpack
    @ddt.data(
        (None, set([])),
        ('course1', set([u'course1'])),
        (['course1', 'course2'], set([u'course1', u'course2']))
    )
    def test_get_course_org_filter_exclude__in(self, course_org_filter, expected_org_list):
        SiteConfigurationFactory.create(
            values={'course_org_filter': course_org_filter},
        )
        mock_query = Mock()
        result = self.resolver.filter_by_org(mock_query)
        mock_query.exclude.assert_called_once_with(enrollment__course__org__in=expected_org_list)
        self.assertEqual(result, mock_query.exclude.return_value)
Пример #4
0
class TestBinnedSchedulesBaseResolver(CacheIsolationTestCase):
    def setUp(self):
        super(TestBinnedSchedulesBaseResolver, self).setUp()

        self.site = SiteFactory.create()
        self.site_config = SiteConfigurationFactory(site=self.site)
        self.schedule_config = ScheduleConfigFactory.create(site=self.site)
        self.resolver = BinnedSchedulesBaseResolver(
            async_send_task=Mock(name='async_send_task'),
            site=self.site,
            target_datetime=datetime.datetime.now(),
            day_offset=3,
            bin_num=2,
        )

    @ddt.data(
        'course1'
    )
    def test_get_course_org_filter_equal(self, course_org_filter):
        self.site_config.values['course_org_filter'] = course_org_filter
        self.site_config.save()
        mock_query = Mock()
        result = self.resolver.filter_by_org(mock_query)
        self.assertEqual(result, mock_query.filter.return_value)
        mock_query.filter.assert_called_once_with(enrollment__course__org=course_org_filter)

    @ddt.unpack
    @ddt.data(
        (['course1', 'course2'], ['course1', 'course2'])
    )
    def test_get_course_org_filter_include__in(self, course_org_filter, expected_org_list):
        self.site_config.values['course_org_filter'] = course_org_filter
        self.site_config.save()
        mock_query = Mock()
        result = self.resolver.filter_by_org(mock_query)
        self.assertEqual(result, mock_query.filter.return_value)
        mock_query.filter.assert_called_once_with(enrollment__course__org__in=expected_org_list)

    @ddt.unpack
    @ddt.data(
        (None, set([])),
        ('course1', set([u'course1'])),
        (['course1', 'course2'], set([u'course1', u'course2']))
    )
    def test_get_course_org_filter_exclude__in(self, course_org_filter, expected_org_list):
        SiteConfigurationFactory.create(
            values={'course_org_filter': course_org_filter},
        )
        mock_query = Mock()
        result = self.resolver.filter_by_org(mock_query)
        mock_query.exclude.assert_called_once_with(enrollment__course__org__in=expected_org_list)
        self.assertEqual(result, mock_query.exclude.return_value)
Пример #5
0
    def setUp(self):
        super(TestBinnedSchedulesBaseResolver, self).setUp()

        self.site = SiteFactory.create()
        self.site_config = SiteConfigurationFactory(site=self.site)
        self.schedule_config = ScheduleConfigFactory.create(site=self.site)
        self.resolver = BinnedSchedulesBaseResolver(
            async_send_task=Mock(name='async_send_task'),
            site=self.site,
            target_datetime=datetime.datetime.now(),
            day_offset=3,
            bin_num=2,
        )
Пример #6
0
    def setUp(self):
        super(TestBinnedSchedulesBaseResolver, self).setUp()

        self.site = SiteFactory.create()
        self.site_config = SiteConfigurationFactory(site=self.site)
        self.schedule_config = ScheduleConfigFactory.create(site=self.site)
        self.resolver = BinnedSchedulesBaseResolver(
            async_send_task=Mock(name='async_send_task'),
            site=self.site,
            target_datetime=datetime.datetime.now(),
            day_offset=3,
            bin_num=2,
        )
Пример #7
0
class TestBinnedSchedulesBaseResolver(SchedulesResolverTestMixin, TestCase):
    """
    Tests the BinnedSchedulesBaseResolver.
    """
    def setUp(self):
        super().setUp()

        self.resolver = BinnedSchedulesBaseResolver(
            async_send_task=Mock(name='async_send_task'),
            site=self.site,
            target_datetime=datetime.datetime.now(),
            day_offset=3,
            bin_num=2,
        )

    @ddt.data('course1')
    def test_get_course_org_filter_equal(self, course_org_filter):
        self.site_config.site_values['course_org_filter'] = course_org_filter
        self.site_config.save()
        mock_query = Mock()
        result = self.resolver.filter_by_org(mock_query)
        assert result == mock_query.filter.return_value
        mock_query.filter.assert_called_once_with(
            enrollment__course__org=course_org_filter)

    @ddt.unpack
    @ddt.data((['course1', 'course2'], ['course1', 'course2']))
    def test_get_course_org_filter_include__in(self, course_org_filter,
                                               expected_org_list):
        self.site_config.site_values['course_org_filter'] = course_org_filter
        self.site_config.save()
        mock_query = Mock()
        result = self.resolver.filter_by_org(mock_query)
        assert result == mock_query.filter.return_value
        mock_query.filter.assert_called_once_with(
            enrollment__course__org__in=expected_org_list)

    @ddt.unpack
    @ddt.data((None, set([])), ('course1', set(['course1'])),
              (['course1', 'course2'], set(['course1', 'course2'])))
    def test_get_course_org_filter_exclude__in(self, course_org_filter,
                                               expected_org_list):
        SiteConfigurationFactory.create(
            site_values={'course_org_filter': course_org_filter})
        mock_query = Mock()
        result = self.resolver.filter_by_org(mock_query)
        mock_query.exclude.assert_called_once_with(
            enrollment__course__org__in=expected_org_list)
        assert result == mock_query.exclude.return_value

    @ddt.data(0, 1)
    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()
        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}