Пример #1
0
def test_batch_update(mocker, db):  # pylint: disable=unused-argument
    """
    batch_update_user_data should create a group of tasks operating on chunks of users to refresh their caches
    """
    users = SocialUserFactory.create_batch(25)
    calc_mock = mocker.patch('dashboard.tasks.calculate_users_to_refresh_in_bulk', autospec=True, return_value=[
        user.id for user in users
    ])
    lock_mock_init = mocker.patch('dashboard.tasks.Lock', autospec=True)
    lock_mock = lock_mock_init.return_value
    token = b'token'
    lock_mock.token = token
    lock_mock.acquire.return_value = True
    refresh_mock = mocker.patch('dashboard.tasks.refresh_user_data', autospec=True)
    release_mock = mocker.patch('dashboard.tasks.release_lock', autospec=True)

    batch_update_user_data()

    assert lock_mock_init.call_args[0][0] == LOCK_ID
    assert is_near_now(lock_mock_init.call_args[0][1] - timedelta(hours=5))
    calc_mock.assert_called_once_with()
    lock_mock.acquire.assert_called_once_with()
    assert refresh_mock.call_count == len(users)
    for user in users:
        refresh_mock.assert_any_call(user.id)
    release_mock.assert_called_once_with(LOCK_ID, token)
Пример #2
0
def test_batch_update(mocker, db):  # pylint: disable=unused-argument
    """
    batch_update_user_data should create a group of tasks operating on chunks of users to refresh their caches
    """
    users = SocialUserFactory.create_batch(25)
    calc_mock = mocker.patch(
        'dashboard.tasks.calculate_users_to_refresh_in_bulk',
        autospec=True,
        return_value=[user.id for user in users])
    lock_mock_init = mocker.patch('dashboard.tasks.Lock', autospec=True)
    lock_mock = lock_mock_init.return_value
    token = b'token'
    lock_mock.token = token
    lock_mock.acquire.return_value = True
    refresh_mock = mocker.patch('dashboard.tasks.refresh_user_data',
                                autospec=True)
    release_mock = mocker.patch('dashboard.tasks.release_lock', autospec=True)

    batch_update_user_data()

    assert lock_mock_init.call_args[0][0] == LOCK_ID
    assert is_near_now(lock_mock_init.call_args[0][1] - timedelta(hours=5))
    calc_mock.assert_called_once_with()
    lock_mock.acquire.assert_called_once_with()
    assert refresh_mock.call_count == len(users)
    for user in users:
        refresh_mock.assert_any_call(user.id)
    release_mock.assert_called_once_with(LOCK_ID, token)
Пример #3
0
    def setUpTestData(cls):
        cls.user = SocialUserFactory.create()

        cls.run_fa = CourseRunFactory.create(
            freeze_grade_date=now_in_utc() - timedelta(days=1),
            course__program__financial_aid_availability=True,
        )
        cls.run_fa_with_cert = CourseRunFactory.create(
            freeze_grade_date=None,
            course__program=cls.run_fa.course.program,
        )

        cls.run_no_fa = CourseRunFactory.create(
            freeze_grade_date=now_in_utc() + timedelta(days=1),
            course__program__financial_aid_availability=False,
        )
        cls.run_no_fa_with_cert = CourseRunFactory.create(
            course__program=cls.run_no_fa.course.program, )

        all_course_runs = (
            cls.run_fa,
            cls.run_fa_with_cert,
            cls.run_no_fa,
            cls.run_no_fa_with_cert,
        )

        for run in all_course_runs:
            if run.course.program.financial_aid_availability:
                FinancialAidFactory.create(
                    user=cls.user,
                    tier_program=TierProgramFactory.create(
                        program=run.course.program,
                        income_threshold=0,
                        current=True),
                    status=FinancialAidStatus.RESET,
                )

        cls.enrollments = {
            course_run.edx_course_key:
            CachedEnrollmentFactory.create(user=cls.user,
                                           course_run=course_run)
            for course_run in all_course_runs
        }

        cls.current_grades = {
            course_run.edx_course_key:
            CachedCurrentGradeFactory.create(user=cls.user,
                                             course_run=course_run)
            for course_run in all_course_runs
        }

        cls.certificates = {
            course_run.edx_course_key:
            CachedCertificateFactory.create(user=cls.user,
                                            course_run=course_run)
            for course_run in (cls.run_fa_with_cert, cls.run_no_fa_with_cert)
        }

        cls.user_edx_data = CachedEdxUserData(cls.user)
Пример #4
0
 def setUpTestData(cls):
     cls.user = SocialUserFactory.create()
     cls.run_1 = CourseRunFactory.create(
         freeze_grade_date=now_in_utc()-timedelta(days=1),
         course__program__financial_aid_availability=True,
     )
     CourseRunGradingStatus.objects.create(course_run=cls.run_1, status='complete')
     cls.program = cls.run_1.course.program
