Functional doctest for SchoolTool
=================================

This is a functional doctest for schooltool.  To find out more about
functional doctests, read http://docs.zope.org/zope.testbrowser/

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

The SchoolTool version is displayed on the page:

    >>> import schooltool.common
    >>> str(manager.contents).count(schooltool.common.get_version()) > 0
    True

Let's create a person so that we can fool around with his calendar:

    >>> from schooltool.basicperson.browser.ftests.setup import addPerson
    >>> addPerson('Frog', 'Prince', 'frog', 'pwd')

Let's create a second person so that we can test access control.

    >>> addPerson('Toad', 'Toad', 'toad', 'doat')

Now we log in as the frog:

    >>> frog = Browser()
    >>> frog.open('http://localhost/')
    >>> frog.getLink('Log In').click()
    >>> frog.getControl('Username').value = 'frog'
    >>> frog.getControl('Password').value = 'pwd'
    >>> frog.getControl('Log in').click()

We should be redirected from the index page to the calendar

    >>> frog.url
    'http://localhost/persons/frog/calendar'

And we should have permission to see the calendar:

    >>> frog.headers['status']
    '200 Ok'

The daily view should be the default for a person's calendar:

    >>> frog.getLink('Calendar').click()
    >>> 'calendar-view-day' in frog.contents
    True

Let's make sure that we can see the SchoolTool preferences page:

    >>> frog.getLink('Frog').click()
    >>> frog.getLink('Edit Preferences').click()
    >>> 'cal_periods' in frog.contents
    True

But you have to log in to see persons, groups, and other locations:

    >>> anonymous = Browser()
    >>> anonymous.handleErrors = True
    >>> anonymous.open('http://localhost/persons')
    >>> print anonymous.url
    http://localhost/auth/@@login.html?forbidden=yes&nexturl=...

    >>> anonymous.open('http://localhost/resources')
    >>> print anonymous.url
    http://localhost/auth/@@login.html?forbidden=yes&nexturl=...

This is a school, so we should add a school year

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

and a term

    >>> manager.getLink('Add a new term').click()
    >>> manager.getControl('Title').value = 'Term 1'
    >>> manager.getControl('Start date').value = '2007-07-01'
    >>> manager.getControl('End date').value = '2007-12-15'
    >>> manager.getControl('Next').click()
    >>> manager.getControl('Saturday').click()
    >>> manager.getControl('Sunday').click()
    >>> manager.getControl('Add term').click()

then a  group:

    >>> manager.getLink('2007').click()
    >>> manager.getLink('Groups').click()
    >>> manager.getLink('New Group').click()

    >>> manager.getControl('Title').value = 'Animals'
    >>> manager.getControl('Add').click()

    >>> 'Animals' in manager.contents
    True

Now let's add a course:

    >>> manager.getLink('2007').click()
    >>> manager.getLink('Courses').click()
    >>> manager.getLink('Add Course').click()
    >>> manager.getControl('Title').value = 'History'
    >>> manager.getControl('Add').click()

    >>> 'History' in manager.contents
    True

Let's see that course:

    >>> manager.getLink('History').click()
    >>> 'History' in manager.contents
    True

Lets create a section to add to that course:

    >>> from schooltool.app.browser.ftests import setup
    >>> setup.addSection('History', '2007', 'Term 1')

Looking at the section:

    >>> manager.reload()
    >>> manager.getLink('(1)').click()
    >>> manager.printQuery("id('content-header')/h1")
    <h1>
      Section of
      <a href="http://localhost/schoolyears/2007/courses/history">History</a>
      -- History (1)
      for
      <a href="http://localhost/schoolyears/2007/term-1">Term 1</a> of
      <a href="http://localhost/schoolyears/2007">2007</a>
    </h1>

Frog can't see the section's calendar by default

    >>> frog.handleErrors = True
    >>> frog.open('http://localhost/schoolyears/2007/term-1/sections/1/calendar')
    >>> print frog.url
    http://localhost/auth/@@login.html?forbidden=yes&nexturl=...

