Ejemplo n.º 1
0
def test_get_context_data_performance_tracking_view(mocked_get_data_for_all_course_groups, adg_admin, request_factory):
    """
    Tests get_context_data method of the performance tracking view
    """
    mocked_get_data_for_all_course_groups.return_value = 'chart_data'

    course = CourseOverviewFactory()
    business_line = BusinessLineFactory()
    course_group = MultilingualCourseGroupFactory(business_line_prerequisite=business_line)
    MultilingualCourseFactory(course=course, multilingual_course_group=course_group)

    course2 = CourseOverviewFactory()
    course_group2 = MultilingualCourseGroupFactory(is_common_business_line_prerequisite=True)
    MultilingualCourseFactory(course=course2, multilingual_course_group=course_group2)

    request = request_factory.get(reverse('performance-tracking'))
    request.user = adg_admin

    kwargs = {'business-line': ALL_BUSINESS_UNITS}

    response = PerformanceTrackingView.as_view()(request, **kwargs)

    assert response.context_data.get('has_adg_admin_permissions')
    assert response.context_data.get('business_lines') == [ALL_BUSINESS_UNITS, business_line.title]
    assert response.context_data.get('selected_business_line') == ALL_BUSINESS_UNITS
    assert response.context_data.get('accepted_students') == 0
    assert response.context_data.get('program_completions') == 0
    assert response.context_data.get('chart') == 'chart_data'
Ejemplo n.º 2
0
def test_bu_admin_can_get_course_grades(course, mocker, user_with_profile, course_grades_get_request):
    """
    Test bu admin can access `CourseGradeListView`.
    """
    mocker.patch(
        'openedx.adg.admin_dashboard.performance.views.CourseGradeListView._get_course',
        return_value=course
    )
    mocker.patch(
        'openedx.adg.admin_dashboard.performance.views.CourseKey.from_string',
        return_value=course.id
    )

    business_line = BusinessLineFactory()
    course_group = MultilingualCourseGroupFactory(business_line_prerequisite=business_line)
    MultilingualCourseFactory(course=course, multilingual_course_group=course_group)

    user_with_profile.is_staff = True
    user_with_profile.save()
    user_with_profile.groups.add(Group.objects.get(name=business_line.title))
    course_grades_get_request.user = user_with_profile

    kwargs = {'course_key_string': course.id}
    response = CourseGradeListView.as_view()(course_grades_get_request, **kwargs)

    assert response.status_code == 200
    assert 'object_list' in response.context_data
    assert response.context_data.get('course_name') == course.display_name
Ejemplo n.º 3
0
def test_other_bu_admin_cannot_get_course_grades(course, mocker, user_with_profile, course_grades_get_request):
    """
    Test bu admin of another bu cannot can access `CourseGradeListView`.
    """
    mocker.patch(
        'openedx.adg.admin_dashboard.performance.views.CourseGradeListView._get_course',
        return_value=course
    )
    mocker.patch(
        'openedx.adg.admin_dashboard.performance.views.CourseKey.from_string',
        return_value=course.id
    )

    business_line = BusinessLineFactory()
    course_group = MultilingualCourseGroupFactory(
        is_program_prerequisite=False, business_line_prerequisite=business_line
    )
    MultilingualCourseFactory(course=course, multilingual_course_group=course_group)
    business_line2 = BusinessLineFactory()

    user_with_profile.is_staff = True
    user_with_profile.save()
    user_with_profile.groups.add(Group.objects.get(name=business_line2.title))
    course_grades_get_request.user = user_with_profile

    kwargs = {'course_key_string': course.id}

    response = CourseGradeListView.as_view()(course_grades_get_request, **kwargs)
    assert response.status_code == 403
