Test for the deprecate skills view
==================================

We are going to test that when skillsets are deprecated, section
gradebooks keep untouched.

Helpers:

    >>> def print_checkbox(browser, cell):
    ...     checked = browser.driver.execute_script(
    ...         'return $(arguments[0]).find("input:checked").length', cell)
    ...     is_checked = bool(checked)
    ...     return ['[ ]', '[X]'][is_checked]
    >>> def print_skills_table(browser):
    ...     for row in browser.query_all.css('table tbody tr'):
    ...         cells = browser.driver.execute_script(
    ...                     'return $(arguments[0]).find("td")', row)
    ...         if cells:
    ...             title, required, deprecated = cells
    ...             print '%s | %s | %s' % (
    ...                 title.text,
    ...                 print_checkbox(browser, required),
    ...                 print_checkbox(browser, deprecated))

Log in as manager:

    >>> manager = browsers.manager
    >>> manager.ui.login('manager', 'schooltool')

Set up persons:

    >>> manager.ui.person.add('Jeffrey', 'Elkner', 'jeffrey', 'pwd')
    >>> manager.ui.person.add('Camila', 'Cerna', 'camila', 'pwd')
    >>> manager.ui.person.add('Mario',  'Tejada', 'mario', 'pwd')

Set up a section:

    >>> manager.ui.schoolyear.add('2013', '2013-01-01', '2013-12-31')
    >>> manager.ui.term.add('2013', '2013', '2013-01-01', '2013-12-31')
    >>> manager.ui.course.add('2013', 'Programming', course_id='PRO')
    >>> manager.ui.section.add('2013', '2013', 'Programming')
    >>> manager.ui.section.instructors.add('2013', '2013', 'Programming (1)',
    ...                                    ['jeffrey'])    
    >>> manager.ui.section.students.add('2013', '2013', 'Programming (1)',
    ...                                 ['camila'])

Set up skills:

    >>> manager.ui.layer.add('Course')
    >>> manager.ui.node.add('Programming', label='PRO')

    >>> manager.ui.skillset.add('Python Environment', '01')
    >>> manager.ui.skillset.add('Data Types, Statements, and Expressions', '02')
    >>> manager.ui.skillset.add('Errors', '03')

    >>> manager.ui.skill.add(
    ...     'Python Environment',
    ...     'Use the Python shell for interactive evaluation',
    ...     '01')
    >>> manager.ui.skill.add(
    ...     'Python Environment',
    ...     'Make Python scripts with a text editor',
    ...     '02',
    ...     required=False)
    >>> manager.ui.skill.add(
    ...     'Data Types, Statements, and Expressions',
    ...     'Recognize int, float, str, list, tuple, and dict.',
    ...     '03')
    >>> manager.ui.skill.add(
    ...     'Data Types, Statements, and Expressions',
    ...     'Use type(...) to determine the data type of a given value.',
    ...     '04')
    >>> manager.ui.skill.add(
    ...     'Data Types, Statements, and Expressions',
    ...     'Use assignment statements to assign names (variables) to values.',
    ...     '05')
    >>> manager.ui.skill.add(
    ...     'Data Types, Statements, and Expressions',
    ...     'Use the input function to read user input.',
    ...     '06')
    >>> manager.ui.skill.add(
    ...     'Data Types, Statements, and Expressions',
    ...     'Define keyword and recognize keywords in Python.',
    ...     '07')
    >>> manager.ui.skill.add(
    ...     'Data Types, Statements, and Expressions',
    ...     'Create legal variable names and recognize illegal ones.',
    ...     '08',
    ...     required=False)
    >>> manager.ui.skill.add(
    ...     'Errors',
    ...     'Recognize and differentiate among errors.',
    ...     '09')
    >>> manager.ui.skill.add(
    ...     'Errors',
    ...     'Read and interpret stack traceback messages.',
    ...     '10')

    >>> manager.query.link('Search').click()
    >>> manager.query.button('Search').click()
    >>> manager.query.link('Programming').click()

    >>> sel = '//h2[contains(@class, "ui-accordion-header")]'
    >>> accordion_headers = manager.query_all.xpath(sel)
    >>> sel = 'div.ui-accordion-content'
    >>> accordion_contents = manager.query_all.css(sel)
    >>> information_accordion_content = accordion_contents[0]
    >>> skillsets_accordion_header = accordion_headers[4]
    >>> skillsets_accordion_header.click()
    >>> skillsets_accordion_content = accordion_contents[4]
    >>> manager.wait_no(information_accordion_content.is_displayed)
    >>> sel = '//a[@title="Edit skill sets"]'
    >>> manager.query.xpath(sel).click()
    >>> manager.query.id('form-buttons-add').click()
    >>> manager.query.link('Done').click()

    >>> sel = '//h2[contains(@class, "ui-accordion-header")]'
    >>> accordion_headers = manager.query_all.xpath(sel)
    >>> sel = 'div.ui-accordion-content'
    >>> accordion_contents = manager.query_all.css(sel)
    >>> information_accordion_content = accordion_contents[0]
    >>> layers_accordion_header = accordion_headers[3]
    >>> layers_accordion_header.click()
    >>> layers_accordion_content = accordion_contents[3]
    >>> manager.wait_no(information_accordion_content.is_displayed)
    >>> sel = '//a[@title="Edit layers"]'
    >>> manager.query.xpath(sel).click()
    >>> manager.query.id('form-buttons-add').click()

