
Imports

    >>> from owslib.wms import WebMapService
    
Fake a request to a WMS Server using saved doc from 
http://wms.jpl.nasa.gov/wms.cgi.

    >>> xml = open('JPLCapabilities.xml', 'r').read() 
    >>> wms = WebMapService('url', version='1.1.1', xml=xml)
    
Test capabilities
-----------------

    >>> wms.identification.type
    'OGC:WMS'
    >>> wms.identification.version
    '1.1.1'
    >>> wms.identification.title
    'JPL Global Imagery Service'
    >>> wms.identification.abstract
    'WMS Server maintained by JPL, worldwide satellite imagery.'
    >>> wms.identification.keywords
    ['ImageryBaseMapsEarthCover', 'Imagery', 'BaseMaps', 'EarthCover', 'JPL', 'Jet Propulsion Laboratory', 'Landsat', 'WMS', 'SLD', 'Global']
    >>> wms.identification.accessconstraints
    'Server is load limited'
    >>> wms.identification.fees
    'none'
    >>> wms.provider.name
    'JPL'
    >>> wms.provider.url
    'http://OnEarth.jpl.nasa.gov/index.html'

Check contact info (some of it is missing)
    >>> wms.provider.contact.name
    'Lucian Plesea'
    >>> wms.provider.contact.email
    'lucian.plesea@jpl.nasa.gov'
    >>> wms.provider.contact.address
    >>> wms.provider.contact.city
    >>> wms.provider.contact.country
    >>> wms.provider.contact.region
    >>> wms.provider.contact.postcode
    >>> wms.provider.contact.organization
    'JPL'
    >>> wms.provider.contact.position

    
Test available content layers
    >>> type(wms.items())
    <type 'list'>
    >>> type(wms.contents)
    <type 'dict'>

NOTE: Not sure this dictionary interface is right...??

    >>> sorted(wms.contents.keys())
    ['BMNG', 'daily_aqua', 'daily_aqua_721', 'daily_aqua_ndvi', 'daily_terra', 'daily_terra_721', 'daily_terra_ndvi', 'global_mosaic', 'global_mosaic_base', 'huemapped_srtm', 'modis', 'srtm_mag', 'srtmplus', 'us_colordem', 'us_elevation', 'us_landsat_wgs84', 'us_ned', 'worldwind_dem']

    >>> sorted([wms[layer].id for layer in wms.contents])
    ['BMNG', 'daily_aqua', 'daily_aqua_721', 'daily_aqua_ndvi', 'daily_terra', 'daily_terra_721', 'daily_terra_ndvi', 'global_mosaic', 'global_mosaic_base', 'huemapped_srtm', 'modis', 'srtm_mag', 'srtmplus', 'us_colordem', 'us_elevation', 'us_landsat_wgs84', 'us_ned', 'worldwind_dem']

 
Test single item accessor
    
    >>> wms['global_mosaic'].title
    'WMS Global Mosaic, pan sharpened'

    >>> wms['global_mosaic'].keywords
    []
    
['GlobalMosaic', 'Imagery', 'BaseMaps', 'EarthCover', 'JPL', 'Jet Propulsion Laboratory', 'Landsat', 'WMS', 'SLD', 'Global']

    >>> wms['global_mosaic'].boundingBox

    >>> wms['global_mosaic'].boundingBoxWGS84
    (-180.0, -60.0, 180.0, 84.0)
    
    >>> wms['global_mosaic'].crsOptions
    ['AUTO:42003', 'EPSG:4326']

    
    >>> wms['global_mosaic'].styles
    {'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'}}
    
Expect a KeyError for invalid names

    >>> wms['utterly bogus'].title
    Traceback (most recent call last):
    ...
    KeyError: 'No content named utterly bogus'

Test operations

    >>> [op.name for op in wms.operations]
    ['GetCapabilities', 'GetMap']
    
    >>> wms.getOperationByName('GetMap').methods
    {'Get': {'url': 'http://wms.jpl.nasa.gov/wms.cgi?'}}
    
    >>> wms.getOperationByName('GetMap').formatOptions
    ['image/jpeg', 'image/png', 'image/geotiff', 'image/tiff']

Test exceptions

    >>> wms.exceptions
    ['application/vnd.ogc.se_xml']

Lastly, test the getcapabilities and getmap methods

    >>> wms = WebMapService('http://wms.jpl.nasa.gov/wms.cgi', version='1.1.1')
    >>> img = wms.getmap(   layers=['global_mosaic'], styles=['visual_bright'],                  srs='EPSG:4326', bbox=(-112, 36, -106, 41), size=(300, 250), format='image/jpeg',         transparent=True)
    >>> out = open('jpl_mosaic_visb.jpg', 'wb')
    >>> out.write(img.read())
    >>> out.close()
