Functional tests for SchoolBell app RESTive views
=================================================

First of all, we will need a schoolbell instance.  We will add it via
the web ZMI:

    >>> print http("""
    ... POST /@@contents.html HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... Content-Length: 81
    ... Content-Type: application/x-www-form-urlencoded
    ...
    ... type_name=BrowserAdd__schoolbell.app.app.SchoolBellApplication&\
    ... new_value=frogpond""")
    HTTP/1.1 303 See Other
    ...
    Location: http://localhost/@@contents.html
    ...

Also, we need the REST HTTP caller:

    >>> from schoolbell.app.rest.ftests import rest

Now, we can run the REST page tests:

    >>> print rest("""
    ... GET /frogpond HTTP/1.1
    ... """)
    HTTP/1.1 200 Ok
    ...
    <schooltool xmlns:xlink="http://www.w3.org/1999/xlink">
      <message>Welcome to the SchoolBell server</message>
      <containers>
        <container xlink:type="simple"
                   xlink:href="http://localhost/frogpond/persons"
                   xlink:title="persons"/>
        <container xlink:type="simple"
                   xlink:href="http://localhost/frogpond/groups"
                   xlink:title="groups"/>
        <container xlink:type="simple"
                   xlink:href="http://localhost/frogpond/resources"
                   xlink:title="resources"/>
      </containers>
    </schooltool>
    <BLANKLINE>

There are no groups at the moment:

    >>> print rest("""
    ... GET /frogpond/groups/ HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """, handle_errors=False)
    HTTP/1.1 200 Ok
    ...
    <container xmlns:xlink="http://www.w3.org/1999/xlink">
      <name>groups</name>
      <items>
      </items>
      <acl xlink:type="simple" xlink:title="ACL"
           xlink:href="http://localhost/frogpond/groups/acl"/>
    </container>
    <BLANKLINE>

