Changeset 510

Show
Ignore:
Timestamp:
10/17/06 14:02:57
Author:
seang
Message:

add a mapserver WMS test. new api provides everything the old one did.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • OWSLib/trunk/owslib/interfaces.py

    r509 r510  
    6363    operations : list 
    6464        List of operation descriptors. 
     65    exceptions : list 
     66        List of exception formats. 
    6567    """ 
    6668     
     
    7274    name : string 
    7375        "GetCapabilities", for example. 
     76    formatOptions : list 
     77        List of content types. 
    7478    methods : dict 
    7579        Array of method descriptors, keyed to HTTP verbs. 
     
    111115    crsOptions : list 
    112116        List of available coordinate/spatial reference systems. 
     117    styles : list 
     118        List of style dicts. 
    113119    """ 
    114120 
  • OWSLib/trunk/owslib/wms.py

    r509 r510  
    9797         
    9898        # operations [] 
     99        self.operations = [] 
     100        for elem in self._root.findall('Capability/Request/*'): 
     101            self.operations.append(OperationMetadata(elem)) 
     102 
     103        # exceptions 
     104        self.exceptions = [f.text for f \ 
     105                in self._root.findall('Capability/Exception/Format')] 
    99106         
    100107        # contents: our assumption is that services use a top-level layer 
     
    167174        # crs options 
    168175        self.crsOptions = [srs.text for srs in parent.findall('SRS')] 
    169          
     176 
     177        # styles 
     178        self.styles = dict([(s.find('Name').text, {'title': s.find('Title').text}) for s in elem.findall('Style')]) 
     179 
     180class OperationMetadata: 
     181    """Abstraction for WMS metadata. 
     182     
     183    Implements IMetadata. 
     184    """ 
     185    def __init__(self, elem): 
     186        """.""" 
     187        self.name = elem.tag 
     188        # formatOptions 
     189        self.formatOptions = [f.text for f in elem.findall('Format')] 
     190        methods = [] 
     191        for verb in elem.findall('DCPType/HTTP/*'): 
     192            url = verb.find('OnlineResource').attrib['{http://www.w3.org/1999/xlink}href'] 
     193            methods.append((verb.tag, {'url': url})) 
     194        self.methods = dict(methods) 
    170195         
    171196class WMSCapabilitiesInfoset: 
  • OWSLib/trunk/tests/JPLCapabilities.txt

    r509 r510  
    1 # ============================================================================= 
    2 # Python Cartographic Library (C) 2006 Sean C. Gillies 
    3 # 
    4 # This program is free software; you can redistribute it and/or modify it 
    5 # under the terms of the GNU General Public License as published by the Free 
    6 # Software Foundation; either version 2 of the License, or (at your option) 
    7 # any later version. 
    8 # 
    9 # This program is distributed in the hope that it will be useful, but WITHOUT 
    10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
    11 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
    12 # details. 
    13 # 
    14 # You should have received a copy of the GNU General Public License along with 
    15 # this program; if not, write to the Free Software Foundation, Inc., 59 Temple 
    16 # Place, Suite 330, Boston, MA 02111-1307 USA 
    17 # 
    18 # Contact email: sgillies@frii.com 
    19 # =========================================================================== 
    201 
    212Imports 
     
    5233    >>> wms.capabilities.getContentByName('global_mosaic').crsOptions 
    5334    ['EPSG:4326', 'AUTO:42003'] 
    54  
     35    >>> wms.capabilities.getContentByName('global_mosaic').styles 
     36    {'pseudo_bright': {'title': 'Pseudo-color image (Uses IR and Visual bands, 542 mapping), gamma 1.5'}, 'pseudo': {'title': '(default) Pseudo-color image, pan sharpened (Uses IR and Visual bands, 542 mapping), gamma 1.5'}, 'visual': {'title': 'Real-color image, pan sharpened (Uses the visual bands, 321 mapping), gamma 1.5'}, 'pseudo_low': {'title': 'Pseudo-color image, pan sharpened (Uses IR and Visual bands, 542 mapping)'}, 'visual_low': {'title': 'Real-color image, pan sharpened (Uses the visual bands, 321 mapping)'}, 'visual_bright': {'title': 'Real-color image (Uses the visual bands, 321 mapping), gamma 1.5'}} 
     37     
    5538Expect a KeyError for invalid names 
    5639 
     
    6043    KeyError: 'No content named utterly bogus' 
    6144 
     45Test operations 
     46 
     47    >>> [op.name for op in wms.capabilities.operations] 
     48    ['GetCapabilities', 'GetMap'] 
     49    >>> wms.capabilities.getOperationByName('GetMap').methods 
     50    {'Get': {'url': 'http://wms.jpl.nasa.gov/wms.cgi?'}} 
     51    >>> wms.capabilities.getOperationByName('GetMap').formatOptions 
     52    ['image/jpeg', 'image/png', 'image/geotiff', 'image/tiff'] 
     53 
     54Test exceptions 
     55 
     56    >>> wms.capabilities.exceptions 
     57    ['application/vnd.ogc.se_xml'] 
     58