Пример #5
0
    def setUpTestData(cls):
        cls.user = SocialUserFactory.create()

        cls.run_1 = CourseRunFactory.create(
            freeze_grade_date=now_in_utc()-timedelta(days=1),
            course__program__financial_aid_availability=True,
        )
        cls.program = cls.run_1.course.program
Пример #6
0
 def setUpTestData(cls):
     cls.user = SocialUserFactory.create()
     cls.run_1 = CourseRunFactory.create(
         freeze_grade_date=now_in_utc()-timedelta(days=1),
         course__program__financial_aid_availability=True,
     )
     CourseRunGradingStatus.objects.create(course_run=cls.run_1, status='complete')
     cls.program = cls.run_1.course.program
Пример #7
0
    def setUpTestData(cls):
        cls.user = SocialUserFactory.create()

        cls.run_1 = CourseRunFactory.create(
            freeze_grade_date=now_in_utc()-timedelta(days=1),
            course__program__financial_aid_availability=True,
        )
        cls.program = cls.run_1.course.program
Пример #8
0
    def setUpTestData(cls):
        super(DashboardTokensTest, cls).setUpTestData()
        # create a user
        cls.user = SocialUserFactory.create(social_auth__extra_data=social_extra_data)
        cls.social_auth = cls.user.social_auth.first()
        cls.enrollments = Enrollments([])

        # url for the dashboard
        cls.url = reverse('dashboard_api', args=[cls.social_auth.uid])
Пример #9
0
    def setUpTestData(cls):
        super(DashboardTokensTest, cls).setUpTestData()
        # create a user
        cls.user = SocialUserFactory.create(social_auth__extra_data=social_extra_data)
        cls.social_auth = cls.user.social_auth.first()
        cls.enrollments = Enrollments([])

        # url for the dashboard
        cls.url = reverse('dashboard_api', args=[cls.social_auth.uid])
Пример #10
0
    def setUpTestData(cls):
        cls.user = SocialUserFactory.create()

        cls.course_run = CourseRunFactory.create(
            course__program__financial_aid_availability=True)
        cls.exam_run = ExamRunFactory.create(
            course=cls.course_run.course,
            date_grades_available=now_in_utc() - timedelta(weeks=1))
        cls.not_passing_final_grade = FinalGradeFactory.create(
            user=cls.user, course_run=cls.course_run, grade=0.5, passed=False)
Пример #11
0
    def setUpTestData(cls):
        super().setUpTestData()
        # create a user
        cls.user = SocialUserFactory.create()

        # create the course run
        cls.course_id = "edx+fake+key"
        cls.course_run = CourseRunFactory.create(edx_course_key=cls.course_id)

        # url for the dashboard
        cls.url = reverse('user_course_enrollments')
Пример #12
0
    def setUpTestData(cls):
        super().setUpTestData()
        # create a user
        cls.user = SocialUserFactory.create()

        # create the course run
        cls.course_id = "edx+fake+key"
        cls.course_run = CourseRunFactory.create(edx_course_key=cls.course_id)

        # url for the dashboard
        cls.url = reverse('user_course_enrollments')
Пример #13
0
    def setUpTestData(cls):
        cls.user = SocialUserFactory.create()

        cls.run_fa = CourseRunFactory.create(
            freeze_grade_date=now_in_utc()-timedelta(days=1),
            course__program__financial_aid_availability=True,
        )
        cls.run_fa_with_cert = CourseRunFactory.create(
            freeze_grade_date=None,
            course__program=cls.run_fa.course.program,
        )

        cls.run_no_fa = CourseRunFactory.create(
            freeze_grade_date=now_in_utc()+timedelta(days=1),
            course__program__financial_aid_availability=False,
        )
        cls.run_no_fa_with_cert = CourseRunFactory.create(
            course__program=cls.run_no_fa.course.program,
        )

        all_course_runs = (cls.run_fa, cls.run_fa_with_cert, cls.run_no_fa, cls.run_no_fa_with_cert, )

        for run in all_course_runs:
            if run.course.program.financial_aid_availability:
                FinancialAidFactory.create(
                    user=cls.user,
                    tier_program=TierProgramFactory.create(
                        program=run.course.program, income_threshold=0, current=True
                    ),
                    status=FinancialAidStatus.RESET,
                )

        cls.enrollments = {
            course_run.edx_course_key: CachedEnrollmentFactory.create(
                user=cls.user, course_run=course_run) for course_run in all_course_runs
        }

        cls.current_grades = {
            course_run.edx_course_key: CachedCurrentGradeFactory.create(
                user=cls.user, course_run=course_run) for course_run in all_course_runs
        }

        cls.certificates = {
            course_run.edx_course_key: CachedCertificateFactory.create(
                user=cls.user, course_run=course_run) for course_run in (cls.run_fa_with_cert, cls.run_no_fa_with_cert)
        }

        cls.user_edx_data = CachedEdxUserData(cls.user)
