course-settings.py 7.07 KB
Newer Older
1
# pylint: disable=missing-docstring
2
# pylint: disable=redefined-outer-name
3

4 5 6
from lettuce import world, step
from terrain.steps import reload_the_page
from selenium.webdriver.common.keys import Keys
Peter Fogg committed
7
from common import type_in_codemirror, upload_file
8
from django.conf import settings
9

10
from nose.tools import assert_true, assert_false, assert_equal  # pylint: disable=no-name-in-module
11

12 13
TEST_ROOT = settings.COMMON_TEST_DATA_ROOT

14 15 16 17 18 19 20 21 22 23
COURSE_START_DATE_CSS = "#course-start-date"
COURSE_END_DATE_CSS = "#course-end-date"
ENROLLMENT_START_DATE_CSS = "#course-enrollment-start-date"
ENROLLMENT_END_DATE_CSS = "#course-enrollment-end-date"

COURSE_START_TIME_CSS = "#course-start-time"
COURSE_END_TIME_CSS = "#course-end-time"
ENROLLMENT_START_TIME_CSS = "#course-enrollment-start-time"
ENROLLMENT_END_TIME_CSS = "#course-enrollment-end-time"

24 25
DUMMY_TIME = "15:30"
DEFAULT_TIME = "00:00"
26 27 28 29 30


############### ACTIONS ####################
@step('I select Schedule and Details$')
def test_i_select_schedule_and_details(step):
David Baumgold committed
31
    world.click_course_settings()
32
    link_css = 'li.nav-course-settings-schedule a'
33
    world.css_click(link_css)
34 35 36
    world.wait_for_requirejs(
        ["jquery", "js/models/course",
         "js/models/settings/course_details", "js/views/settings/main"])
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63


@step('I have set course dates$')
def test_i_have_set_course_dates(step):
    step.given('I have opened a new course in Studio')
    step.given('I select Schedule and Details')
    step.given('And I set course dates')


@step('And I set course dates$')
def test_and_i_set_course_dates(step):
    set_date_or_time(COURSE_START_DATE_CSS, '12/20/2013')
    set_date_or_time(COURSE_END_DATE_CSS, '12/26/2013')
    set_date_or_time(ENROLLMENT_START_DATE_CSS, '12/1/2013')
    set_date_or_time(ENROLLMENT_END_DATE_CSS, '12/10/2013')

    set_date_or_time(COURSE_START_TIME_CSS, DUMMY_TIME)
    set_date_or_time(ENROLLMENT_END_TIME_CSS, DUMMY_TIME)


@step('And I clear all the dates except start$')
def test_and_i_clear_all_the_dates_except_start(step):
    set_date_or_time(COURSE_END_DATE_CSS, '')
    set_date_or_time(ENROLLMENT_START_DATE_CSS, '')
    set_date_or_time(ENROLLMENT_END_DATE_CSS, '')


64 65
@step('Then I see cleared dates$')
def test_then_i_see_cleared_dates(step):
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    verify_date_or_time(COURSE_END_DATE_CSS, '')
    verify_date_or_time(ENROLLMENT_START_DATE_CSS, '')
    verify_date_or_time(ENROLLMENT_END_DATE_CSS, '')

    verify_date_or_time(COURSE_END_TIME_CSS, '')
    verify_date_or_time(ENROLLMENT_START_TIME_CSS, '')
    verify_date_or_time(ENROLLMENT_END_TIME_CSS, '')

    # Verify course start date (required) and time still there
    verify_date_or_time(COURSE_START_DATE_CSS, '12/20/2013')
    verify_date_or_time(COURSE_START_TIME_CSS, DUMMY_TIME)


@step('I clear the course start date$')
def test_i_clear_the_course_start_date(step):
    set_date_or_time(COURSE_START_DATE_CSS, '')


@step('I receive a warning about course start date$')
def test_i_receive_a_warning_about_course_start_date(step):
86 87 88
    assert_true(world.css_has_text('.message-error', 'The course must have an assigned start date.'))
    assert_true('error' in world.css_find(COURSE_START_DATE_CSS).first._element.get_attribute('class'))
    assert_true('error' in world.css_find(COURSE_START_TIME_CSS).first._element.get_attribute('class'))
89 90


91 92
@step('the previously set start date is shown$')
def test_the_previously_set_start_date_is_shown(step):
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
    verify_date_or_time(COURSE_START_DATE_CSS, '12/20/2013')
    verify_date_or_time(COURSE_START_TIME_CSS, DUMMY_TIME)


