Journal tab
===========

We'll test that the Journal tab redirect teachers only to sections
they teach.

Helper:

    >>> def print_section_navigator(browser):
    ...     sel = 'select[name="currentSection"] option'
    ...     for option in browser.query_all.css(sel):
    ...         print ['%s', '*%s*'][option.is_selected()] % option.text

Log in as manager:

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

Set up persons:

    >>> manager.ui.person.add('Tom', 'Hoffman', 'tom', 'pwd')
    >>> manager.ui.person.add('Jeffrey', 'Elkner', 'jeffrey', 'pwd')
    >>> manager.ui.person.add('Camila', 'Cerna', 'camila', 'pwd')
    >>> manager.ui.person.add('Mario', 'Tejada', 'mario', 'pwd')
    >>> manager.ui.person.add('Nestor', 'Guzman', 'nestor', 'pwd')
    >>> manager.ui.person.add('Liliana', 'Vividor', 'liliana', 'pwd')
    >>> manager.ui.person.add('German', 'Tejada', 'german', 'pwd')

Set up some courses with a section each:

    >>> manager.ui.schoolyear.add('2013', '2013-01-01', '2013-12-31')
    >>> manager.ui.term.add('2013', 'Year', '2013-01-01', '2013-12-31')

    >>> manager.ui.course.add('2013', 'Math')
    >>> manager.ui.course.add('2013', 'Physics')
    >>> manager.ui.course.add('2013', 'Algebra')

    >>> manager.ui.course.add('2013', 'Baseball')
    >>> manager.ui.course.add('2013', 'Soccer')
    >>> manager.ui.course.add('2013', 'Swimming')

    >>> manager.ui.section.add('2013', 'Year', 'Algebra')
    >>> manager.ui.section.add('2013', 'Year', 'Math')
    >>> manager.ui.section.add('2013', 'Year', 'Physics')
    >>> manager.ui.section.add('2013', 'Year', 'Baseball')
    >>> manager.ui.section.add('2013', 'Year', 'Soccer')
    >>> manager.ui.section.add('2013', 'Year', 'Swimming')

    >>> for section in ['Algebra (1)', 'Math (2)', 'Physics (3)']:
    ...     manager.ui.section.instructors.add('2013', 'Year', section,
    ...                                        ['jeffrey'])
    ...     manager.ui.section.students.add('2013', 'Year', section,
    ...                                     ['camila', 'mario', 'nestor'])

    >>> for section in ['Baseball (4)', 'Soccer (5)', 'Swimming (6)']:
    ...     manager.ui.section.instructors.add('2013', 'Year', section,
    ...                                        ['tom'])
    ...     manager.ui.section.students.add('2013', 'Year', section,
    ...                                     ['liliana', 'german'])

Add a timetable:

    >>> manager.query.link('School').click()
    >>> manager.query.link('Timetables').click()
    >>> manager.query.link('Timetable').click()
    >>> manager.query.button('Next').click()
    >>> manager.query.button('Days of the week').click()
    >>> manager.query.button('Same time each day').click()
    >>> times = '9:30-10:25\n10:30-11:25\n11:30-12:25'
    >>> manager.query.id('field.times').clear()
    >>> manager.query.id('field.times').ui.set_value(times)
    >>> manager.query.button('Next').click()
    >>> manager.query.button('Designated by time').click()
    >>> manager.query.button('No').click()

Set a schedule for some sections:

    >>> sel = '//div[contains(@class, "sidebar")]//a[text()="Schedule"]'
    >>> for i, section in enumerate(['Algebra (1)', 'Math (2)', 'Baseball (4)']):
    ...     manager.ui.section.go('2013', 'Year', section)
    ...     manager.query.link('Schedule').click()
    ...     manager.query.xpath(sel).click()
    ...     manager.query.button('Submit').click()
    ...     period = 'Period-'
    ...     if i > 0:
    ...         period = 'Period-%d-' % (i + 1)
    ...     manager.query.xpath('//input[@name="period.0-.%s"]' % period).click()
    ...     manager.query.xpath('//input[@name="period.1-.%s"]' % period).click()
    ...     manager.query.xpath('//input[@name="period.2-.%s"]' % period).click()
    ...     manager.query.xpath('//input[@name="period.3-.%s"]' % period).click()
    ...     manager.query.xpath('//input[@name="period.4-.%s"]' % period).click()
    ...     manager.query.button('Save').click()

Log in as teacher:

    >>> teacher = browsers.teacher
    >>> teacher.ui.login('jeffrey', 'pwd')

Click the Journal tab:

    >>> teacher.query.link('Journal').click()

List the sections navigator:

    >>> print_section_navigator(teacher)
    *Algebra (1)*
    Math (2)
    Physics (3)

Switch to the Math (2) section and list the sections navigator again:

    >>> navigator = teacher.query_all.css('.refine .navigator')[0]
    >>> page = teacher.query.tag('html')
    >>> navigator.ui.set_value('Math (2)')
    >>> teacher.wait(lambda: page.expired)
    >>> print_section_navigator(teacher)
    Algebra (1)
    *Math (2)*
    Physics (3)

Go to Home page and back to the Journal tab. Current section should
be Math (2):

    >>> teacher.query.link('Home').click()
    >>> teacher.query.link('Journal').click()
    >>> print_section_navigator(teacher)
    Algebra (1)
    *Math (2)*
    Physics (3)

Add teacher to the School Administrators group:

    >>> manager.ui.group.members.add('2013', 'School Administrators',
    ...                              ['jeffrey'])

This gives the teacher ability to see other teachers' journals:

    >>> teacher.ui.section.go('2013', 'Year', 'Baseball (4)')
    >>> sel = '//div[contains(@class, "sidebar")]//a[text()="Journal"]'
    >>> teacher.query.xpath(sel).click()
    >>> print teacher.url
    http://localhost/schoolyears/2013/year/sections/4/journal

Go to Home page and back to the Journal tab. Again, the current
section should be Math (2), not Baseball (4):

    >>> teacher.query.link('Home').click()
    >>> teacher.query.link('Journal').click()
    >>> print_section_navigator(teacher)
    Algebra (1)
    *Math (2)*
    Physics (3)
