textbooks.py 4.47 KB
Newer Older
1
# pylint: disable=missing-docstring
2
# pylint: disable=redefined-outer-name
3 4

from lettuce import world, step
5
from django.conf import settings
Peter Fogg committed
6
from common import upload_file
7
from nose.tools import assert_equal
8 9 10 11 12 13

TEST_ROOT = settings.COMMON_TEST_DATA_ROOT


@step(u'I go to the textbooks page')
def go_to_uploads(_step):
14
    world.wait_for_js_to_load()
15
    world.click_course_content()
16 17
    menu_css = 'li.nav-course-courseware-textbooks a'
    world.css_click(menu_css)
18

David Baumgold committed
19

20 21 22 23 24 25 26
@step(u'I should see a message telling me to create a new textbook')
def assert_create_new_textbook_msg(_step):
    css = ".wrapper-content .no-textbook-content"
    assert world.is_css_present(css)
    no_tb = world.css_find(css)
    assert "You haven't added any textbooks" in no_tb.text

David Baumgold committed
27

28
@step(u'I upload the textbook "([^"]*)"$')
Peter Fogg committed
29
def upload_textbook(_step, file_name):
30
    upload_file(file_name, sub_path="uploads/")
31

David Baumgold committed
32

33 34 35 36 37 38
@step(u'I click (on )?the New Textbook button')
def click_new_textbook(_step, on):
    button_css = ".nav-actions .new-button"
    button = world.css_find(button_css)
    button.click()

David Baumgold committed
39

40 41 42 43
@step(u'I name my textbook "([^"]*)"')
def name_textbook(_step, name):
    input_css = ".textbook input[name=textbook-name]"
    world.css_fill(input_css, name)
44 45
    if world.is_firefox():
        world.trigger_event(input_css)
46

David Baumgold committed
47

48 49 50
@step(u'I name the (first|second|third) chapter "([^"]*)"')
def name_chapter(_step, ordinal, name):
    index = ["first", "second", "third"].index(ordinal)
Jay Zoldak committed
51
    input_css = ".textbook .chapter{i} input.chapter-name".format(i=index + 1)
52
    world.css_fill(input_css, name)
53 54
    if world.is_firefox():
        world.trigger_event(input_css)
55

David Baumgold committed
56

57 58 59
@step(u'I type in "([^"]*)" for the (first|second|third) chapter asset')
def asset_chapter(_step, name, ordinal):
    index = ["first", "second", "third"].index(ordinal)
Jay Zoldak committed
60
    input_css = ".textbook .chapter{i} input.chapter-asset-path".format(i=index + 1)
61
    world.css_fill(input_css, name)
62 63
    if world.is_firefox():
        world.trigger_event(input_css)
64

David Baumgold committed
65

66 67 68
@step(u'I click the Upload Asset link for the (first|second|third) chapter')
def click_upload_asset(_step, ordinal):
    index = ["first", "second", "third"].index(ordinal)
Jay Zoldak committed
69
    button_css = ".textbook .chapter{i} .action-upload".format(i=index + 1)
70 71
    world.css_click(button_css)

David Baumgold committed
72

73 74 75
@step(u'I click Add a Chapter')
def click_add_chapter(_step):
    button_css = ".textbook .action-add-chapter"
76 77
    world.css_click(button_css)

David Baumgold committed
78

79 80 81 82 83
@step(u'I save the textbook')
def save_textbook(_step):
    submit_css = "form.edit-textbook button[type=submit]"
    world.css_click(submit_css)

David Baumgold committed
84

85
@step(u'I should see a textbook named "([^"]*)" with a chapter path containing "([^"]*)"')
86
def check_textbook(_step, textbook_name, chapter_name):
87 88 89 90
    title = world.css_text(".textbook h3.textbook-title", index=0)
    chapter = world.css_text(".textbook .wrap-textbook p", index=0)
    assert_equal(title, textbook_name)
    assert_equal(chapter, chapter_name)
91

David Baumgold committed
92

93
@step(u'I should see a textbook named "([^"]*)" with (\d+) chapters')
David Baumgold committed
94
def check_textbook_chapters(_step, textbook_name, num_chapters_str):
95
    num_chapters = int(num_chapters_str)
96 97 98 99 100 101 102 103
    title = world.css_text(".textbook .view-textbook h3.textbook-title", index=0)
    toggle_text = world.css_text(".textbook .view-textbook .chapter-toggle", index=0)
    assert_equal(title, textbook_name)
    assert_equal(
        toggle_text,
        "{num} PDF Chapters".format(num=num_chapters),
        "Expected {num} chapters, found {real}".format(num=num_chapters, real=toggle_text)
    )
104

David Baumgold committed
105

106 107 108 109
@step(u'I click the textbook chapters')
def click_chapters(_step):
    world.css_click(".textbook a.chapter-toggle")

David Baumgold committed
110

111 112 113 114 115 116 117 118
@step(u'the (first|second|third) chapter should be named "([^"]*)"')
def check_chapter_name(_step, ordinal, name):
    index = ["first", "second", "third"].index(ordinal)
    chapter = world.css_find(".textbook .view-textbook ol.chapters li")[index]
    element = chapter.find_by_css(".chapter-name")
    assert element.text == name, "Expected chapter named {expected}, found chapter named {actual}".format(
        expected=name, actual=element.text)

David Baumgold committed
119

120
@step(u'the (first|second|third) chapter should have an asset called "([^"]*)"')
David Baumgold committed
121
def check_chapter_asset(_step, ordinal, name):
122 123 124 125 126
    index = ["first", "second", "third"].index(ordinal)
    chapter = world.css_find(".textbook .view-textbook ol.chapters li")[index]
    element = chapter.find_by_css(".chapter-asset-path")
    assert element.text == name, "Expected chapter with asset {expected}, found chapter with asset {actual}".format(
        expected=name, actual=element.text)