course-overview.py 4.39 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 overview page$')
def navigate_to_the_course_overview_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 61 62 63
@step(u'I navigate to the courseware page of a course with multiple sections')
def nav_to_the_courseware_page_of_a_course_with_multiple_sections(step):
    step.given('I have a course with multiple sections')
    step.given('I navigate to the course overview page')

Calen Pennington committed
64

65 66 67 68
@step(u'I add a section')
def i_add_a_section(step):
    add_section(name='My New Section That I Just Added')

Calen Pennington committed
69

70 71 72
@step(u'I click the "([^"]*)" link$')
def i_click_the_text_span(step, text):
    span_locator = '.toggle-button-sections span'
73
    assert_true(world.browser.is_element_present_by_css(span_locator))
74
    # first make sure that the expand/collapse text is the one you expected
75
    assert_true(world.css_has_value(span_locator, text))
76
    world.css_click(span_locator)
77

Calen Pennington committed
78

79 80 81
@step(u'I collapse the first section$')
def i_collapse_a_section(step):
    collapse_locator = 'section.courseware-section a.collapse'
82
    world.css_click(collapse_locator)
83

Calen Pennington committed
84

85 86 87
@step(u'I expand the first section$')
def i_expand_a_section(step):
    expand_locator = 'section.courseware-section a.expand'
88
    world.css_click(expand_locator)
89

Calen Pennington committed
90

91 92 93
@step(u'I see the "([^"]*)" link$')
def i_see_the_span_with_text(step, text):
    span_locator = '.toggle-button-sections span'
94
    assert_true(world.css_has_value(span_locator, text))
95
    assert_true(world.css_visible(span_locator))
96

Calen Pennington committed
97

98 99 100 101
@step(u'I do not see the "([^"]*)" link$')
def i_do_not_see_the_span_with_text(step, text):
    # Note that the span will exist on the page but not be visible
    span_locator = '.toggle-button-sections span'
102 103
    assert_true(world.is_css_present(span_locator))
    assert_false(world.css_visible(span_locator))
104

Calen Pennington committed
105

106 107 108
@step(u'all sections are expanded$')
def all_sections_are_expanded(step):
    subsection_locator = 'div.subsection-list'
109
    subsections = world.css_find(subsection_locator)
110 111
    for index in range(len(subsections)):
        assert_true(world.css_visible(subsection_locator, index=index))
112

Calen Pennington committed
113

114
@step(u'all sections are collapsed$')
115
def all_sections_are_collapsed(step):
116
    subsection_locator = 'div.subsection-list'
117
    subsections = world.css_find(subsection_locator)
118 119
    for index in range(len(subsections)):
        assert_false(world.css_visible(subsection_locator, index=index))
120 121 122 123 124 125


@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()
126 127 128 129


@step(u'I reorder subsections')
def reorder_subsections(_step):
Peter Fogg committed
130
    draggable_css = '.subsection-drag-handle'
131 132 133
    ele = world.css_find(draggable_css).first
    ele.action_chains.drag_and_drop_by_offset(
        ele._element,
Peter Fogg committed
134
        0,
135
        25
136
    ).perform()