Tests for automatic linking of sections
---------------------------------------

This file tests the automatic linking of sections that have the same ID
defined by the user between the terms:

    >>> browser = Browser('manager', 'schooltool')
    >>> browser.getLink('Manage').click()
    >>> browser.getLink('XLS Import').click()
    >>> import pkg_resources
    >>> browser.getControl('XLS File').add_file(
    ...     pkg_resources.resource_stream('schooltool.export.ftests', 'linked_sections.xls'),
    ...     'application/excel',
    ...     'sample_data.xls')
    >>> browser.getControl('Submit').click()
    >>> browser.queryHTML("//p[@class='error']")
    []

We see that each term has three sections, all with ids matching a section in
another term.  However, as we will see, if the cell after the 'Link?' heading
is not set to 'y' or 'yes', or the matching section is not in an adjacent term,
then the section will not end up linked.

    >>> browser.getLink('2006-2007').click()
    >>> browser.getLink('Fall').click()
    >>> browser.getLink('Sections').click()
    >>> browser.printQuery('//table[@class="container"]//tr/td[3]/a/@href')
    http://localhost/schoolyears/2006-2007/fall/sections/Art_1
    http://localhost/schoolyears/2006-2007/fall/sections/Art_2
    http://localhost/schoolyears/2006-2007/fall/sections/Art_4

    >>> browser.getLink('2006-2007').click()
    >>> browser.getLink('Winter').click()
    >>> browser.getLink('Sections').click()
    >>> browser.printQuery('//table[@class="container"]//tr/td[3]/a/@href')
    http://localhost/schoolyears/2006-2007/winter/sections/Art_1
    http://localhost/schoolyears/2006-2007/winter/sections/Art_2
    http://localhost/schoolyears/2006-2007/winter/sections/Art_3

    >>> browser.getLink('2006-2007').click()
    >>> browser.getLink('Spring').click()
    >>> browser.getLink('Sections').click()
    >>> browser.printQuery('//table[@class="container"]//tr/td[3]/a/@href')
    http://localhost/schoolyears/2006-2007/spring/sections/Art_1
    http://localhost/schoolyears/2006-2007/spring/sections/Art_3
    http://localhost/schoolyears/2006-2007/spring/sections/Art_4

We'll show all the linked sections for each term, starting with Fall.  We see
the ones with matching ids in other terms are linked, except in the case of
the Art_3 section which was not marked to link in either term (see 'Link?'
heading in linked_sections.xls) and Art_4 which is found in two terms that are
not adjacent.

    >>> browser.getLink('2006-2007').click()
    >>> browser.getLink('Fall').click()
    >>> browser.getLink('Sections').click()
    >>> browser.getLink('Art_1').click()
    >>> browser.getLink('Linked sections').click()

    >>> browser.printQuery('id("content-body")//tbody/tr/td//div[1]/a/@href')
    http://localhost/schoolyears/2006-2007/fall/sections/Art_1
    http://localhost/schoolyears/2006-2007/winter/sections/Art_1
    http://localhost/schoolyears/2006-2007/spring/sections/Art_1

    >>> browser.getLink('2006-2007').click()
    >>> browser.getLink('Fall').click()
    >>> browser.getLink('Sections').click()
    >>> browser.getLink('Art_2').click()
    >>> browser.getLink('Linked sections').click()

    >>> browser.printQuery('id("content-body")//tbody/tr/td//div[1]/a/@href')
    http://localhost/schoolyears/2006-2007/fall/sections/Art_2
    http://localhost/schoolyears/2006-2007/winter/sections/Art_2

    >>> browser.getLink('2006-2007').click()
    >>> browser.getLink('Fall').click()
    >>> browser.getLink('Sections').click()
    >>> browser.getLink('Art_4').click()
    >>> browser.getLink('Linked sections').click()

    >>> browser.printQuery('id("content-body")//tbody/tr/td//div[1]/a/@href')
    http://localhost/schoolyears/2006-2007/fall/sections/Art_4

