joey: thuban/Extensions/wms/test test_parser.py, NONE, 1.1 sample.xml, NONE, 1.1
cvs@intevation.de
cvs at intevation.de
Thu Mar 18 18:18:56 CET 2004
Author: joey
Update of /thubanrepository/thuban/Extensions/wms/test
In directory doto:/tmp/cvs-serv30729
Added Files:
test_parser.py sample.xml
Log Message:
Added another test for checking whether the WMS XML parser (to be
implemented) returns the information we expect. This requires a
sample WMS WML file (sample.xml) which has been extracted from the
frida <http://frida.intevation.org/> server and "improved" manually.
--- NEW FILE: test_parser.py ---
# -*- encoding: iso-8859-1 -*-
#
# Copyright (c) 2004 by Intevation GmbH
# Authors:
# Martin Schulze <joey at infodrom.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
Test for WMSCapabilitiesParser from ../parser.py
"""
__version__ = "$Revision: 1.1 $"
# $Source: /thubanrepository/thuban/Extensions/wms/test/test_parser.py,v $
# $Id: test_parser.py,v 1.1 2004/03/18 17:18:53 joey Exp $
import os
import unittest
from sys import path
# Add the main Thuban directory so the path so that all modules are
# accessible as expected
#
if os.path.dirname (__file__) == "" or os.path.dirname (__file__) == ".":
path.insert (0, os.path.abspath ("../../../"))
else:
path.insert (0, os.path.abspath (os.path.dirname(__file__) + "/../../.."))
from Extensions.wms.parser import WMSCapabilitiesParser
class TestWMSCapabilitiesParser (unittest.TestCase, WMSCapabilitiesParser):
"""
Defines a test environment for the class WMSCapabilities.
"""
def compareLists (self, foo, bar):
"""
Compare two lists
- check same number of elements
- check whether all elements in the first list are part of the second
"""
# Check for same number of elements
if len(foo) != len(bar):
self.fail ("Different number of elements");
# Loop through all elements for existance
for elm in foo:
if elm not in bar:
self.fail ("%s not in second list" % elm);
def compareDicts (self, foo, bar):
"""
Compare two dictionaries (hashes)
- check same number of keys
- check whether all keys from the first list are part of the second
"""
# Check for same number of elements
if len(foo) != len(bar):
self.fail ("Different number of keys");
# Loop through all elements for existance
for key in foo.keys():
if key not in bar:
self.fail ("%s not in second dictionary" % key);
if foo[key] != bar[key]:
self.fail ("%s has different value in second dictionary" % key);
def load_frida(self):
"""
Load the locally stored frida capabilities.
http://frida.intevation.org/cgi-bin/frida_wms?
"""
try:
try:
f = open ("sample.xml", "r")
except:
f = open (os.path.dirname (__file__) + "/sample.xml", "r")
except:
print "Cannot open sample.xml for reading"
else:
xml = f.read ();
f.close()
self.grok (xml)
def test_general (self):
"""
Test general attributes extracted from Capabilities XML
"""
if not self.capabilities:
self.load_frida()
self.assertEquals (self.getTitle(),'Frida - Freie Vektor-Geodaten Osnabrück')
self.assertEquals (self.getAbstract(),'')
self.assertEquals (self.getFees(),'')
self.assertEquals (self.getAccessConstraints(),'')
formats = ['image/gif', 'image/png', 'image/jpeg', 'image/wbmp']
self.compareLists (self.getFormats(),formats)
layers = ['Osnabrueck', 'gruenflaechen', 'gewaesser',
'gewaesserpolyl','gewaesserlinien', 'strassen_all',
'strassenhinten', 'strassen', 'beschriftung',
'hauptbeschriftung', 'sehenswuerdigkeiten']
self.compareLists (self.getLayers(),layers)
self.compareLists (self.getSRS(),[31493])
def test_LayerTitle (self):
"""
Check if layer titles are recognised properly
"""
if not self.capabilities:
self.load_frida()
# main layer
self.assertEquals (self.getLayerTitle('Osnabrueck'),'Frida - Freie Vektor-Geodaten Osnabrück')
# first nested layer
self.assertEquals (self.getLayerTitle('gruenflaechen'),'Grünflächen')
# first nested layer
self.assertEquals (self.getLayerTitle('gewaesser'),'Gewässer')
# second nested layer
self.assertEquals (self.getLayerTitle('gewaesserpolyl'),'Gewässerflächen')
def test_LayerSRS (self):
"""
Check if the SRS are returned properly
"""
if not self.capabilities:
self.load_frida()
# SRS of main layer
self.compareLists (self.getLayerSRS('Osnabrueck'),[31493])
# Single SRS of layer without inheritance
self.compareLists (self.getLayerSRS('gruenflaechen'),[31493])
# Multiple SRS (new/1.1.1) of layer without inheritance
self.compareLists (self.getLayerSRS('gewaesserpolyl'),[31493, 31494])
# Multiple SRS (old/1.0.0) of layer without inheritance
self.compareLists (self.getLayerSRS('gewaesserlinien'),[31493, 31494])
# Multiple SRS of layer with inheritance
self.compareLists (self.getLayerSRS('strassenhinten'),[31493, 31494])
# Multiple SRS (old/1.0.0) with inheritance
self.compareLists (self.getLayerSRS('strassen'),[31493, 31494, 31495])
# Multiple SRS (new/1.1.1) with inheritance
self.compareLists (self.getLayerSRS('beschriftung'),[31493, 31494, 31495])
def test_LatLonBoundingBoxes (self):
"""
Check if the LatLonBoundingBoxes are returned properly
"""
if not self.capabilities:
self.load_frida()
# main LatLonBoundingBox
bbox = {'minx': "7.92881", 'miny': "52.2131",
'maxx': "8.18349", 'maxy': "52.341"}
self.compareDicts (self.getLayerLatLonBBox('Osnabrueck'),bbox)
# inherited LatLonBoundingBox
bbox = {'minx': "7.92881", 'miny': "52.2131",
'maxx': "8.18349", 'maxy': "52.341"}
self.compareDicts (self.getLayerLatLonBBox('gewaesser'),bbox)
# third layer non-inherited LatLonBoundingBox
bbox = {'minx': "7.93531", 'miny': "52.2328",
'maxx': "8.17739", 'maxy': "52.3353"}
self.compareDicts (self.getLayerLatLonBBox('gewaesserpolyl'),bbox)
def test_BBoxSRS (self):
"""
Check if the BoundingBoxSRS' are returned properly
"""
if not self.capabilities:
self.load_frida()
# Single SRS:BBox
self.compareLists (self.getLayerBBoxSRS('gruenflaechen'),[31493])
# Single inherited SRS:BBox
self.compareLists (self.getLayerBBoxSRS('gewaesser'),[31493])
# Multiple SRS:BBox
self.compareLists (self.getLayerBBoxSRS('gewaesserpolyl'),[31493, 31494])
def test_BoundingBoxes (self):
"""
Check if the BoundingBoxes are returned properly
"""
if not self.capabilities:
self.load_frida()
# main BoundingBox
bbox = {'minx': "3.427e+06", 'miny': "5.787e+06",
'maxx': "3.4442e+06", 'maxy': "5.801e+06"}
self.compareDicts (self.getLayerBBox('Osnabrueck', 31493),bbox)
# inherited BoundingBox
self.compareDicts (self.getLayerBBox('gewaesser', 31493),bbox)
# overwritten BoundingBox
bbox = {'minx': "3.427e+06", 'miny': "5.78901e+06",
'maxx': "3.44173e+06", 'maxy': "5.79952e+06"}
self.compareDicts (self.getLayerBBox('gewaesserlinien', 31493),bbox)
# multiple BoundingBoxes
bbox = {'minx': "3.42743e+06", 'miny': "5.78919e+06",
'maxx': "3.44381e+06", 'maxy': "5.80038e+06"}
self.compareDicts (self.getLayerBBox('gewaesserpolyl', 31493),bbox)
bbox = {'minx': "3.42742e+06", 'miny': "5.78918e+06",
'maxx': "3.44380e+06", 'maxy': "5.80037e+06"}
self.compareDicts (self.getLayerBBox('gewaesserpolyl', 31494),bbox)
def test_queryable (self):
"""
Check if layers are properly classified queryable or not
"""
if not self.capabilities:
self.load_frida()
# implicit setting in main layer
self.assertEquals (self.isQueryable('Osnabrueck'),0)
# explicit setting in second layer
self.assertEquals (self.isQueryable('gruenflaechen'),0)
# inherited setting in second layer
self.assertEquals (self.isQueryable('gewaesser'),0)
# explicit setting in second layer
self.assertEquals (self.isQueryable('sehenswuerdigkeiten'),1)
# explicit setting in third layer
self.assertEquals (self.isQueryable('strassen'),1)
if __name__ == "__main__":
unittest.main()
--- NEW FILE: sample.xml ---
<?xml version='1.0' encoding="ISO-8859-1" standalone="no" ?>
<!DOCTYPE WMT_MS_Capabilities SYSTEM "http://www.digitalearth.gov/wmt/xml/capabilities_1_0_8.dtd"
[
<!ELEMENT VendorSpecificCapabilities EMPTY>
]> <!-- end of DOCTYPE declaration -->
<!-- Based on the capabilities returned on March 15th 2004 from
http://frida.intevation.org/cgi-bin/frida_wms? -->
<WMT_MS_Capabilities version="1.0.8" updateSequence="0">
<Service> <!-- a service IS a MapServer mapfile -->
<Name>GetMap</Name> <!-- WMT defined -->
<Title>Frida - Freie Vektor-Geodaten Osnabrück</Title>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://frida.intevation.org/cgi-bin/frida_wms?"/>
<ContactInformation>
</ContactInformation>
</Service>
<Capability>
<Request>
<GetCapabilities>
<Format>application/vnd.ogc.wms_xml</Format>
<DCPType>
<HTTP>
<Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://frida.intevation.org/cgi-bin/frida_wms?"/></Get>
<Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://frida.intevation.org/cgi-bin/frida_wms?"/></Post>
</HTTP>
</DCPType>
</GetCapabilities>
<GetMap>
<Format>image/gif</Format>
<Format>image/png</Format>
<Format>image/jpeg</Format>
<Format>image/wbmp</Format>
<DCPType>
<HTTP>
<Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://frida.intevation.org/cgi-bin/frida_wms?"/></Get>
<Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://frida.intevation.org/cgi-bin/frida_wms?"/></Post>
</HTTP>
</DCPType>
</GetMap>
<GetFeatureInfo>
<Format>text/plain</Format>
<Format>text/html</Format>
<Format>application/vnd.ogc.gml</Format>
<DCPType>
<HTTP>
<Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://frida.intevation.org/cgi-bin/frida_wms?"/></Get>
<Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://frida.intevation.org/cgi-bin/frida_wms?"/></Post>
</HTTP>
</DCPType>
</GetFeatureInfo>
</Request>
<Exception>
<Format>application/vnd.ogc.se_xml</Format>
<Format>application/vnd.ogc.se_inimage</Format>
<Format>application/vnd.ogc.se_blank</Format>
</Exception>
<VendorSpecificCapabilities />
<Layer>
<Name>Osnabrueck</Name>
<Title>Frida - Freie Vektor-Geodaten Osnabrück</Title>
<SRS>31493</SRS>
<LatLonBoundingBox minx="7.92881" miny="52.2131" maxx="8.18349" maxy="52.341" />
<BoundingBox SRS="31493"
minx="3.427e+06" miny="5.787e+06" maxx="3.4442e+06" maxy="5.801e+06" />
<ScaleHint min="0.498903" max="49.8903" />
<Layer queryable="0" opaque="0" cascaded="0">
<Name>gruenflaechen</Name>
<Title>Grünflächen</Title>
<SRS>EPSG:31493</SRS>
<LatLonBoundingBox minx="7.92984" miny="52.225" maxx="8.18033" maxy="52.3382" />
<BoundingBox SRS="EPSG:31493"
minx="3.42707e+06" miny="5.78832e+06" maxx="3.444e+06" maxy="5.80069e+06" />
</Layer>
<Layer>
<Name>gewaesser</Name>
<Title>Gewässer</Title>
<Layer queryable="0" opaque="0" cascaded="0">
<Name>gewaesserpolyl</Name>
<Title>Gewässerflächen</Title>
<SRS>EPSG:31493</SRS>
<SRS>EPSG:31494</SRS>
<LatLonBoundingBox minx="7.93531" miny="52.2328" maxx="8.17739" maxy="52.3353" />
<BoundingBox SRS="EPSG:31493"
minx="3.42743e+06" miny="5.78919e+06" maxx="3.44381e+06" maxy="5.80038e+06" />
<BoundingBox SRS="EPSG:31494"
minx="3.42742e+06" miny="5.78918e+06" maxx="3.44380e+06" maxy="5.80037e+06" />
</Layer>
<Layer queryable="0" opaque="0" cascaded="0">
<Name>gewaesserlinien</Name>
<Title>Gewässerlinien</Title>
<SRS>EPSG:31493 EPSG:31492</SRS>
<LatLonBoundingBox minx="7.92914" miny="52.2311" maxx="8.14707" maxy="52.3273" />
<BoundingBox SRS="EPSG:31493"
minx="3.427e+06" miny="5.78901e+06" maxx="3.44173e+06" maxy="5.79952e+06" />
</Layer>
</Layer>
<Layer>
<Name>strassen_all</Name>
<Title>Strassen sowie Beschriftung und Hintergrund</Title>
<Layer queryable="0" opaque="0" cascaded="0">
<Name>strassenhinten</Name>
<Title>Strassenhintergrund</Title>
<SRS>EPSG:31494</SRS>
<LatLonBoundingBox minx="7.92885" miny="52.2185" maxx="8.18052" maxy="52.3398" />
<BoundingBox SRS="EPSG:31493"
minx="3.427e+06" miny="5.78759e+06" maxx="3.444e+06" maxy="5.80088e+06" />
</Layer>
<Layer queryable="1" opaque="0" cascaded="0">
<Name>strassen</Name>
<Title>Strassen</Title>
<SRS>EPSG:31494 EPSG:31495</SRS>
<LatLonBoundingBox minx="7.92885" miny="52.2185" maxx="8.18052" maxy="52.3398" />
<BoundingBox SRS="EPSG:31493"
minx="3.427e+06" miny="5.78759e+06" maxx="3.444e+06" maxy="5.80088e+06" />
</Layer>
<Layer queryable="0" opaque="0" cascaded="0">
<Name>beschriftung</Name>
<Title>Beschriftung</Title>
<SRS>EPSG:31494</SRS>
<SRS>EPSG:31495</SRS>
<LatLonBoundingBox minx="7.92885" miny="52.2185" maxx="8.18052" maxy="52.3398" />
<BoundingBox SRS="EPSG:31493"
minx="3.427e+06" miny="5.78759e+06" maxx="3.444e+06" maxy="5.80088e+06" />
<ScaleHint min="0" max="4.98903" />
</Layer>
<Layer queryable="0" opaque="0" cascaded="0">
<Name>hauptbeschriftung</Name>
<Title>Hauptbeschriftung</Title>
<SRS>EPSG:31493</SRS>
<LatLonBoundingBox minx="7.92885" miny="52.2185" maxx="8.18052" maxy="52.3398" />
<BoundingBox SRS="EPSG:31493"
minx="3.427e+06" miny="5.78759e+06" maxx="3.444e+06" maxy="5.80088e+06" />
<ScaleHint min="0" max="9.97806" />
</Layer>
</Layer>
<Layer queryable="1" opaque="0" cascaded="0">
<Name>sehenswuerdigkeiten</Name>
<Title>Sehenswürdigkeiten</Title>
<SRS>EPSG:31493</SRS>
<LatLonBoundingBox minx="7.94044" miny="52.2332" maxx="8.1586" maxy="52.3265" />
<BoundingBox SRS="EPSG:31493"
minx="3.42777e+06" miny="5.78922e+06" maxx="3.44253e+06" maxy="5.79941e+06" />
</Layer>
</Layer>
</Capability>
</WMT_MS_Capabilities>
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)