registration.py 2.22 KB
Newer Older
1
# pylint: disable=missing-docstring
2

3
from lettuce import world, step
4
from lettuce.django import django_url
5
import time
6

Will Daly committed
7

8
@step('I register for the course "([^"]*)"$')
Don Mitchell committed
9
def i_register_for_the_course(_step, course):
10
    url = django_url('courses/%s/about' % world.scenario_dict['COURSE'].id.to_deprecated_string())
11
    world.browser.visit(url)
12 13
    world.css_click('.intro a.register')
    assert world.is_css_present('.container.dashboard')
14

15

16 17 18 19
@step('I register to audit the course$')
def i_register_to_audit_the_course(_step):
    url = django_url('courses/%s/about' % world.scenario_dict['COURSE'].id.to_deprecated_string())
    world.browser.visit(url)
20
    world.css_click('.intro a.register')
21 22 23 24 25 26 27
    # When the page first loads some animation needs to
    # complete before this button is in a stable location
    world.retry_on_exception(
        lambda: world.browser.find_by_name("honor_mode").click(),
        max_attempts=10,
        ignored_exceptions=AttributeError
    )
28
    time.sleep(1)
29
    assert world.is_css_present('.container.dashboard')
30

Jay Zoldak committed
31

32
@step(u'I should see an empty dashboard message')
Don Mitchell committed
33
def i_should_see_empty_dashboard(_step):
34
    empty_dash_css = '.empty-dashboard-message'
35 36 37
    assert world.is_css_present(empty_dash_css)


38
@step(u'I should( NOT)? see the course numbered "([^"]*)" in my dashboard$')
Don Mitchell committed
39
def i_should_see_that_course_in_my_dashboard(_step, doesnt_appear, course):
40
    course_link_css = '.my-courses a[href*="%s"]' % course
41
    if doesnt_appear:
42
        assert world.is_css_not_present(course_link_css)
43 44
    else:
        assert world.is_css_present(course_link_css)
45 46


47 48
@step(u'I unenroll from the course numbered "([^"]*)"')
def i_unenroll_from_that_course(_step, course):
49 50 51 52 53 54
    more_actions_dropdown_link_selector = '[id*=actions-dropdown-link-0]'
    assert world.is_css_present(more_actions_dropdown_link_selector)
    world.css_click(more_actions_dropdown_link_selector)

    unregister_css = 'li.actions-item a.action-unenroll[data-course-number*="{course_number}"][href*=unenroll-modal]'.format(course_number=course)
    assert world.is_css_present(unregister_css)
55
    world.css_click(unregister_css)
56

57
    button_css = '#unenroll-modal input[value="Unenroll"]'
58
    assert world.is_css_present(button_css)
59
    world.css_click(button_css)