Tests for Zambia levels and grades
====================================

A manager logs in and clicks 'Manage'

    >>> manager = Browser('manager', 'schooltool')
    >>> manager.getLink('Manage').click()

    >>> def managerQuery(query):
    ...     print '\n'.join(
    ...         [s.strip()
    ...          for s in analyze.queryHTML(query, manager.contents)])

He doesn't see a link to Levels in the manage page.

    >>> managerQuery("id('content-body')//a[@class='navigation_header']")
    <a class="navigation_header" href="http://localhost/schoolyears">School Years</a>

He creates a new school year:

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

Schoolyears have their one default term.

    >>> managerQuery("id('content-body')//form//a")
    <a href="http://localhost/schoolyears/2009-2010/20092010">2009-2010</a>
            (Sep 1, 2009
            &#8212;
            Jul 15, 2010)

Manager registers a new class (student group).

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Classes').click()

    >>> manager.getLink('New Class').click()

    >>> managerQuery("id('content-body')//form//label")
    <label for="form-widgets-level">
      <span>Level</span>
      <span class="required">*</span>
    </label>
    <label for="form-widgets-title">
      <span>Full Title</span>
      <span class="required">*</span>
    </label>

    >>> manager.getControl('Level').displayValue = ['11']
    >>> manager.getControl('Full Title').value = '11G'
    >>> manager.getControl('Add').click()

Default levels and courses were created for the new school year.  The
newly added class is listed with respective courses.

    >>> manager.getLink('Manage').click()

    >>> managerQuery("id('content-body')//a[@class='navigation_header']")
    <BLANKLINE>
    ...
    <a class="navigation_header"
       href="http://localhost/schoolyears/2009-2010/zambia-levels">Levels</a>

    >>> manager.getLink('Levels').click()

    >>> query = ("id('content-body')//h2"
    ...          "|id('content-body')//table//tr/th"
    ...          "|id('content-body')//table//tr/td")
    >>> result = [s.strip() for s in analyze.queryHTML(query, manager.contents)]
    >>> print '\n'.join(result)
    <BLANKLINE>
    ...
    <h2>Grade 11</h2>
    <th class="first">Subject</th>
    <th>Credits</th>
    <th colspan="4">Classes</th>
    <td>Biology</td>
    <td>100</td>
    <td>
      <a href="http://localhost/schoolyears/2009-2010/.../sections/...">
         <span>11A</span>
      </a>
    </td>
    ...
    <td>
      <a href="http://localhost/schoolyears/2009-2010/.../sections/...">
         <span>11G</span>
      </a>
    </td>
    <td>Chimistry</td>
    <td>100</td>
    ...
    <td>Earth and Environmental Studies</td>
    <td>100</td>
    ...

Links follow to the sections themselves.

    >>> manager.getLink('11G', index=0).click()

    >>> biology_11g_url = manager.url

    >>> managerQuery("id('content-header')//h1")
    <h1>
      Section of
      <a href=".../courses...biology">Biology</a>
          -- Biology
          for
          <a href="...2009-2010...">2009-2010</a> of
          <a href="...2009-2010">2009-2010</a>
    </h1>

We see no students enrolled to the section.

    >>> managerQuery("id('section-view')//table/tbody")
    <tbody></tbody>

When the student is enrolled to an auto-created group, he is also
enrolled to such sections.

    >>> from schooltool.zambia.person.browser.ftests import addStudent
    >>> addStudent('Mortimer', 'Smith')

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('School Years').click()
    >>> manager.getLink('2009-2010').click()
    >>> manager.getLink('Groups').click()
    >>> manager.getLink('11G').click()
    >>> manager.getLink('edit members').click()

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

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Levels').click()
    >>> manager.getLink('11G', index=0).click()
    >>> managerQuery("id('section-view')//table/tbody")
    <tbody>
      <tr class="odd"><td>
          <a href="http://localhost/persons/BasicPerson">Mortimer</a>
        </td>
        <td>
          <a href="http://localhost/persons/BasicPerson">Smith</a>
        </td>
      </tr>
    </tbody>

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Levels').click()
    >>> manager.getLink('11G', index=1).click()
    >>> managerQuery("id('content-header')//h1")
    <h1>
      Section of
      <a href=".../2009-2010/courses...chimistry">Chimistry</a>
          -- Chimistry
          for
          <a href=".../2009-2010/...">2009-2010</a> of
          <a href=".../2009-2010">2009-2010</a>
    </h1>

    >>> managerQuery("id('section-view')//table/tbody")
    <tbody>
      <tr class="odd"><td>
          <a href="http://localhost/persons/BasicPerson">Mortimer</a>
        </td>
        <td>
          <a href="http://localhost/persons/BasicPerson">Smith</a>
        </td>
      </tr>
    </tbody>