Пример #14
0
    def setUpTestData(cls):
        cls.user = SocialUserFactory.create()

        cls.course_run = CourseRunFactory.create(
            course__program__financial_aid_availability=True
        )
        cls.exam_run = ExamRunFactory.create(
            course=cls.course_run.course,
            date_grades_available=now_in_utc() - timedelta(weeks=1)
        )
        cls.not_passing_final_grade = FinalGradeFactory.create(
            user=cls.user,
            course_run=cls.course_run,
            grade=0.5,
            passed=False
        )
Пример #15
0
    def setUpTestData(cls):
        super(DashboardTest, cls).setUpTestData()
        # create a user
        cls.user = SocialUserFactory.create()
        UserCacheRefreshTimeFactory(user=cls.user, unexpired=True)

        # create the programs
        cls.program_1 = ProgramFactory.create(live=True)
        cls.program_2 = ProgramFactory.create(live=True)
        cls.program_not_enrolled = ProgramFactory.create(live=True)
        cls.program_no_live = ProgramFactory.create(live=False)

        # enroll the user in some courses
        for program in [cls.program_1, cls.program_2, cls.program_no_live]:
            ProgramEnrollment.objects.create(
                user=cls.user,
                program=program
            )

        # url for the dashboard
        cls.url = reverse('dashboard_api', args=[cls.user.social_auth.first().uid])
Пример #16
0
    def setUpTestData(cls):
        super(DashboardTest, cls).setUpTestData()
        # create a user
        cls.user = SocialUserFactory.create()
        UserCacheRefreshTimeFactory(user=cls.user, unexpired=True)

        # create the programs
        cls.program_1 = ProgramFactory.create(live=True)
        cls.program_2 = ProgramFactory.create(live=True)
        cls.program_not_enrolled = ProgramFactory.create(live=True)
        cls.program_no_live = ProgramFactory.create(live=False)

        # enroll the user in some courses
        for program in [cls.program_1, cls.program_2, cls.program_no_live]:
            ProgramEnrollment.objects.create(
                user=cls.user,
                program=program
            )

        # url for the dashboard
        cls.url = reverse('dashboard_api', args=[cls.user.social_auth.first().uid])
Пример #17
0
def test_batch_update_disabled(mocker, settings):
    """batch_update_user_data should not run if it's disabled"""
    settings.EDX_BATCH_UPDATES_ENABLED = False
    users = SocialUserFactory.create_batch(25)
    calc_mock = mocker.patch(
        'dashboard.tasks.calculate_users_to_refresh_in_bulk',
        autospec=True,
        return_value=[user.id for user in users])
    lock_mock_init = mocker.patch('dashboard.tasks.Lock', autospec=True)
    lock_mock = lock_mock_init.return_value
    token = b'token'
    lock_mock.token = token
    lock_mock.acquire.return_value = True
    mocker.patch('dashboard.tasks.refresh_user_data', autospec=True)
    mocker.patch('dashboard.tasks.release_lock', autospec=True)
    mock_log = mocker.patch('dashboard.tasks.log', autospec=True)

    batch_update_user_data.delay()

    calc_mock.assert_not_called()
    mock_log.debug.assert_called_once_with(
        "Edx batch updates disabled via EDX_BATCH_UPDATES_ENABLED")
Пример #18
0
 def setUpTestData(cls):
     super(BackendViewTest, cls).setUpTestData()
     # create a user
     cls.user = SocialUserFactory.create()
     UserCacheRefreshTimeFactory(user=cls.user, unexpired=True)
     cls.url = reverse('social:complete', args=['edxorg'])
Пример #19
0
 def setUpTestData(cls):
     super(BackendViewTest, cls).setUpTestData()
     # create a user
     cls.user = SocialUserFactory.create()
     UserCacheRefreshTimeFactory(user=cls.user, unexpired=True)
     cls.url = reverse('social:complete', args=['edxorg'])
Пример #20
0
 def setUpTestData(cls):
     cls.user = SocialUserFactory.create(social_auth__extra_data=social_extra_data)
     cls.invalid_user = UserFactory.create()
     cls.url = reverse('unenroll_programs')
Пример #21
0
 def setUpTestData(cls):
     cls.user = SocialUserFactory.create(social_auth__extra_data=social_extra_data)
     cls.invalid_user = UserFactory.create()
     cls.url = reverse('unenroll_programs')