
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'
    >>> import datetime
    >>> dc.created = datetime.datetime.utcnow()
    >>> from zgeo.geographer.interfaces import IWriteGeoreferenced
    >>> geo = IWriteGeoreferenced(placemark)
    >>> geo.setGeoInterface('Point', (-105, 40))
    >>> transaction.commit()

Test rendering of the atom-link-entry view

    >>> response = http(r"""
    ... GET /places/a/@@atom-link-entry HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    >>> response.getStatus()
    200
    >>> response.getHeader('Content-Type')
    'application/atom+xml;type=entry'
    >>> print response.getBody()
    <?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 href="http://localhost/places/a" type="text/html"
              rel="alternate"/>
        <id>urn:uuid:...</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

    >>> response = http(r"""
    ... GET /places/@@atom-subscription-feed HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    >>> response.getStatus()
    200
    >>> response.getHeader('Content-type')
    'application/atom+xml'
    >>> print response.getBody()
    <?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 href="http://localhost/places/@@atom-subscription-feed"
            type="application/atom+xml" rel="self"/>
      <link href="http://localhost/places" type="text/html"
            rel="alternate"/>
      <link href="None" type="application/atom+xml"
            rel="previous-archive"/>
      <updated>2008...</updated>
      <author>
        <name>()</name>
        <uri></uri>
        <email></email>
      </author>
      <id>urn:uuid:...</id>
    <BLANKLINE>
      <entry>
        <title>Placemark A</title>
        <link href="http://localhost/places/a" type="text/html"
              rel="alternate"/>
        <id>urn:uuid:...</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

    >>> response = http(r"""
    ... GET /places/@@atom-search-feed HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """, handle_errors=False)
    >>> response.getStatus()
    200
    >>> response.getHeader('Content-Type')
    'application/atom+xml'
    >>> print response.getBody()
    <?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 href="http://localhost/places/@@atom-search-feed?page=-1"
            type="application/atom+xml" rel="last"/>
      <link href="http://localhost/places/@@atom-search-feed"
            type="application/atom+xml" rel="self"/>
      <link href="http://localhost/places" type="text/html"
            rel="alternate"/>
      <link href="None" type="application/atom+xml" rel="next"/>
      <link href="http://localhost/places/@@atom-search-feed"
            type="application/atom+xml" rel="first"/>
      <link href="None" type="application/atom+xml"
            rel="previous"/>
    <BLANKLINE>
    <BLANKLINE>
      <updated>2008...</updated>
      <author>
        <name>()</name>
        <uri></uri>
        <email></email>
      </author>
      <id>urn:uuid:...</id>
    <BLANKLINE>
      <entry>
        <title>Placemark A</title>
        <link href="http://localhost/places/a" type="text/html"
              rel="alternate"/>
        <id>urn:uuid:...</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

    >>> response = http(r"""
    ... GET /places/@@atom-search-feed?bbox=-110,40,-105,45 HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    >>> response.getStatus()
    500

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))

    >>> response = http(r"""
    ... GET /places/@@atom-search-feed?bbox=-110,40,-105,45 HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    >>> response.getStatus()
    200
    >>> response.getHeader('Content-Type')
    'application/atom+xml'
    >>> print response.getBody()
    <?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 href="http://localhost/places/@@atom-search-feed?page=-1&amp;bbox=-110.000000,40.000000,-105.000000,45.000000"
            type="application/atom+xml" rel="last"/>
      <link href="http://localhost/places/@@atom-search-feed"
            type="application/atom+xml" rel="self"/>
      <link href="http://localhost/places" type="text/html"
            rel="alternate"/>
      <link href="None" type="application/atom+xml" rel="next"/>
      <link href="http://localhost/places/@@atom-search-feed?bbox=-110.000000,40.000000,-105.000000,45.000000"
            type="application/atom+xml" rel="first"/>
      <link href="None" type="application/atom+xml"
            rel="previous"/>
    <BLANKLINE>
    <BLANKLINE>
      <updated>2008...</updated>
      <author>
        <name>()</name>
        <uri></uri>
        <email></email>
      </author>
      <id>urn:uuid:...</id>
    <BLANKLINE>
      <entry>
        <title>Placemark A</title>
        <link href="http://localhost/places/a" type="text/html"
              rel="alternate"/>
        <id>urn:uuid:...</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

    >>> response = http(r"""
    ... GET /places/@@atom-search-feed?bbox=0,40,5,45 HTTP/1.1
    ... Authorization: Basic mgr:mgrpw
    ... """)
    >>> response.getStatus()
    200
    >>> response.getHeader('Content-Type')
    'application/atom+xml'
    >>> print response.getBody()
    <?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 href="http://localhost/places/@@atom-search-feed?page=-1&amp;bbox=0.000000,40.000000,5.000000,45.000000"
            type="application/atom+xml" rel="last"/>
      <link href="http://localhost/places/@@atom-search-feed"
            type="application/atom+xml" rel="self"/>
      <link href="http://localhost/places" type="text/html"
            rel="alternate"/>
      <link href="None" type="application/atom+xml" rel="next"/>
      <link href="http://localhost/places/@@atom-search-feed?bbox=0.000000,40.000000,5.000000,45.000000"
            type="application/atom+xml" rel="first"/>
      <link href="None" type="application/atom+xml"
            rel="previous"/>
    <BLANKLINE>
    <BLANKLINE>
      <updated>2008...</updated>
      <author>
        <name>()</name>
        <uri></uri>
        <email></email>
      </author>
      <id>urn:uuid:...</id>
    <BLANKLINE>
    <BLANKLINE>
    </feed>
    <BLANKLINE>
    <BLANKLINE>
    <BLANKLINE>

