course-outline.py 4.51 KB
Newer Older
Don Mitchell committed
1 2
# pylint: disable=C0111
# pylint: disable=W0621
3

4 5
from lettuce import world, step
from common import *
6
from nose.tools import assert_true, assert_false, assert_equal  # pylint: disable=E0611
7 8 9 10

from logging import getLogger
logger = getLogger(__name__)

Calen Pennington committed
11

12 13
@step(u'I have a course with no sections$')
def have_a_course(step):
14
    world.clear_courses()
15
    course = world.CourseFactory.create()
16

Calen Pennington committed
17

18 19
@step(u'I have a course with 1 section$')
def have_a_course_with_1_section(step):
20
    world.clear_courses()
21 22 23
    course = world.CourseFactory.create()
    section = world.ItemFactory.create(parent_location=course.location)
    subsection1 = world.ItemFactory.create(
24
        parent_location=section.location,
25
        category='sequential',
Calen Pennington committed
26 27
        display_name='Subsection One',)

28 29 30

@step(u'I have a course with multiple sections$')
def have_a_course_with_two_sections(step):
31
    world.clear_courses()
32 33 34
    course = world.CourseFactory.create()
    section = world.ItemFactory.create(parent_location=course.location)
    subsection1 = world.ItemFactory.create(
35
        parent_location=section.location,
36
        category='sequential',
Calen Pennington committed
37
        display_name='Subsection One',)
38
    section2 = world.ItemFactory.create(
39 40
        parent_location=course.location,
        display_name='Section Two',)
41
    subsection2 = world.ItemFactory.create(
42
        parent_location=section2.location,
43
        category='sequential',
Calen Pennington committed
44
        display_name='Subsection Alpha',)
45
    subsection3 = world.ItemFactory.create(
46
        parent_location=section2.location,
47
        category='sequential',
Calen Pennington committed
48 49
        display_name='Subsection Beta',)

50

51 52
@step(u'I navigate to the course outline page$')
def navigate_to_the_course_outline_page(step):
JonahStanley committed
53 54
    create_studio_user(is_staff=True)
    log_into_studio()
55
    course_locator = 'a.course-link'
56
    world.css_click(course_locator)
57

Calen Pennington committed
58

59 60
@step(u'I navigate to the outline page of a course with multiple sections')
def nav_to_the_outline_page_of_a_course_with_multiple_sections(step):
61
    step.given('I have a course with multiple sections')
62
    step.given('I navigate to the course outline page')
63

Calen Pennington committed
64

65 66
@step(u'I add a section')
def i_add_a_section(step):
67
    add_section()
68

Calen Pennington committed
69

70 71
@step(u'I press the "section" delete icon')
def i_press_the_section_delete_icon(step):
72
    delete_locator = 'section .outline-section > .section-header a.delete-button'
73
    world.css_click(delete_locator)
Calen Pennington committed
74

75

76 77 78 79
@step(u'I will confirm all alerts')
def i_confirm_all_alerts(step):
    confirm_locator = '.prompt .nav-actions a.action-primary'
    world.css_click(confirm_locator)
Calen Pennington committed
80

81

82 83 84
@step(u'I see the "([^"]*) All Sections" link$')
def i_see_the_collapse_expand_all_span(step, text):
    if text == "Collapse":
85
        span_locator = '.button-toggle-expand-collapse .collapse-all .label'
86
    elif text == "Expand":
87
        span_locator = '.button-toggle-expand-collapse .expand-all .label'
88
    assert_true(world.css_visible(span_locator))
89

Calen Pennington committed
90

91 92 93
@step(u'I do not see the "([^"]*) All Sections" link$')
def i_do_not_see_the_collapse_expand_all_span(step, text):
    if text == "Collapse":
94
        span_locator = '.button-toggle-expand-collapse .collapse-all .label'
95
    elif text == "Expand":
96
        span_locator = '.button-toggle-expand-collapse .expand-all .label'
97
    assert_false(world.css_visible(span_locator))
98

Calen Pennington committed
99

100 101 102
@step(u'I click the "([^"]*) All Sections" link$')
def i_click_the_collapse_expand_all_span(step, text):
    if text == "Collapse":
103
        span_locator = '.button-toggle-expand-collapse .collapse-all .label'
104
    elif text == "Expand":
105
        span_locator = '.button-toggle-expand-collapse .expand-all .label'
106 107 108 109 110 111 112
    assert_true(world.browser.is_element_present_by_css(span_locator))
    world.css_click(span_locator)


@step(u'I ([^"]*) the first section$')
def i_collapse_expand_a_section(step, text):
    if text == "collapse":
113
        locator = 'section .outline-section .ui-toggle-expansion'
114
    elif text == "expand":
115
        locator = 'section .outline-section .ui-toggle-expansion'
116
    world.css_click(locator)
117

Calen Pennington committed
118

119 120
@step(u'all sections are ([^"]*)$')
def all_sections_are_collapsed_or_expanded(step, text):
121
    subsection_locator = 'div.subsection-list'
122
    subsections = world.css_find(subsection_locator)
123
    for index in range(len(subsections)):
124 125 126 127
        if text == "collapsed":
            assert_false(world.css_visible(subsection_locator, index=index))
        elif text == "expanded":
            assert_true(world.css_visible(subsection_locator, index=index))
128 129 130 131 132 133


@step(u"I change an assignment's grading status")
def change_grading_status(step):
    world.css_find('a.menu-toggle').click()
    world.css_find('.menu li').first.click()