grading.py 6.99 KB
Newer Older
1 2
# pylint: disable=C0111
# pylint: disable=W0621
3 4 5

from lettuce import world, step
from common import *
6
from terrain.steps import reload_the_page
7
from selenium.common.exceptions import InvalidElementStateException
8
from opaque_keys.edx.locations import SlashSeparatedCourseKey
9
from contentstore.utils import reverse_course_url
10
from nose.tools import assert_in, assert_not_in, assert_equal, assert_not_equal  # pylint: disable=E0611
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39


@step(u'I am viewing the grading settings')
def view_grading_settings(step):
    world.click_course_settings()
    link_css = 'li.nav-course-settings-grading a'
    world.css_click(link_css)


@step(u'I add "([^"]*)" new grade')
def add_grade(step, many):
    grade_css = '.new-grade-button'
    for i in range(int(many)):
        world.css_click(grade_css)


@step(u'I delete a grade')
def delete_grade(step):
    #grade_css = 'li.grade-specific-bar > a.remove-button'
    #range_css = '.grade-specific-bar'
    #world.css_find(range_css)[1].mouseover()
    #world.css_click(grade_css)
    world.browser.execute_script('document.getElementsByClassName("remove-button")[0].click()')


@step(u'I see I now have "([^"]*)" grades$')
def view_grade_slider(step, how_many):
    grade_slider_css = '.grade-specific-bar'
    all_grades = world.css_find(grade_slider_css)
40
    assert_equal(len(all_grades), int(how_many))
41 42 43 44 45 46


@step(u'I move a grading section')
def move_grade_slider(step):
    moveable_css = '.ui-resizable-e'
    f = world.css_find(moveable_css).first
47 48 49 50 51 52 53 54
    f.action_chains.drag_and_drop_by_offset(f._element, 100, 0).perform()


@step(u'I see that the grade range has changed')
def confirm_change(step):
    range_css = '.range'
    all_ranges = world.css_find(range_css)
    for i in range(len(all_ranges)):
55
        assert_not_equal(world.css_html(range_css, index=i), '0-50')
56 57 58 59 60 61 62


@step(u'I change assignment type "([^"]*)" to "([^"]*)"$')
def change_assignment_name(step, old_name, new_name):
    name_id = '#course-grading-assignment-name'
    index = get_type_index(old_name)
    f = world.css_find(name_id)[index]
63
    assert_not_equal(index, -1)
64 65 66 67 68 69 70
    for count in range(len(old_name)):
        f._element.send_keys(Keys.END, Keys.BACK_SPACE)
    f._element.send_keys(new_name)


@step(u'I go back to the main course page')
def main_course_page(step):
cahrens committed
71
    course_name = world.scenario_dict['COURSE'].display_name.replace(' ', '_')
72 73 74 75
    course_key = SlashSeparatedCourseKey(
        world.scenario_dict['COURSE'].org,
        world.scenario_dict['COURSE'].number,
        course_name
cahrens committed
76
    )
77
    main_page_link = reverse_course_url('course_handler', course_key)
cahrens committed
78

79 80
    world.visit(main_page_link)
    assert_in('Course Outline', world.css_text('h1.page-header'))
81 82 83 84


@step(u'I do( not)? see the assignment name "([^"]*)"$')
def see_assignment_name(step, do_not, name):
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    # TODO: rewrite this once grading has been added back to the course outline
    pass
    # assignment_menu_css = 'ul.menu > li > a'
    # # First assert that it is there, make take a bit to redraw
    # assert_true(
    #     world.css_find(assignment_menu_css),
    #     msg="Could not find assignment menu"
    # )
    #
    # assignment_menu = world.css_find(assignment_menu_css)
    # allnames = [item.html for item in assignment_menu]
    # if do_not:
    #     assert_not_in(name, allnames)
    # else:
    #     assert_in(name, allnames)
100 101 102 103 104


@step(u'I delete the assignment type "([^"]*)"$')
def delete_assignment_type(step, to_delete):
    delete_css = '.remove-grading-data'
105
    world.css_click(delete_css, index=get_type_index(to_delete))
106 107 108 109 110 111 112


