section.py 3.56 KB
Newer Older
1 2 3
#pylint: disable=C0111
#pylint: disable=W0621

4 5
from lettuce import world, step
from common import *
cahrens committed
6
from nose.tools import assert_equal
7 8

############### ACTIONS ####################
9 10


11 12 13
@step('I click the new section link$')
def i_click_new_section_link(step):
    link_css = 'a.new-courseware-section-button'
14
    world.css_click(link_css)
15

16

17 18
@step('I enter the section name and click save$')
def i_save_section_name(step):
cahrens committed
19 20 21 22 23 24
    save_section_name('My Section')


@step('I enter a section name with a quote and click save$')
def i_save_section_name_with_quote(step):
    save_section_name('Section with "Quote"')
25

26

27 28 29
@step('I have added a new section$')
def i_have_added_new_section(step):
    add_section()
30 31


32 33 34
@step('I click the Edit link for the release date$')
def i_click_the_edit_link_for_the_release_date(step):
    button_css = 'div.section-published-date a.edit-button'
35
    world.css_click(button_css)
36

37

38 39
@step('I save a new section release date$')
def i_save_a_new_section_release_date(step):
cahrens committed
40
    set_date_and_time('input.start-date.date.hasDatepicker', '12/25/2013',
41
        'input.start-time.time.ui-timepicker-input', '00:00')
42
    world.browser.click_link_by_text('Save')
43

44

45
############ ASSERTIONS ###################
46 47


48 49
@step('I see my section on the Courseware page$')
def i_see_my_section_on_the_courseware_page(step):
cahrens committed
50 51 52 53 54 55 56 57 58 59
    see_my_section_on_the_courseware_page('My Section')


@step('I see my section name with a quote on the Courseware page$')
def i_see_my_section_name_with_quote_on_the_courseware_page(step):
    see_my_section_on_the_courseware_page('Section with "Quote"')


@step('I click to edit the section name$')
def i_click_to_edit_section_name(step):
60
    world.css_click('span.section-name-span')
cahrens committed
61 62 63 64 65


@step('I see the complete section name with a quote in the editor$')
def i_see_complete_section_name_with_quote_in_editor(step):
    css = '.edit-section-name'
66
    assert world.is_css_present(css)
cahrens committed
67
    assert_equal(world.browser.find_by_css(css).value, 'Section with "Quote"')
68

69

70 71 72 73 74
@step('the section does not exist$')
def section_does_not_exist(step):
    css = 'span.section-name-span'
    assert world.browser.is_element_not_present_by_css(css)

75

76 77 78 79 80
@step('I see a release date for my section$')
def i_see_a_release_date_for_my_section(step):
    import re

    css = 'span.published-status'
81
    assert world.is_css_present(css)
82 83 84 85 86 87 88
    status_text = world.browser.find_by_css(css).text

    # e.g. 11/06/2012 at 16:25
    msg = 'Will Release:'
    date_regex = '[01][0-9]\/[0-3][0-9]\/[12][0-9][0-9][0-9]'
    time_regex = '[0-2][0-9]:[0-5][0-9]'
    match_string = '%s %s at %s' % (msg, date_regex, time_regex)
cahrens committed
89
    assert re.match(match_string, status_text)
90

91

92 93 94
@step('I see a link to create a new subsection$')
def i_see_a_link_to_create_a_new_subsection(step):
    css = 'a.new-subsection-item'
95
    assert world.is_css_present(css)
96

97

98 99 100
@step('the section release date picker is not visible$')
def the_section_release_date_picker_not_visible(step):
    css = 'div.edit-subsection-publish-settings'
101
    assert not world.css_visible(css)
102

103

104 105 106
@step('the section release date is updated$')
def the_section_release_date_is_updated(step):
    css = 'span.published-status'
107
    status_text = world.css_text(css)
108
    assert_equal(status_text, 'Will Release: 12/25/2013 at 00:00 UTC')
cahrens committed
109 110 111 112 113 114 115


############ HELPER METHODS ###################

def save_section_name(name):
    name_css = '.new-section-name'
    save_css = '.new-section-name-save'
116 117
    world.css_fill(name_css, name)
    world.css_click(save_css)
cahrens committed
118 119 120 121


def see_my_section_on_the_courseware_page(name):
    section_css = 'span.section-name-span'
122
    assert world.css_has_text(section_css, name)