Timetabling in SchoolTool
=========================

This functional doctest demonstrates and tests SchoolTool's timetable
browser views.

We do most of the fixture setup through ReSTive views for now.  A lot of the
code has been copied from rest/composite-timetables.txt.

Overview
--------

1. Set up 1 Term, 1 Schema, a User and a a couple of Groups
2. Add the User to both Groups
3. Check composite Timetable for the User

Prologue
--------

    >>> manager = Browser('manager', 'schooltool')

Add a schoolyear and a term:

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('School Years').click()
    >>> manager.getLink('New School Year').click()
    >>> manager.getControl('Title').value = '2003'
    >>> manager.getControl('First day').value = '2003-09-01'
    >>> manager.getControl('Last day').value = '2004-07-31'
    >>> manager.getControl('Add').click()

    >>> manager.getLink("Add a new term").click()
    >>> manager.getControl("Title").value = "2005 Fall"
    >>> manager.getControl("Start date").value = "2003-09-01"
    >>> manager.getControl("End date").value = "2003-09-07"
    >>> manager.getControl("Next").click()

    >>> manager.getControl("Sunday").click()
    >>> manager.getControl("Wednesday").click()
    >>> manager.getControl("Add term").click()

Add Schema:

    >>> from schooltool.app.browser.ftests import setup
    >>> setup.addDefaultSchoolTimetable(schoolyear='2003')

Add 2 groups:

    >>> manager.getLink('2003').click()
    >>> manager.getLink('Groups').click()
    >>> manager.getLink('New Group').click()
    >>> manager.getControl('Title').value = "Boys"
    >>> manager.getControl('Add').click()

    >>> manager.getLink('New Group').click()
    >>> manager.getControl('Title').value = "Guys"
    >>> manager.getControl('Add').click()

And create a person so that we can fool around with his calendar:

    >>> setup.addPerson('John', 'john', 'pwd', ['boys', 'guys'])
    >>> setup.addPerson('Billie', 'billie', 'pwd', ['boys'])
    >>> setup.addPerson('Bob', 'bob', 'pwd', ['guys'])

Add a course:

    >>> setup.addCourse('Birding', '2003')

And a couple of sections:

    >>> setup.addSection('Birding', '2003', '2005 Fall', title="Birding1")
    >>> setup.addSection('Birding', '2003', '2005 Fall', title="Birding2")

Let's add guys and boys to different sections:

    >>> from lxml import etree
    >>> def clickCheckboxes(browser, prefix='', value=True):
    ...     doc = etree.HTML(browser.contents)
    ...     names = doc.xpath(
    ...         '//input[@type="checkbox" and'
    ...         '        starts-with(./@name, "%s")]/@name' % prefix)
    ...     for name in names:
    ...         browser.getControl(name=name).value = value
    ...         print '[%s]' % (value and 'V' or ' '), name

    >>> manager.getLink('2003').click()
    >>> manager.getLink('Courses').click()
    >>> manager.getLink('Birding').click()
    >>> manager.getLink('Birding1').click()
    >>> manager.getLink('edit individuals').click()
    >>> manager.getControl(name='SEARCH_GROUP').displayValue=['Guys']
    >>> manager.getControl('Find Now').click()
    >>> clickCheckboxes(manager, prefix='add_item')
    [V] add_item.bob
    [V] add_item.john

    >>> manager.getControl('Add').click()

    >>> manager.getLink('2003').click()
    >>> manager.getLink('Courses').click()
    >>> manager.getLink('Birding').click()
    >>> manager.getLink('Birding2').click()
    >>> manager.getLink('edit individuals').click()
    >>> manager.getControl(name='SEARCH_GROUP').displayValue=['Boys']
    >>> manager.getControl('Find Now').click()
    >>> clickCheckboxes(manager, prefix='add_item')
    [V] add_item.billie
    [V] add_item.john

    >>> manager.getControl('Add').click()

Add section timetables:

    >>> manager.getLink('2003').click()
    >>> manager.getLink('Courses').click()
    >>> manager.getLink('Birding').click()
    >>> manager.getLink('Birding1').click()
    >>> manager.getLink('Timetables').click()
    >>> manager.getLink('Add Timetable').click()
    >>> manager.getControl('Add').click()

    >>> manager.getLink('2005-fall.schema1').click()
    >>> manager.getControl('C').click()
    >>> manager.getControl('Save').click()

    >>> manager.getLink('2003').click()
    >>> manager.getLink('Courses').click()
    >>> manager.getLink('Birding').click()
    >>> manager.getLink('Birding2').click()
    >>> manager.getLink('Timetables').click()
    >>> manager.getLink('Add Timetable').click()
    >>> manager.getControl('Add').click()

    >>> manager.getLink('2005-fall.schema1').click()
    >>> manager.getControl('D').click()
    >>> manager.getControl('Save').click()

Finally, we're done with setup.

Rendering views
---------------

Let's look at John's composite calendar:

    >>> john = Browser()
    >>> john.addHeader('Authorization', 'Basic john:pwd')
    >>> john.open('http://localhost/persons/john/calendar/2003-09-02')
    >>> john.getControl(name='my_timetable').value = True
    >>> john.getControl('Apply').click()

    >>> print john.contents
    <BLANKLINE>
    ...
    Birding
    ...
    Birding
    ...


Epilogue
--------

 vim: ft=rest