Frog's overlay portlet has just his own calendar and application
calendar:

    >>> frog.getLink('Calendar').click()
    >>> def print_portlet(contents):
    ...     print analyze.queryHTML(
    ...         'id("portlet-calendar-overlay")//table[@class="overlays"]', contents)[0]

    >>> print_portlet(frog.contents)
    <table class="overlays">
      <tr style="background: #9db8d2"><td><input type="checkbox" checked="checked" disabled="disabled" /></td>
            <td style="width: 100%">My Calendar</td>
            <td></td>
          </tr>
      <tr style="background: #e0b6af"><td><input type="checkbox" name="overlay:list" checked="checked" value="/" /></td>
            <td style="width: 100%">Your School</td>
                <td><a class="go" style="..." href="http://localhost/calendar">&#160;</a></td>
        </tr>
    </table>

As does Toad's:

    >>> toad = Browser('toad', 'doat')

    >>> toad.getLink('Calendar').click()
    >>> print_portlet(toad.contents)
    <table class="overlays">
      <tr style="background: #9db8d2"><td><input type="checkbox" checked="checked" disabled="disabled" /></td>
            <td style="width: 100%">My Calendar</td>
            <td></td>
          </tr>
      <tr style="background: #e0b6af"><td><input type="checkbox" name="overlay:list" checked="checked" value="/" /></td>
            <td style="width: 100%">Your School</td>
            <td><a class="go" style="..." href="http://localhost/calendar">...</a></td>
        </tr>
    </table>

Adding a teacher:

    >>> manager.getLink('edit instructors').click()
    >>> manager.getControl(name='add_item.frog').value = True
    >>> manager.getControl('Add').click()

    >>> print manager.contents
    <BLANKLINE>
    ...
      <legend>Current Instructors</legend>
    ...
         <label for="remove_item.frog">Frog</label>
    ...
      <legend>Available Instructors</legend>
    ...

Now Frog is in the Instructors div

    >>> manager.getControl('OK').click()
    >>> manager.printQuery("id('content-body')//div[@class='info-block'][2]/h3")
    <h3>Instructors</h3>
    >>> manager.printQuery("id('content-body')//div[@class='info-block'][2]/ul[1]//a")
    <a href="http://localhost/persons/frog">Frog Prince</a>

Toad should still be able to see the course view even though it is
showing bits of frog's personal information as well as the section
list:

    >>> toad.open('http://localhost/schoolyears/2007/courses/history')
    >>> print toad.url
    http://localhost/schoolyears/2007/courses/history

Frog can see the calendar now

    >>> frog.open('http://localhost/schoolyears/2007/term-1/sections/1/calendar')
    >>> 'Calendar for History (1)' in frog.contents
    True

And Frog's overlay portlet shows the section:

    >>> frog.getLink('Calendar').click()
    >>> print_portlet(frog.contents)
    <table class="overlays">
      <tr style="background: #9db8d2"><td><input type="checkbox" checked="checked" disabled="disabled" /></td>
            <td style="width: 100%">My Calendar</td>
            <td></td>
          </tr>
      <tr style="background: #eed680"><td><input type="checkbox" name="overlay:list" checked="checked" value="/schooltool.course.section/.../1" /></td>
            <td style="width: 100%">History (1)</td>
            <td><a class="go" style="background: #d1940c;...
                color: #d1940c" href="http://localhost/schoolyears/2007/term-1/sections/1/calendar">...</a></td>
        </tr>
      <tr style="background: #e0b6af"><td><input type="checkbox" name="overlay:list" checked="checked" value="/" /></td>
            <td style="width: 100%">Your School</td>
            <td><a class="go" style="..." href="http://localhost/calendar">...</a></td>
        </tr>
    </table>