no resources:

    >>> print rest("""
    ... GET /frogpond/resources/ HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    ...
    <container xmlns:xlink="http://www.w3.org/1999/xlink">
      <name>resources</name>
      <items>
      </items>
      <acl xlink:type="simple" xlink:title="ACL"
           xlink:href="http://localhost/frogpond/resources/acl"/>
    </container>
    <BLANKLINE>

and no persons:

    >>> print rest("""
    ... GET /frogpond/persons/ HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    ...
    <container xmlns:xlink="http://www.w3.org/1999/xlink">
      <name>persons</name>
      <items>
      </items>
      <acl xlink:type="simple" xlink:title="ACL"
           xlink:href="http://localhost/frogpond/persons/acl"/>
    </container>
    <BLANKLINE>

We can add some groups with POST:

    >>> print rest("""
    ... POST /frogpond/groups/ HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... Content-Type: text/xml
    ...
    ... <object xmlns="http://schooltool.org/ns/model/0.1" title="A Group"/>
    ... """)
    HTTP/1.1 201 Created
    ...
    Location: http://localhost/frogpond/groups/a-group
    <BLANKLINE>
    Object created: http://localhost/frogpond/groups/a-group

We can add some groups with PUT:

    >>> print rest("""
    ... PUT /frogpond/groups/another-group HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... Content-Type: text/xml
    ...
    ... <object xmlns="http://schooltool.org/ns/model/0.1" title="Another Group"/>
    ... """)
    HTTP/1.1 201 Created
    ...
    <BLANKLINE>

Both groups were created:

    >>> print rest("""
    ... GET /frogpond/groups/ HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    ...
    <container xmlns:xlink="http://www.w3.org/1999/xlink">
      <name>groups</name>
      <items>
        <item xlink:type="simple"
              xlink:href="http://localhost/frogpond/groups/a-group"
              xlink:title="A Group"/>
        <item xlink:type="simple"
              xlink:href="http://localhost/frogpond/groups/another-group"
              xlink:title="Another Group"/>
      </items>
      <acl xlink:type="simple" xlink:title="ACL"
           xlink:href="http://localhost/frogpond/groups/acl"/>
    </container>
    <BLANKLINE>

We can delete groups as well:

    >>> print rest("""
    ... DELETE /frogpond/groups/another-group HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    ...

Only one group is left:

    >>> print rest("""
    ... GET /frogpond/groups/ HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    ...
    <container xmlns:xlink="http://www.w3.org/1999/xlink">
      <name>groups</name>
      <items>
        <item xlink:type="simple"
              xlink:href="http://localhost/frogpond/groups/a-group"
              xlink:title="A Group"/>
      </items>
      <acl xlink:type="simple" xlink:title="ACL"
           xlink:href="http://localhost/frogpond/groups/acl"/>
    </container>
    <BLANKLINE>

Same with the resources:

We can add some resources with POST:

    >>> print rest("""
    ... POST /frogpond/resources/ HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... Content-Type: text/xml
    ...
    ... <object xmlns="http://schooltool.org/ns/model/0.1" title="A Resource" isLocation="true" />
    ... """)
    HTTP/1.1 201 Created
    ...
    Location: http://localhost/frogpond/resources/a-resource
    <BLANKLINE>
    Object created: http://localhost/frogpond/resources/a-resource

This resource is a location:

    >>> print rest("""
    ... GET /frogpond/resources/a-resource HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    ...
    <BLANKLINE>
    <resource xmlns:xlink="http://www.w3.org/1999/xlink">
    ...
      <isLocation>True</isLocation>
    ...
    <BLANKLINE>


We can add some resources with PUT:

    >>> print rest("""
    ... PUT /frogpond/resources/another-resource HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... Content-Type: text/xml
    ...
    ... <object xmlns="http://schooltool.org/ns/model/0.1" title="Another Resource"/>
    ... """)
    HTTP/1.1 201 Created
    ...
    <BLANKLINE>


This resource is not a location:

    >>> print rest("""
    ... GET /frogpond/resources/another-resource HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    ...
    <BLANKLINE>
    <resource xmlns:xlink="http://www.w3.org/1999/xlink">
    ...
      <isLocation>False</isLocation>
    ...
    <BLANKLINE>

Both resources were created:

    >>> print rest("""
    ... GET /frogpond/resources/ HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    ...
    <container xmlns:xlink="http://www.w3.org/1999/xlink">
      <name>resources</name>
      <items>
        <item xlink:type="simple"
              xlink:href="http://localhost/frogpond/resources/a-resource"
              xlink:title="A Resource"/>
        <item xlink:type="simple"
              xlink:href="http://localhost/frogpond/resources/another-resource"
              xlink:title="Another Resource"/>
      </items>
      <acl xlink:type="simple" xlink:title="ACL"
           xlink:href="http://localhost/frogpond/resources/acl"/>
    </container>
    <BLANKLINE>

We can delete resources as well:

    >>> print rest("""
    ... DELETE /frogpond/resources/another-resource HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    ...

Only one resource is left:

    >>> print rest("""
    ... GET /frogpond/resources/ HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    ...
    <container xmlns:xlink="http://www.w3.org/1999/xlink">
      <name>resources</name>
      <items>
        <item xlink:type="simple"
              xlink:href="http://localhost/frogpond/resources/a-resource"
              xlink:title="A Resource"/>
      </items>
      <acl xlink:type="simple" xlink:title="ACL"
           xlink:href="http://localhost/frogpond/resources/acl"/>
    </container>
    <BLANKLINE>

Persons are a bit different, they don't have description yet they have
username:

The id of the user is same as his username:

    >>> print rest("""
    ... PUT /frogpond/persons/john HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... Content-Type: text/xml
    ...
    ... <object xmlns="http://schooltool.org/ns/model/0.1" title="John"/>
    ... """)
    HTTP/1.1 201 Created
    ...

We don't have to supply a username when making a PUT:

    >>> print rest("""
    ... PUT /frogpond/persons/peter HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... Content-Type: text/xml
    ...
    ... <object xmlns="http://schooltool.org/ns/model/0.1" title="Peter"/>
    ... """)
    HTTP/1.1 201 Created
    ...
    <BLANKLINE>

Both persons were created:

    >>> print rest("""
    ... GET /frogpond/persons/ HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    ...
    <container xmlns:xlink="http://www.w3.org/1999/xlink">
      <name>persons</name>
      <items>
        <item xlink:type="simple"
              xlink:href="http://localhost/frogpond/persons/john"
              xlink:title="John"/>
        <item xlink:type="simple"
              xlink:href="http://localhost/frogpond/persons/peter"
              xlink:title="Peter"/>
      </items>
      <acl xlink:type="simple" xlink:title="ACL"
           xlink:href="http://localhost/frogpond/persons/acl"/>
    </container>
    <BLANKLINE>

We can delete persons as well:

    >>> print rest("""
    ... DELETE /frogpond/persons/peter HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    ...

Only one person is left:

    >>> print rest("""
    ... GET /frogpond/persons/ HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    ...
    <container xmlns:xlink="http://www.w3.org/1999/xlink">
      <name>persons</name>
      <items>
        <item xlink:type="simple"
              xlink:href="http://localhost/frogpond/persons/john"
              xlink:title="John"/>
      </items>
      <acl xlink:type="simple" xlink:title="ACL"
           xlink:href="http://localhost/frogpond/persons/acl"/>
    </container>
    <BLANKLINE>

Let's look how our group looks now:

    >>> print rest("""
    ... GET /frogpond/groups/a-group HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """, handle_errors = False)
    HTTP/1.1 200 Ok
    ...
    <group xmlns="http://schooltool.org/ns/model/0.1"
           xmlns:xlink="http://www.w3.org/1999/xlink">
      <title>A Group</title>
      <description></description>
      <relationships xlink:type="simple"
                     xlink:title="Relationships"
                     xlink:href="http://localhost/frogpond/groups/a-group/relationships"/>
      <acl xlink:type="simple" xlink:title="ACL"
           xlink:href="http://localhost/frogpond/groups/a-group/acl"/>
      <calendar xlink:type="simple" xlink:title="Calendar"
                xlink:href="http://localhost/frogpond/groups/a-group/calendar"/>
      <relationships xlink:type="simple"
                     xlink:title="Calendar subscriptions"
                     xlink:href="http://localhost/frogpond/groups/a-group/calendar/relationships"/>
      <acl xlink:type="simple" xlink:title="Calendar ACL"
           xlink:href="http://localhost/frogpond/groups/a-group/calendar/acl"/>
    </group>
    <BLANKLINE>


We can change the title of the group that we just created:

    >>> print rest("""
    ... PUT /frogpond/groups/a-group HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... Content-Type: text/xml
    ...
    ... <object xmlns="http://schooltool.org/ns/model/0.1" title="The group"/>
    ... """)
    HTTP/1.1 200 Ok
    ...
    <BLANKLINE>

Now the title of the group should be different:

    >>> print rest("""
    ... GET /frogpond/groups/a-group HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    ...
    <group xmlns="http://schooltool.org/ns/model/0.1"
           xmlns:xlink="http://www.w3.org/1999/xlink">
      <title>The group</title>
      <description></description>
      <relationships xlink:type="simple"
                     xlink:title="Relationships"
                     xlink:href="http://localhost/frogpond/groups/a-group/relationships"/>
      <acl xlink:type="simple" xlink:title="ACL"
           xlink:href="http://localhost/frogpond/groups/a-group/acl"/>
      <calendar xlink:type="simple" xlink:title="Calendar"
                xlink:href="http://localhost/frogpond/groups/a-group/calendar"/>
      <relationships xlink:type="simple"
                     xlink:title="Calendar subscriptions"
                     xlink:href="http://localhost/frogpond/groups/a-group/calendar/relationships"/>
      <acl xlink:type="simple" xlink:title="Calendar ACL"
           xlink:href="http://localhost/frogpond/groups/a-group/calendar/acl"/>
    </group>
    <BLANKLINE>

Resource:

    >>> print rest("""
    ... GET /frogpond/resources/a-resource HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    ...
    <resource xmlns:xlink="http://www.w3.org/1999/xlink">
      <title>A Resource</title>
      <description></description>
      <isLocation>True</isLocation>
      <relationships xlink:type="simple"
                     xlink:title="Relationships"
                     xlink:href="http://localhost/frogpond/resources/a-resource/relationships"/>
      <acl xlink:type="simple" xlink:title="ACL"
           xlink:href="http://localhost/frogpond/resources/a-resource/acl"/>
      <calendar xlink:type="simple" xlink:title="Calendar"
                xlink:href="http://localhost/frogpond/resources/a-resource/calendar"/>
      <relationships xlink:type="simple"
                     xlink:title="Calendar subscriptions"
                     xlink:href="http://localhost/frogpond/resources/a-resource/calendar/relationships"/>
      <acl xlink:type="simple" xlink:title="Calendar ACL"
           xlink:href="http://localhost/frogpond/resources/a-resource/calendar/acl"/>
    </resource>
    <BLANKLINE>


We can change the title of the resource that we just created:

    >>> print rest("""
    ... PUT /frogpond/resources/a-resource HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... Content-Type: text/xml
    ...
    ... <object xmlns="http://schooltool.org/ns/model/0.1" title="The resource" isLocation="true" />
    ... """)
    HTTP/1.1 200 Ok
    ...
    <BLANKLINE>

Now the title of the resource should be different:

    >>> print rest("""
    ... GET /frogpond/resources/a-resource HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    ...
    <resource xmlns:xlink="http://www.w3.org/1999/xlink">
      <title>The resource</title>
      <description></description>
      <isLocation>True</isLocation>
      <relationships xlink:type="simple"
                     xlink:title="Relationships"
                     xlink:href="http://localhost/frogpond/resources/a-resource/relationships"/>
      <acl xlink:type="simple" xlink:title="ACL"
           xlink:href="http://localhost/frogpond/resources/a-resource/acl"/>
      <calendar xlink:type="simple" xlink:title="Calendar"
                xlink:href="http://localhost/frogpond/resources/a-resource/calendar"/>
      <relationships xlink:type="simple"
                     xlink:title="Calendar subscriptions"
                     xlink:href="http://localhost/frogpond/resources/a-resource/calendar/relationships"/>
      <acl xlink:type="simple" xlink:title="Calendar ACL"
           xlink:href="http://localhost/frogpond/resources/a-resource/calendar/acl"/>
    </resource>
    <BLANKLINE>

We can decide this resource isn't really a usable location:

    >>> print rest("""
    ... PUT /frogpond/resources/a-resource HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... Content-Type: text/xml
    ...
    ... <object xmlns="http://schooltool.org/ns/model/0.1" title="The resource" isLocation="false" />
    ... """)
    HTTP/1.1 200 Ok
    ...
    <BLANKLINE>

Now the resource isn't a location

    >>> print rest("""
    ... GET /frogpond/resources/a-resource HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    ...
    <resource xmlns:xlink="http://www.w3.org/1999/xlink">
      <title>The resource</title>
      <description></description>
      <isLocation>False</isLocation>
    ...

Person:

    >>> print rest("""
    ... GET /frogpond/persons/john HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    ...
    <person xmlns="http://schooltool.org/ns/model/0.1"
            xmlns:xlink="http://www.w3.org/1999/xlink">
      <title>John</title>
      <relationships xlink:type="simple"
                     xlink:title="Relationships"
                     xlink:href="http://localhost/frogpond/persons/john/relationships"/>
      <acl xlink:type="simple" xlink:title="ACL"
           xlink:href="http://localhost/frogpond/persons/john/acl"/>
      <calendar xlink:type="simple" xlink:title="Calendar"
                xlink:href="http://localhost/frogpond/persons/john/calendar"/>
      <relationships xlink:type="simple"
                     xlink:title="Calendar subscriptions"
                     xlink:href="http://localhost/frogpond/persons/john/calendar/relationships"/>
      <acl xlink:type="simple" xlink:title="Calendar ACL"
           xlink:href="http://localhost/frogpond/persons/john/calendar/acl"/>
    </person>
    <BLANKLINE>


We can change the title of the person that we just created:

    >>> print rest("""
    ... PUT /frogpond/persons/john HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... Content-Type: text/xml
    ...
    ... <object xmlns="http://schooltool.org/ns/model/0.1" title="The person"/>
    ... """)
    HTTP/1.1 200 Ok
    ...
    <BLANKLINE>

Now the title of the person should be different:

    >>> print rest("""
    ... GET /frogpond/persons/john HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    ...
    <person xmlns="http://schooltool.org/ns/model/0.1"
            xmlns:xlink="http://www.w3.org/1999/xlink">
      <title>The person</title>
      <relationships xlink:type="simple"
                     xlink:title="Relationships"
                     xlink:href="http://localhost/frogpond/persons/john/relationships"/>
      <acl xlink:type="simple" xlink:title="ACL"
           xlink:href="http://localhost/frogpond/persons/john/acl"/>
      <calendar xlink:type="simple" xlink:title="Calendar"
                xlink:href="http://localhost/frogpond/persons/john/calendar"/>
      <relationships xlink:type="simple"
                     xlink:title="Calendar subscriptions"
                     xlink:href="http://localhost/frogpond/persons/john/calendar/relationships"/>
      <acl xlink:type="simple" xlink:title="Calendar ACL"
           xlink:href="http://localhost/frogpond/persons/john/calendar/acl"/>
    </person>
    <BLANKLINE>


We should be capable of viewing his calendar:

    >>> print str(rest("""
    ... GET /frogpond/persons/john/calendar HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)).replace("\r\n", "\n")
    HTTP/1.1 200 Ok
    ...
    <BLANKLINE>
    BEGIN:VCALENDAR
    VERSION:2.0
    PRODID:-//SchoolTool.org/NONSGML SchoolBell//EN
    BEGIN:VEVENT
    UID:empty-calendar-placeholder@schooltool.org
    SUMMARY:Empty calendar
    ...
    DURATION:P0D
    ...
    END:VEVENT
    END:VCALENDAR
    <BLANKLINE>

We can access group and resource calendars too:

    >>> print str(rest("""
    ... GET /frogpond/groups/a-group/calendar HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)).replace("\r\n", "\n")
    HTTP/1.1 200 Ok
    ...
    <BLANKLINE>
    BEGIN:VCALENDAR
    VERSION:2.0
    PRODID:-//SchoolTool.org/NONSGML SchoolBell//EN
    BEGIN:VEVENT
    UID:empty-calendar-placeholder@schooltool.org
    SUMMARY:Empty calendar
    ...
    DURATION:P0D
    ...
    END:VEVENT
    END:VCALENDAR
    <BLANKLINE>

    >>> print str(rest("""
    ... GET /frogpond/resources/a-resource/calendar HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)).replace("\r\n", "\n")
    HTTP/1.1 200 Ok
    ...
    <BLANKLINE>
    BEGIN:VCALENDAR
    VERSION:2.0
    PRODID:-//SchoolTool.org/NONSGML SchoolBell//EN
    BEGIN:VEVENT
    UID:empty-calendar-placeholder@schooltool.org
    SUMMARY:Empty calendar
    ...
    DURATION:P0D
    ...
    END:VEVENT
    END:VCALENDAR
    <BLANKLINE>

Let's put a new calendar in there:

    >>> print rest(r"""
    ... PUT /frogpond/resources/a-resource/calendar HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... Content-Length: 244
    ... Content-Type: text/calendar
    ...
    ... BEGIN:VCALENDAR
    ... VERSION:2.0
    ... PRODID:-//SchoolTool.org/NONSGML SchoolBell//EN
    ... BEGIN:VEVENT
    ... UID:some-uid@example.com
    ... SUMMARY:Sample event (modified)
    ... DTSTART:20050204T100000Z
    ... DURATION:PT2H
    ... DTSTAMP:20050203T150000
    ... END:VEVENT
    ... BEGIN:VEVENT
    ... UID:some-uid2@example.com
    ... SUMMARY:New event
    ... DTSTART:20050204T120000Z
    ... DURATION:PT1H
    ... DTSTAMP:20050203T150000
    ... END:VEVENT
    ... END:VCALENDAR
    ... """)
    HTTP/1.1 200 Ok
    Content-Length: 0
    <BLANKLINE>

Let's get it back:

    >>> print str(rest("""
    ... GET /frogpond/resources/a-resource/calendar HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)).replace("\r\n", "\n")
    HTTP/1.1 200 Ok
    ...
    <BLANKLINE>
    BEGIN:VCALENDAR
    VERSION:2.0
    PRODID:-//SchoolTool.org/NONSGML SchoolBell//EN
    BEGIN:VEVENT
    UID:some-uid@example.com
    SUMMARY:Sample event (modified)
    DTSTART:20050204T100000Z
    DURATION:PT2H
    ...
    END:VEVENT
    BEGIN:VEVENT
    UID:some-uid2@example.com
    SUMMARY:New event
    DTSTART:20050204T120000Z
    DURATION:PT1H
    ...
    END:VEVENT
    END:VCALENDAR
    <BLANKLINE>

Calendars should support other charsets too:

    >>> print rest(r"""
    ... PUT /frogpond/resources/a-resource/calendar HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... Content-Length: 244
    ... Content-Type: text/calendar; charset=latin-1
    ...
    ... BEGIN:VCALENDAR
    ... VERSION:2.0
    ... PRODID:-//SchoolTool.org/NONSGML SchoolBell//EN
    ... BEGIN:VEVENT
    ... UID:some-uid@example.com
    ... SUMMARY:Sample event 200 %s (pounds)
    ... DTSTART:20050204T100000
    ... DURATION:PT2H
    ... DTSTAMP:20050203T150000
    ... END:VEVENT
    ... BEGIN:VEVENT
    ... UID:some-uid2@example.com
    ... SUMMARY:New event
    ... DTSTART:20050204T120000
    ... DURATION:PT1H
    ... DTSTAMP:20050203T150000
    ... END:VEVENT
    ... END:VCALENDAR
    ... """ % chr(163))
    HTTP/1.1 200 Ok
    Content-Length: 0
    <BLANKLINE>

The event should be there now:

    >>> print str(rest("""
    ... GET /frogpond/resources/a-resource/calendar HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """, handle_errors=False)).replace("\r\n", "\n")
    HTTP/1.1 200 Ok
    ...
    <BLANKLINE>
    BEGIN:VCALENDAR
    VERSION:2.0
    PRODID:-//SchoolTool.org/NONSGML SchoolBell//EN
    BEGIN:VEVENT
    UID:some-uid@example.com
    SUMMARY:Sample event 200 ... (pounds)
    DTSTART:20050204T100000Z
    DURATION:PT2H
    ...
    END:VEVENT
    BEGIN:VEVENT
    UID:some-uid2@example.com
    SUMMARY:New event
    DTSTART:20050204T120000Z
    DURATION:PT1H
    ...
    END:VEVENT
    END:VCALENDAR
    <BLANKLINE>


We should be capable of giving a password to a person:

    >>> print rest("""
    ... PUT /frogpond/persons/john/password HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ...
    ... super-secret-password
    ... """)
    HTTP/1.1 200 Ok
    Content-Length: 0
    <BLANKLINE>

He should be capable of logging in with this password now:

    >>> print rest("""
    ... GET /frogpond/persons/john HTTP/1.1
    ... Authorization: Basic john:super-secret-password
    ... """)
    HTTP/1.1 200 Ok
    ...
    <BLANKLINE>
    <person xmlns="http://schooltool.org/ns/model/0.1"
            xmlns:xlink="http://www.w3.org/1999/xlink">
      <title>The person</title>
      <relationships xlink:type="simple"
                     xlink:title="Relationships"
                     xlink:href="http://localhost/frogpond/persons/john/relationships"/>
      <acl xlink:type="simple" xlink:title="ACL"
           xlink:href="http://localhost/frogpond/persons/john/acl"/>
      <calendar xlink:type="simple" xlink:title="Calendar"
                xlink:href="http://localhost/frogpond/persons/john/calendar"/>
      <relationships xlink:type="simple"
                     xlink:title="Calendar subscriptions"
                     xlink:href="http://localhost/frogpond/persons/john/calendar/relationships"/>
      <acl xlink:type="simple" xlink:title="Calendar ACL"
           xlink:href="http://localhost/frogpond/persons/john/calendar/acl"/>
    </person>
    <BLANKLINE>

We can give our user a new photo if we want to:

    >>> print rest("""
    ... PUT /frogpond/persons/john/photo HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ...
    ... really-nice-photo %s !
    ... """ % chr(163)) # non ascii symbol
    HTTP/1.1 200 Ok
    Content-Length: 0
    <BLANKLINE>

Get it back:

    >>> print rest("""
    ... GET /frogpond/persons/john/photo HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    Content-Length: ...
    Content-Type: image/jpeg
    <BLANKLINE>
    really-nice-photo ... !
    <BLANKLINE>

Delete it:

    >>> print rest("""
    ... DELETE /frogpond/persons/john/photo HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    ...


And it should raise a not found if the photo is missing:

    >>> print rest("""
    ... GET /frogpond/persons/john/photo HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 404 Not Found
    Content-Length: 0
    <BLANKLINE>

We can view the preferences of our user:

    >>> print rest("""
    ... GET /frogpond/persons/john/preferences HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    Content-Length: ...
    Content-Type: text/xml; charset=UTF-8
    <BLANKLINE>
    <preferences xmlns:xlink="http://www.w3.org/1999/xlink">
    <BLANKLINE>
      <preference id="timezone" value="UTC"/>
      <preference id="timeformat" value="%H:%M"/>
      <preference id="dateformat" value="%Y-%m-%d"/>
      <preference id="weekstart" value="0"/>
    <BLANKLINE>
    </preferences>
    <BLANKLINE>

We can change the preferences:

    >>> print rest(r"""
    ... PUT /frogpond/persons/john/preferences HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... Content-Length: 244
    ... Content-Type: text/xml; charset=latin-1
    ...
    ... <?xml version="1.0"?>
    ... <preferences xmlns="http://schooltool.org/ns/model/0.1">
    ...  <preference id="timezone" value="US/Eastern"/>
    ... </preferences>
    ... """)
    HTTP/1.1 200 Ok
    Content-Length: ...
    <BLANKLINE>
    Preferences updated

And verify that the preference was changed:

    >>> print rest("""
    ... GET /frogpond/persons/john/preferences HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    Content-Length: ...
    Content-Type: text/xml; charset=UTF-8
    ...
      <preference id="timezone" value="US/Eastern"/>
    ...