Ejemplo n.º 4
0
def create_prerequisite_course_group(request):
    """
    This fixture takes in a tuple through the request fixture to set the batch size of course groups
    to be created and to make these course groups either program, common business line, or
    business line prerequisite e.g. (10, 'common_business_line_pre_req')

    request: a fixture providing information of the requesting test function
    """
    is_program_prereq = request.param[1] == PROGRAM_PRE_REQ
    is_common_bu_prereq = request.param[1] == COMMON_BUSINESS_LINE_PRE_REQ
    course_groups = MultilingualCourseGroupFactory.create_batch(
        request.param[0],
        is_program_prerequisite=is_program_prereq,
        is_common_business_line_prerequisite=is_common_bu_prereq)

    now = timezone.now()
    for course_group in course_groups:
        # Open prereq courses
        MultilingualCourseFactory.create_batch(
            2,
            course__start_date=now,
            course__end_date=now + timedelta(days=1),
            multilingual_course_group=course_group)
        # Ended prereq course
        MultilingualCourseFactory(course__start_date=now - timedelta(days=2),
                                  course__end_date=now,
                                  multilingual_course_group=course_group)

    return course_groups
Ejemplo n.º 5
0
def test_check_and_update_prereq_courses_status_to_completed(
        pre_req_status, bu_pre_req_status, expected_pre_req_courses_status,
        expected_bu_pre_req_courses_status, application_hub, user_application,
        courses, mocker):
    """
    Verify that the `program_prereq_courses_status` and `bu_prereq_courses_status` fields of application hub
    are marked as completed correctly.
    """
    mocker.patch('lms.djangoapps.grades.models.is_testing_environment',
                 return_value=False)
    mocker.patch(
        'openedx.adg.lms.applications.helpers.get_course_cards_and_gross_details',
        return_value=(None, None, True))

    user_application.user = application_hub.user
    user_application.save()

    MultilingualCourseFactory(
        course=courses['test_course1'],
        multilingual_course_group=MultilingualCourseGroupFactory(
            is_program_prerequisite=pre_req_status,
            is_common_business_line_prerequisite=bu_pre_req_status,
            business_line_prerequisite=None))
    application_hub.program_prereq_courses_status = ApplicationHub.IN_PROGRESS
    application_hub.bu_prereq_courses_status = ApplicationHub.IN_PROGRESS
    application_hub.save()

    check_and_update_prereq_courses_status_to_completed(
        application_hub.user.id, courses['test_course1'].id)
    application_hub.refresh_from_db()

    assert expected_pre_req_courses_status == application_hub.program_prereq_courses_status
    assert expected_bu_pre_req_courses_status == application_hub.bu_prereq_courses_status
Ejemplo n.º 6
0
def test_is_course_in_prereqs(courses, bu_prereq):
    """
    Assert that True is returned only if course is in prerequisite course groups.
    """
    assert not is_course_in_prereqs(courses['test_course1'].id,
                                    bu_prereq=bu_prereq)

    course_group = MultilingualCourseGroupFactory(
        is_program_prerequisite=(not bu_prereq),
        is_common_business_line_prerequisite=bu_prereq)
    MultilingualCourseFactory(course=courses['test_course1'],
                              multilingual_course_group=course_group)

    assert is_course_in_prereqs(courses['test_course1'].id,
                                bu_prereq=bu_prereq)
Ejemplo n.º 7
0
def test_get_business_line_prereq_courses(user_client, courses):
    """
    Tests `get_business_line_prereq_courses` returns valid courses for a user.
    """
    user, _ = user_client

    UserApplicationFactory(user=user)
    ApplicationHubFactory(
        user=user, program_prereq_courses_status=ApplicationHub.COMPLETED)
    MultilingualCourseFactory(
        course=courses['test_course1'],
        multilingual_course_group=(MultilingualCourseGroupFactory(
            is_common_business_line_prerequisite=True)))

    courses_list = get_business_line_prereq_courses(user)

    assert courses_list == [courses['test_course1']]
Ejemplo n.º 8
0
def test_get_courses_from_course_groups(user_client, courses):
    """
    Tests `get_courses_from_course_groups` returns a valid list of courses.
    """
    user, _ = user_client

    UserApplicationFactory(user=user)
    ApplicationHubFactory(user=user)

    course_group = MultilingualCourseGroupFactory(
        is_common_business_line_prerequisite=True)
    MultilingualCourseFactory(course=courses['test_course1'],
                              multilingual_course_group=course_group)

    catalog_courses = get_courses_from_course_groups([course_group], user)

    assert catalog_courses == [courses['test_course1']]
Ejemplo n.º 9
0
def multilingual_course_group():
    return MultilingualCourseGroupFactory()