If we fire Frog, in hopes of getting Salamander to step in:

    >>> manager.getLink('edit instructors').click()
    >>> manager.getControl(name='remove_item.frog').value = True
    >>> manager.getControl('Remove').click()

Frog can't see the section's calendar any more

    >>> frog.open('http://localhost/schoolyears/2007/term-1/sections/1/calendar')
    >>> print frog.url
    http://localhost/auth/@@login.html?forbidden=yes&nexturl=...

and he's no longer an instructor:

    >>> manager.getControl('OK').click()
    >>> manager.printQuery("id('content-body')//div[@class='info-block'][2]/h3")
    <h3>Instructors</h3>
    >>> manager.printQuery("id('content-body')//div[@class='info-block'][2]/ul")
    <ul></ul>

And the section's calendar is no longer in his overlay portlet.

    >>> frog.getLink('Calendar').click()
    >>> print_portlet(frog.contents)
    <table class="overlays">
      <tr style="background: #9db8d2"><td><input type="checkbox" checked="checked" disabled="disabled" /></td>
            <td style="width: 100%">My Calendar</td>
            <td></td>
          </tr>
      <tr style="background: #e0b6af"><td><input type="checkbox" name="overlay:list" checked="checked" value="/" /></td>
            <td style="width: 100%">Your School</td>
            <td><a class="go" style="..." href="http://localhost/calendar">...</a></td>
        </tr>
    </table>

Adding a student:

    >>> manager.getLink('edit individuals').click()
    >>> manager.getControl(name='add_item.toad').value = True
    >>> manager.getControl('Add').click()
    >>> manager.getControl('OK').click()

Now toad is in the Students div

    >>> manager.printQuery("id('content-body')//div[@class='info-block'][3]/h3")
    <h3>Students</h3>
    >>> manager.printQuery("id('content-body')//div[@class='info-block'][3]/ul[1]//a")
    <a href="http://localhost/persons/toad">Toad</a>
    <a href="http://localhost/persons/toad">Toad</a>

Toad can see the calendar now:

    >>> toad.open('http://localhost/schoolyears/2007/term-1/sections/1/calendar')
    >>> print toad.url
    http://localhost/schoolyears/2007/term-1/sections/1/calendar

And Toad's overlay portlet shows the section:

    >>> toad.open('http://localhost/persons/toad/calendar')
    >>> print_portlet(toad.contents)
    <table class="overlays">
      <tr style="background: #9db8d2"><td><input type="checkbox" checked="checked" disabled="disabled" /></td>
            <td style="width: 100%">My Calendar</td>
            <td></td>
          </tr>
      <tr style="background: #eed680"><td><input type="checkbox" name="overlay:list" checked="checked" value="/schooltool.course.section/.../1" /></td>
            <td style="width: 100%">History (1)</td>
            <td><a class="go" style="..." href="http://localhost/schoolyears/2007/term-1/sections/1/calendar">...</a></td>
        </tr>
      <tr style="background: #e0b6af"><td><input type="checkbox" name="overlay:list" checked="checked" value="/" /></td>
            <td style="width: 100%">Your School</td>
            <td><a class="go" style="..." href="http://localhost/calendar">...</a></td>
        </tr>
    </table>

Though students can't see the section list (nor sections themselves) by
default:

    >>> frog.open('http://localhost/schoolyears/2007/term-1/sections/1')
    >>> print frog.url
    http://localhost/auth/@@login.html?forbidden=yes&nexturl=...

we can give them the permission:

    >>> url = manager.url
    >>> manager.open('http://localhost/access_control.html')
    >>> manager.getControl('Basic information about sections, including rosters, is visible to the general public').click()
    >>> manager.getControl('Apply').click()

Students still aren't given the option to change the location:

    >>> frog.open('http://localhost/schoolyears/2007/term-1/sections/1')
    >>> print frog.url
    http://localhost/schoolyears/2007/term-1/sections/1
    >>> "change location" not in frog.contents
    True


Epilogue
--------

 vim: ft=rest