@step(u'I add a new assignment type "([^"]*)"$')
def add_assignment_type(step, new_name):
    add_button_css = '.add-grading-data'
    world.css_click(add_button_css)
    name_id = '#course-grading-assignment-name'
113 114
    new_assignment = world.css_find(name_id)[-1]
    new_assignment._element.send_keys(new_name)
115 116


117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
@step(u'I set the assignment weight to "([^"]*)"$')
def set_weight(step, weight):
    weight_id = '#course-grading-assignment-gradeweight'
    weight_field = world.css_find(weight_id)[-1]
    old_weight = world.css_value(weight_id, -1)
    for count in range(len(old_weight)):
        weight_field._element.send_keys(Keys.END, Keys.BACK_SPACE)
    weight_field._element.send_keys(weight)


@step(u'the assignment weight is displayed as "([^"]*)"$')
def verify_weight(step, weight):
    weight_id = '#course-grading-assignment-gradeweight'
    assert_equal(world.css_value(weight_id, -1), weight)


133 134 135 136
@step(u'I do not see the changes persisted on refresh$')
def changes_not_persisted(step):
    reload_the_page(step)
    name_id = '#course-grading-assignment-name'
137
    assert_equal(world.css_value(name_id), 'Homework')
138 139


140 141
@step(u'I see the assignment type "(.*)"$')
def i_see_the_assignment_type(_step, name):
142 143 144
    assignment_css = '#course-grading-assignment-name'
    assignments = world.css_find(assignment_css)
    types = [ele['value'] for ele in assignments]
145
    assert_in(name, types)
146 147


148 149 150 151 152 153 154 155 156 157 158
@step(u'I change the highest grade range to "(.*)"$')
def change_grade_range(_step, range_name):
    range_css = 'span.letter-grade'
    grade = world.css_find(range_css).first
    grade.value = range_name


@step(u'I see the highest grade range is "(.*)"$')
def i_see_highest_grade_range(_step, range_name):
    range_css = 'span.letter-grade'
    grade = world.css_find(range_css).first
159
    assert_equal(grade.value, range_name)
160

161 162 163 164 165

@step(u'I cannot edit the "Fail" grade range$')
def cannot_edit_fail(_step):
    range_css = 'span.letter-grade'
    ranges = world.css_find(range_css)
166 167
    assert_equal(len(ranges), 2)
    assert_not_equal(ranges.last.value, 'Failure')
168 169

    # try to change the grade range -- this should throw an exception
170 171
    try:
        ranges.last.value = 'Failure'
172
    except (InvalidElementStateException):
173 174
        pass  # We should get this exception on failing to edit the element

175 176
    # check to be sure that nothing has changed
    ranges = world.css_find(range_css)
177 178
    assert_equal(len(ranges), 2)
    assert_not_equal(ranges.last.value, 'Failure')
179

180

181 182 183 184
@step(u'I change the grace period to "(.*)"$')
def i_change_grace_period(_step, grace_period):
    grace_period_css = '#course-grading-graceperiod'
    ele = world.css_find(grace_period_css).first
Jay Zoldak committed
185

186 187 188 189 190
    # Sometimes it takes a moment for the JavaScript
    # to populate the field.  If we don't wait for
    # this to happen, then we can end up with
    # an invalid value (e.g. "00:0048:00")
    # which prevents us from saving.
191
    assert_true(world.css_has_value(grace_period_css, "00:00"))
192 193

    # Set the new grace period
194 195 196 197 198 199
    ele.value = grace_period


@step(u'I see the grace period is "(.*)"$')
def the_grace_period_is(_step, grace_period):
    grace_period_css = '#course-grading-graceperiod'
200 201 202 203 204 205

    # The default value is 00:00
    # so we need to wait for it to change
    world.wait_for(
        lambda _: world.css_has_value(grace_period_css, grace_period)
    )
206 207


208 209
def get_type_index(name):
    name_id = '#course-grading-assignment-name'
210 211 212 213
    all_types = world.css_find(name_id)
    for index in range(len(all_types)):
        if world.css_value(name_id, index=index) == name:
            return index
214
    return -1