common.py 4.51 KB
Newer Older
1 2 3 4
"""
Define common steps for instructor dashboard acceptance tests.
"""

5
# pylint: disable=missing-docstring
6
# pylint: disable=redefined-outer-name
7 8 9 10

from __future__ import absolute_import

from lettuce import world, step
11
from mock import patch
12
from nose.tools import assert_in  # pylint: disable=no-name-in-module
13 14 15 16

from courseware.tests.factories import StaffFactory, InstructorFactory


17 18 19 20 21 22 23 24 25 26
@step(u'Given I am "([^"]*)" for a very large course')
def make_staff_or_instructor_for_large_course(step, role):
    make_large_course(step, role)


@patch.dict('courseware.access.settings.FEATURES', {"MAX_ENROLLMENT_INSTR_BUTTONS": 0})
def make_large_course(step, role):
    i_am_staff_or_instructor(step, role)


27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
@step(u'Given I am "([^"]*)" for a course')
def i_am_staff_or_instructor(step, role):  # pylint: disable=unused-argument
    ## In summary: makes a test course, makes a new Staff or Instructor user
    ## (depending on `role`), and logs that user in to the course

    # Store the role
    assert_in(role, ['instructor', 'staff'])

    # Clear existing courses to avoid conflicts
    world.clear_courses()

    # Create a new course
    course = world.CourseFactory.create(
        org='edx',
        number='999',
        display_name='Test Course'
    )

45
    world.course_key = course.id
46 47 48 49
    world.role = 'instructor'
    # Log in as the an instructor or staff for the course
    if role == 'instructor':
        # Make & register an instructor for the course
50 51
        world.instructor = InstructorFactory(course_key=world.course_key)
        world.enroll_user(world.instructor, world.course_key)
52 53 54 55 56 57 58 59 60 61 62

        world.log_in(
            username=world.instructor.username,
            password='test',
            email=world.instructor.email,
            name=world.instructor.profile.name
        )

    else:
        world.role = 'staff'
        # Make & register a staff member
63 64
        world.staff = StaffFactory(course_key=world.course_key)
        world.enroll_user(world.staff, world.course_key)
65 66 67 68 69 70 71 72 73 74 75 76

        world.log_in(
            username=world.staff.username,
            password='test',
            email=world.staff.email,
            name=world.staff.profile.name
        )


def go_to_section(section_name):
    # section name should be one of
    # course_info, membership, student_admin, data_download, analytics, send_email
77 78
    world.visit(u'/courses/{}'.format(world.course_key))
    world.css_click(u'a[href="/courses/{}/instructor"]'.format(world.course_key))
79 80 81 82 83 84 85 86 87 88 89 90 91 92
    world.css_click('a[data-section="{0}"]'.format(section_name))


@step(u'I click "([^"]*)"')
def click_a_button(step, button):  # pylint: disable=unused-argument

    if button == "Generate Grade Report":
        # Go to the data download section of the instructor dash
        go_to_section("data_download")

        # Click generate grade report button
        world.css_click('input[name="calculate-grades-csv"]')

        # Expect to see a message that grade report is being generated
93 94 95
        expected_msg = "Your grade report is being generated!" \
                       " You can view the status of the generation" \
                       " task in the 'Pending Tasks' section."
96
        world.wait_for_visible('#report-request-response')
97
        assert_in(
98
            expected_msg, world.css_text('#report-request-response'),
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
            msg="Could not find grade report generation success message."
        )

    elif button == "Grading Configuration":
        # Go to the data download section of the instructor dash
        go_to_section("data_download")

        world.css_click('input[name="dump-gradeconf"]')

    elif button == "List enrolled students' profile information":
        # Go to the data download section of the instructor dash
        go_to_section("data_download")

        world.css_click('input[name="list-profiles"]')

114 115 116
    elif button == "Download profile information as a CSV":
        # Go to the data download section of the instructor dash
        go_to_section("data_download")
117 118

        world.css_click('input[name="list-profiles-csv"]')
119

120 121
    else:
        raise ValueError("Unrecognized button option " + button)
122 123 124 125 126 127 128 129 130 131 132 133 134 135


@step(u'I visit the "([^"]*)" tab')
def click_a_button(step, tab_name):  # pylint: disable=unused-argument
    # course_info, membership, student_admin, data_download, analytics, send_email
    tab_name_dict = {
        'Course Info': 'course_info',
        'Membership': 'membership',
        'Student Admin': 'student_admin',
        'Data Download': 'data_download',
        'Analytics': 'analytics',
        'Email': 'send_email',
    }
    go_to_section(tab_name_dict[tab_name])