
Imports

    >>> from __future__ import (absolute_import, division, print_function)
    >>> from owslib.wms import WebMapService
    >>> from tests.utils import resource_file
    >>> import os
    
Fake a request to a WMS Server using saved doc from 
http://wms.jpl.nasa.gov/wms.cgi.

    >>> xml = open(resource_file('wms_JPLCapabilities.xml'), 'rb').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
    >>> isinstance(wms.items(), list)
    True
    >>> type(wms.contents)
    <class '...OrderedDict'>

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

    >>> sorted(wms.contents.keys())
    ['BMNG', 'daily_afternoon', 'daily_planet', 'gdem', '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_afternoon', 'daily_planet', 'gdem', '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)
    
    >>> sorted(wms['global_mosaic'].crsOptions)
    ['AUTO:42003', 'EPSG:4326']

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

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

Test operations

    >>> sorted([op.name for op in wms.operations])
    ['GetCapabilities', 'GetMap', 'GetTileService']

    >>> x = wms.getOperationByName('GetMap').methods
    >>> x == [{'type': 'Get', 'url': 'http://wms.jpl.nasa.gov/wms.cgi?'}]
    True
    
    >>> wms.getOperationByName('GetMap').formatOptions
    ['image/jpeg', 'image/png', 'image/geotiff', 'image/tiff', 'application/vnd.google-earth.kml+xml']

Test exceptions

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

Lastly, test the getcapabilities and getmap methods

    >>> wms = WebMapService('http://giswebservices.massgis.state.ma.us/geoserver/wms', version='1.1.1')
