
Integration tests of the views
==============================

Setup

    >>> root = getRootFolder()
    >>> from zope.app.folder import Folder
    >>> import transaction
    >>> root['places'] = Folder()
    >>> places = root['places']
    >>> from zope.dublincore.interfaces import IWriteZopeDublinCore
    >>> dc = IWriteZopeDublinCore(places)
    >>> dc.title = u'Test Places'
    >>> dc.description = u'Places for testing'
    >>> places['a'] = Folder()
    >>> placemark = places['a']
    >>> dc = IWriteZopeDublinCore(placemark)
    >>> dc.title = u'Placemark A'
    >>> dc.description = u'A first testing placemark'
    >>> from zgeo.geographer.interfaces import IWriteGeoreferenced
    >>> geo = IWriteGeoreferenced(placemark)
    >>> geo.setGeoInterface('Point', (-105, 40))
    >>> transaction.commit()

Test rendering of the atom-link-entry view

    >>> print http(r"""
    ... GET /places/a/@@atom-link-entry HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    Content-Length: 616
    Content-Type: application/atom+xml;charset=utf-8
    <BLANKLINE>
    <?xml version="1.0" encoding="utf-8"?>
    <entry xmlns="http://www.w3.org/2005/Atom"
           xmlns:georss="http://www.georss.org/georss"
           xmlns:gml="http://www.opengis.net/gml">
    <BLANKLINE>
        <title>Placemark A</title>
        <link rel="alternate" href="http://localhost/places/a">http://localhost/places/a</link>
        <id>http://localhost/places/a/@@atom-link-entry</id>
        <updated>2008...</updated>
        <summary>A first testing placemark</summary>
    <BLANKLINE>
        <georss:where>
          <gml:Point>
            <gml:pos>40.000000 -105.000000</gml:pos>
          </gml:Point>
        </georss:where>
    <BLANKLINE>
    <BLANKLINE>
    <BLANKLINE>
    </entry>
    <BLANKLINE>
    <BLANKLINE>

Test the feed view

    >>> print http(r"""
    ... GET /places/@@atom-subscription-feed HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    Content-Length: 1132
    Content-Type: application/atom+xml;charset=utf-8
    <BLANKLINE>
    <?xml version="1.0" encoding="utf-8"?>
    <feed xmlns="http://www.w3.org/2005/Atom"
          xmlns:georss="http://www.georss.org/georss"
          xmlns:gml="http://www.opengis.net/gml">
    <BLANKLINE>
    <BLANKLINE>
      <title>Test Places</title>
      <link rel="alternate" href="http://localhost/places">http://localhost/places</link>
      <link rel="self" type="application/atom+xml"
            href="http://localhost/places/@@atom-subscription-feed"/>
      <link rel="previous-archive" type="application/atom+xml"
            href="None"/>
      <updated>2008...</updated>
      <author>
        <name>()</name>
        <uri></uri>
        <email></email>
      </author>
      <id>http://localhost/places/@@atom-subscription-feed</id>
    <BLANKLINE>
      <entry>
        <title>Placemark A</title>
        <link rel="alternate" href="http://localhost/places/a">http://localhost/places/a</link>
        <id>http://localhost/places/a/@@atom-link-entry</id>
        <updated>2008...</updated>
        <summary>A first testing placemark</summary>
    <BLANKLINE>
        <georss:where>
          <gml:Point>
            <gml:pos>40.000000 -105.000000</gml:pos>
          </gml:Point>
        </georss:where>
    <BLANKLINE>
    <BLANKLINE>
    <BLANKLINE>
      </entry>
    <BLANKLINE>
    </feed>
    <BLANKLINE>
    <BLANKLINE>
    <BLANKLINE>

Test the search feed XML

    >>> print http(r"""
    ... GET /places/@@atom-search-feed HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    Content-Length: 1383
    Content-Type: application/atom+xml;charset=utf-8
    <BLANKLINE>
    <?xml version="1.0" encoding="utf-8"?>
    <feed xmlns="http://www.w3.org/2005/Atom"
          xmlns:georss="http://www.georss.org/georss"
          xmlns:gml="http://www.opengis.net/gml"
          xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
    <BLANKLINE>
    <BLANKLINE>
      <title>Test Places</title>
      <opensearch:totalResults>1</opensearch:totalResults>
      <opensearch:startPage>1</opensearch:startPage>
      <opensearch:itemsPerPage>20</opensearch:itemsPerPage>
      <link rel="alternate" href="http://localhost/places">http://localhost/places</link>
      <link rel="first" type="application/atom+xml"
            href="http://localhost/places/@@atom-search-feed"/>
      <link rel="last" type="application/atom+xml"
            href="http://localhost/places/@@atom-search-feed?page=-1"/>
    <BLANKLINE>
    <BLANKLINE>
      <updated>2008...</updated>
      <author>
        <name>()</name>
        <uri></uri>
        <email></email>
      </author>
      <id>http://localhost/places/@@atom-search-feed</id>
    <BLANKLINE>
      <entry>
        <title>Placemark A</title>
        <link rel="alternate" href="http://localhost/places/a">http://localhost/places/a</link>
        <id>http://localhost/places/a/@@atom-link-entry</id>
        <updated>2008...</updated>
        <summary>A first testing placemark</summary>
    <BLANKLINE>
        <georss:where>
          <gml:Point>
            <gml:pos>40.000000 -105.000000</gml:pos>
          </gml:Point>
        </georss:where>
    <BLANKLINE>
    <BLANKLINE>
    <BLANKLINE>
      </entry>
    <BLANKLINE>
    </feed>
    <BLANKLINE>
    <BLANKLINE>
    <BLANKLINE>

And now with a bbox

    >>> print http(r"""
    ... GET /places/@@atom-search-feed?bbox=-110,40,-105,45 HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 500 Internal Server Error
    Content-Length: 84
    Content-Type: text/html;charset=utf-8
    <BLANKLINE>
    <html><title>System Error</title>
    <body>
      A system error occurred.
    </body>
    </html>
    <BLANKLINE>

Fails without a catalog. Let's add one to places:

    >>> from zgeo.spatialindex.site import createLocalSpatialCatalog
    >>> createLocalSpatialCatalog(places)
    >>> transaction.commit()
    >>> from zope.component.interfaces import ObjectEvent
    >>> from zgeo.spatialindex.event import addIntIdSubscriber
    >>> from zgeo.spatialindex.event import indexDocSubscriber
    >>> addIntIdSubscriber(placemark, ObjectEvent(placemark))
    >>> indexDocSubscriber(ObjectEvent(placemark))

    >>> print http(r"""
    ... GET /places/@@atom-search-feed?bbox=-110,40,-105,45 HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    Content-Length: 1485
    Content-Type: application/atom+xml;charset=utf-8
    <BLANKLINE>
    <?xml version="1.0" encoding="utf-8"?>
    <feed xmlns="http://www.w3.org/2005/Atom"
          xmlns:georss="http://www.georss.org/georss"
          xmlns:gml="http://www.opengis.net/gml"
          xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
    <BLANKLINE>
    <BLANKLINE>
      <title>Test Places</title>
      <opensearch:totalResults>1</opensearch:totalResults>
      <opensearch:startPage>1</opensearch:startPage>
      <opensearch:itemsPerPage>20</opensearch:itemsPerPage>
      <link rel="alternate" href="http://localhost/places">http://localhost/places</link>
      <link rel="first" type="application/atom+xml"
            href="http://localhost/places/@@atom-search-feed?bbox=-110.000000,40.000000,-105.000000,45.000000"/>
      <link rel="last" type="application/atom+xml"
            href="http://localhost/places/@@atom-search-feed?page=-1&amp;bbox=-110.000000,40.000000,-105.000000,45.000000"/>
    <BLANKLINE>
    <BLANKLINE>
      <updated>2008...</updated>
      <author>
        <name>()</name>
        <uri></uri>
        <email></email>
      </author>
      <id>http://localhost/places/@@atom-search-feed</id>
    <BLANKLINE>
      <entry>
        <title>Placemark A</title>
        <link rel="alternate" href="http://localhost/places/a">http://localhost/places/a</link>
        <id>http://localhost/places/a/@@atom-link-entry</id>
        <updated>2008...</updated>
        <summary>A first testing placemark</summary>
    <BLANKLINE>
        <georss:where>
          <gml:Point>
            <gml:pos>40.000000 -105.000000</gml:pos>
          </gml:Point>
        </georss:where>
    <BLANKLINE>
    <BLANKLINE>
    <BLANKLINE>
      </entry>
    <BLANKLINE>
    </feed>
    <BLANKLINE>
    <BLANKLINE>
    <BLANKLINE>

Test with a bbox that misses the placemark

    >>> print http(r"""
    ... GET /places/@@atom-search-feed?bbox=0,40,5,45 HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    HTTP/1.1 200 Ok
    Content-Length: 1029
    Content-Type: application/atom+xml;charset=utf-8
    <BLANKLINE>
    <?xml version="1.0" encoding="utf-8"?>
    <feed xmlns="http://www.w3.org/2005/Atom"
          xmlns:georss="http://www.georss.org/georss"
          xmlns:gml="http://www.opengis.net/gml"
          xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
    <BLANKLINE>
    <BLANKLINE>
      <title>Test Places</title>
      <opensearch:totalResults>0</opensearch:totalResults>
      <opensearch:startPage>1</opensearch:startPage>
      <opensearch:itemsPerPage>20</opensearch:itemsPerPage>
      <link rel="alternate" href="http://localhost/places">http://localhost/places</link>
      <link rel="first" type="application/atom+xml"
            href="http://localhost/places/@@atom-search-feed?bbox=0.000000,40.000000,5.000000,45.000000"/>
      <link rel="last" type="application/atom+xml"
            href="http://localhost/places/@@atom-search-feed?page=-1&amp;bbox=0.000000,40.000000,5.000000,45.000000"/>
    <BLANKLINE>
    <BLANKLINE>
      <updated>2008...</updated>
      <author>
        <name>()</name>
        <uri></uri>
        <email></email>
      </author>
      <id>http://localhost/places/@@atom-search-feed</id>
    <BLANKLINE>
    <BLANKLINE>
    </feed>
    <BLANKLINE>
    <BLANKLINE>
    <BLANKLINE>