Assign the skills to the course:

    >>> manager.query.link('School').click()
    >>> manager.query.link('Courses').click()
    >>> manager.query.link('Batch Assign Skills').click()
    >>> manager.query.name('course_attr').ui.set_value('Course ID')
    >>> manager.query.name('layer').ui.set_value('Course')
    >>> manager.query.name('node_attr').ui.set_value('Label')
    >>> manager.query.name('SEARCH_BUTTON').click()
    >>> manager.query.name('ASSIGN_BUTTON').click()

Check the course skills:

    >>> manager.query.link('Programming').click()
    >>> manager.query.link('Skills').click()
    >>> manager.query.link('Set Required / Deprecated').click()
    >>> course_skills_url = manager.url
    >>> print_skills_table(manager)
    01: Use the Python shell for interactive evaluation | [X] | [ ]
    02: Make Python scripts with a text editor | [ ] | [ ]
    03: Recognize int, float, str, list, tuple, and dict. | [X] | [ ]
    04: Use type(...) to determine the data type of a given value. | [X] | [ ]
    05: Use assignment statements to assign names (variables) to values. | [X] | [ ]
    06: Use the input function to read user input. | [X] | [ ]
    07: Define keyword and recognize keywords in Python. | [X] | [ ]
    08: Create legal variable names and recognize illegal ones. | [ ] | [ ]
    09: Recognize and differentiate among errors. | [X] | [ ]
    10: Read and interpret stack traceback messages. | [X] | [ ]

Log in as instructor:

    >>> teacher = browsers.teacher
    >>> teacher.ui.login('jeffrey', 'pwd')
    >>> teacher.query.link('CanDo').click()

Set a score and print the gradebook:

    >>> teacher.ui.gradebook.worksheet.score('Camila Cerna', '01', '3')
    >>> teacher.query.name('UPDATE_SUBMIT').click()

    >>> sel = 'a[title="01: Python Environment"]'
    >>> link = teacher.query.css(sel)
    >>> # XXX: fix this, use clicks instead of open
    >>> teacher.open(link.get_attribute('href'))
    >>> teacher.ui.gradebook.worksheet.pprint()
    +--------------------------+---------------------------------------------+------------+
    | *01: Python Environment* | 02: Data Types, Statements, and Expressions | 03: Errors |
    +--------------------------+---------------------------------------------+------------+
    +-----------+------------+----+----+
    | Last Name | First Name | 01 | 02 |
    |           |            | 4  | 4  |
    +-----------+------------+----+----+
    | Cerna     | Camila     | 3  |    |
    +-----------+------------+----+----+

Now, let's deprecate the Python Environment skillset:

    >>> manager.query.link('School').click()
    >>> manager.query.link('Skills').click()
    >>> manager.query.link('Deprecate Skills').click()
    >>> manager.query.id('SEARCH').ui.set_value('Python Environment')
    >>> selector = '#retire-ajax-view-container-retire- table'
    >>> table = manager.query.css(selector)
    >>> manager.query.name('SEARCH_BUTTON').click()
    >>> manager.wait(lambda: table.expired)
    >>> manager.query.css('th.active input[type="checkbox"]').click()
    >>> manager.query.name('SAVE_RESULTS').click()

    >>> dialog = manager.query.css('.ui-dialog')
    >>> print dialog.query.css('.ui-dialog-title').text
    Changes saved

Let's print the gradebook again:

    >>> sel = 'a[title="01: Python Environment"]'
    >>> link = teacher.query.css(sel)
    >>> # XXX: fix this, use clicks instead of open
    >>> teacher.open(link.get_attribute('href'))
    >>> teacher.ui.gradebook.worksheet.pprint()
    +--------------------------+---------------------------------------------+------------+
    | *01: Python Environment* | 02: Data Types, Statements, and Expressions | 03: Errors |
    +--------------------------+---------------------------------------------+------------+
    +-----------+------------+----+----+
    | Last Name | First Name | 01 | 02 |
    |           |            | 4  | 4  |
    +-----------+------------+----+----+
    | Cerna     | Camila     | 3  |    |
    +-----------+------------+----+----+