Now we'll do the same for the Winter sections.

    >>> browser.getLink('2006-2007').click()
    >>> browser.getLink('Winter').click()
    >>> browser.getLink('Sections').click()
    >>> browser.getLink('Art_1').click()
    >>> browser.getLink('Linked sections').click()

    >>> browser.printQuery('id("content-body")//tbody/tr/td//div[1]/a/@href')
    http://localhost/schoolyears/2006-2007/fall/sections/Art_1
    http://localhost/schoolyears/2006-2007/winter/sections/Art_1
    http://localhost/schoolyears/2006-2007/spring/sections/Art_1

    >>> browser.getLink('2006-2007').click()
    >>> browser.getLink('Winter').click()
    >>> browser.getLink('Sections').click()
    >>> browser.getLink('Art_2').click()
    >>> browser.getLink('Linked sections').click()

    >>> browser.printQuery('id("content-body")//tbody/tr/td//div[1]/a/@href')
    http://localhost/schoolyears/2006-2007/fall/sections/Art_2
    http://localhost/schoolyears/2006-2007/winter/sections/Art_2

    >>> browser.getLink('2006-2007').click()
    >>> browser.getLink('Winter').click()
    >>> browser.getLink('Sections').click()
    >>> browser.getLink('Art_3').click()
    >>> browser.getLink('Linked sections').click()

    >>> browser.printQuery('id("content-body")//tbody/tr/td//div[1]/a/@href')
    http://localhost/schoolyears/2006-2007/winter/sections/Art_3

Finally the same for the Spring sections.

    >>> browser.getLink('2006-2007').click()
    >>> browser.getLink('Spring').click()
    >>> browser.getLink('Sections').click()
    >>> browser.getLink('Art_1').click()
    >>> browser.getLink('Linked sections').click()

    >>> browser.printQuery('id("content-body")//tbody/tr/td//div[1]/a/@href')
    http://localhost/schoolyears/2006-2007/fall/sections/Art_1
    http://localhost/schoolyears/2006-2007/winter/sections/Art_1
    http://localhost/schoolyears/2006-2007/spring/sections/Art_1

    >>> browser.getLink('2006-2007').click()
    >>> browser.getLink('Spring').click()
    >>> browser.getLink('Sections').click()
    >>> browser.getLink('Art_3').click()
    >>> browser.getLink('Linked sections').click()

    >>> browser.printQuery('id("content-body")//tbody/tr/td//div[1]/a/@href')
    http://localhost/schoolyears/2006-2007/spring/sections/Art_3

    >>> browser.getLink('2006-2007').click()
    >>> browser.getLink('Spring').click()
    >>> browser.getLink('Sections').click()
    >>> browser.getLink('Art_4').click()
    >>> browser.getLink('Linked sections').click()

    >>> browser.printQuery('id("content-body")//tbody/tr/td//div[1]/a/@href')
    http://localhost/schoolyears/2006-2007/spring/sections/Art_4

Now let's try reimporting the same file:

    >>> browser.getLink('Manage').click()
    >>> browser.getLink('XLS Import').click()
    >>> browser.getControl('XLS File').add_file(
    ...     pkg_resources.resource_stream('schooltool.export.ftests', 'linked_sections.xls'),
    ...     'application/excel',
    ...     'sample_data.xls')
    >>> browser.getControl('Submit').click()
    >>> browser.queryHTML("//p[@class='error']")
    []

No problem.  The same sections are there.

    >>> browser.getLink('2006-2007').click()
    >>> browser.getLink('Fall').click()
    >>> browser.getLink('Sections').click()
    >>> browser.printQuery('//table[@class="container"]//tr/td[3]/a/@href')
    http://localhost/schoolyears/2006-2007/fall/sections/Art_1
    http://localhost/schoolyears/2006-2007/fall/sections/Art_2
    http://localhost/schoolyears/2006-2007/fall/sections/Art_4

    >>> browser.getLink('2006-2007').click()
    >>> browser.getLink('Winter').click()
    >>> browser.getLink('Sections').click()
    >>> browser.printQuery('//table[@class="container"]//tr/td[3]/a/@href')
    http://localhost/schoolyears/2006-2007/winter/sections/Art_1
    http://localhost/schoolyears/2006-2007/winter/sections/Art_2
    http://localhost/schoolyears/2006-2007/winter/sections/Art_3

    >>> browser.getLink('2006-2007').click()
    >>> browser.getLink('Spring').click()
    >>> browser.getLink('Sections').click()
    >>> browser.printQuery('//table[@class="container"]//tr/td[3]/a/@href')
    http://localhost/schoolyears/2006-2007/spring/sections/Art_1
    http://localhost/schoolyears/2006-2007/spring/sections/Art_3
    http://localhost/schoolyears/2006-2007/spring/sections/Art_4

Just to be sure, we'll make sure the first one is linked to the other terms.

    >>> browser.getLink('2006-2007').click()
    >>> browser.getLink('Fall').click()
    >>> browser.getLink('Sections').click()
    >>> browser.getLink('Art_1').click()
    >>> browser.getLink('Linked sections').click()

    >>> browser.printQuery('id("content-body")//tbody/tr/td//div[1]/a/@href')
    http://localhost/schoolyears/2006-2007/fall/sections/Art_1
    http://localhost/schoolyears/2006-2007/winter/sections/Art_1
    http://localhost/schoolyears/2006-2007/spring/sections/Art_1