@step('Given I have tried to clear the course start$')
def test_i_have_tried_to_clear_the_course_start(step):
    step.given("I have set course dates")
    step.given("I clear the course start date")
    step.given("I receive a warning about course start date")


@step('I have entered a new course start date$')
def test_i_have_entered_a_new_course_start_date(step):
    set_date_or_time(COURSE_START_DATE_CSS, '12/22/2013')


@step('The warning about course start date goes away$')
def test_the_warning_about_course_start_date_goes_away(step):
111
    assert world.is_css_not_present('.message-error')
112 113
    assert_false('error' in world.css_find(COURSE_START_DATE_CSS).first._element.get_attribute('class'))
    assert_false('error' in world.css_find(COURSE_START_TIME_CSS).first._element.get_attribute('class'))
114 115


116 117
@step('my new course start date is shown$')
def new_course_start_date_is_shown(step):
118 119 120 121 122
    verify_date_or_time(COURSE_START_DATE_CSS, '12/22/2013')
    # Time should have stayed from before attempt to clear date.
    verify_date_or_time(COURSE_START_TIME_CSS, DUMMY_TIME)


123 124 125 126 127 128 129 130
@step('I change fields$')
def test_i_change_fields(step):
    set_date_or_time(COURSE_START_DATE_CSS, '7/7/7777')
    set_date_or_time(COURSE_END_DATE_CSS, '7/7/7777')
    set_date_or_time(ENROLLMENT_START_DATE_CSS, '7/7/7777')
    set_date_or_time(ENROLLMENT_END_DATE_CSS, '7/7/7777')


131 132 133 134 135
@step('I change the course overview')
def test_change_course_overview(_step):
    type_in_codemirror(0, "<h1>Overview</h1>")


Peter Fogg committed
136 137 138 139 140 141
@step('I click the "Upload Course Image" button')
def click_upload_button(_step):
    button_css = '.action-upload-image'
    world.css_click(button_css)


142 143
@step('I upload a new course image$')
def upload_new_course_image(_step):
144
    upload_file('image.jpg', sub_path="uploads")
145 146 147 148 149 150 151 152


@step('I should see the new course image$')
def i_see_new_course_image(_step):
    img_css = '#course-image'
    images = world.css_find(img_css)
    assert len(images) == 1
    img = images[0]
Don Mitchell committed
153
    expected_src = 'image.jpg'
154

155
    # Don't worry about the domain in the URL
156 157
    success_func = lambda _: img['src'].endswith(expected_src)
    world.wait_for(success_func)
158 159 160 161 162


@step('the image URL should be present in the field')
def image_url_present(_step):
    field_css = '#course-image-url'
Don Mitchell committed
163 164
    expected_value = 'image.jpg'
    assert world.css_value(field_css).endswith(expected_value)
165

166

167 168 169 170 171
############### HELPER METHODS ####################
def set_date_or_time(css, date_or_time):
    """
    Sets date or time field.
    """
172 173
    world.css_fill(css, date_or_time)
    e = world.css_find(css).first
174 175 176 177 178 179 180 181
    # hit Enter to apply the changes
    e._element.send_keys(Keys.ENTER)


def verify_date_or_time(css, date_or_time):
    """
    Verifies date or time field.
    """
182 183 184
    # We need to wait for JavaScript to fill in the field, so we use
    # css_has_value(), which first checks that the field is not blank
    assert_true(world.css_has_value(css, date_or_time))
185 186


187 188 189
@step('I do not see the changes')
@step('I see the set dates')
def i_see_the_set_dates(_step):
190 191 192 193 194 195 196 197 198 199 200 201 202
    """
    Ensure that each field has the value set in `test_and_i_set_course_dates`.
    """
    verify_date_or_time(COURSE_START_DATE_CSS, '12/20/2013')
    verify_date_or_time(COURSE_END_DATE_CSS, '12/26/2013')
    verify_date_or_time(ENROLLMENT_START_DATE_CSS, '12/01/2013')
    verify_date_or_time(ENROLLMENT_END_DATE_CSS, '12/10/2013')

    verify_date_or_time(COURSE_START_TIME_CSS, DUMMY_TIME)
    # Unset times get set to 12 AM once the corresponding date has been set.
    verify_date_or_time(COURSE_END_TIME_CSS, DEFAULT_TIME)
    verify_date_or_time(ENROLLMENT_START_TIME_CSS, DEFAULT_TIME)
    verify_date_or_time(ENROLLMENT_END_TIME_CSS, DUMMY_TIME)