
Imports

    >>> from owslib.wms import WebMapService
    >>> from tests.utils import cast_tuple_int_list, cast_tuple_int_list_srs, resource_file, scratch_file
    >>> import os
    
Fake a request to a GeoServer WMS Server using saved doc from 
http://gis-prod.digital.mass.gov/geoserver/wms

    >>> xml = open(resource_file('wms_mass_gis-caps.xml'), 'rb').read()
    >>> wms = WebMapService('url', version='1.1.1', xml=xml)
    
Test capabilities
-----------------


    >>> wms.updateSequence is not None
    True
    >>> wms.identification.type
    'OGC:WMS'
    >>> wms.identification.version
    '1.1.1'
    >>> wms.identification.title
    'Massachusetts Data from MassGIS (GeoServer)'
    >>> wms.identification.abstract
    'Statewide Massachusetts data served by MassGIS via GeoServer.'
    >>> wms.identification.keywords
    ['WMS', 'GEOSERVER', 'Massachusetts', 'MassGIS']
    >>> wms.identification.accessconstraints
    'NONE'
    >>> wms.identification.fees
    'NONE'
    >>> wms.provider.url
    'http://giswebservices.massgis.state.ma.us/geoserver/wms'


Check contact info (some of it is missing)
    >>> wms.provider.contact.name
    'Aleda Freeman'
    >>> wms.provider.contact.email
    'aleda.freeman@state.ma.us'
    >>> wms.provider.contact.address
    '1 Ashburton Pl, Room 1601'
    >>> wms.provider.contact.city
    'Boston'
    >>> wms.provider.contact.country
    'USA'
    >>> wms.provider.contact.region
    'MA'
    >>> wms.provider.contact.postcode
    '02114'
    >>> wms.provider.contact.organization
    'MassGIS - Information Technology Division'
    >>> wms.provider.contact.position
    'GIS Programmer'

Test available content layers
    >>> isinstance(wms.items(), list)
    True
    >>> type(wms.contents)
    <class '...OrderedDict'>

 
Test single item accessor
    
    >>> wms['massgis:GISDATA.SHORELINES_ARC'].title
    'Shoreline Change'

    >>> wms['massgis:GISDATA.SHORELINES_ARC'].keywords
    ['MassgisMetadataUrl=http://maps.massgis.digital.mass.gov/czm/moris/metadata/moris_shorelines_arc.html', 'Change', 'GISDATA.SHORELINES_ARC', 'Shoreline', 'pg_gisdata']

    >>> cast_tuple_int_list_srs(wms['massgis:GISDATA.SHORELINES_ARC'].boundingBox)
    [231474, 777443, 331004, 958511, 'EPSG:26986']

    >>> cast_tuple_int_list(wms['massgis:GISDATA.SHORELINES_ARC'].boundingBoxWGS84)
    [-71, 41, -69, 42]
    
    >>> x = wms['massgis:GISDATA.SHORELINES_ARC'].styles
    >>> x == {'GISDATA.SHORELINES_ARC::Default': {'title': 'GISDATA.SHORELINES_ARC::Default', 'legend': 'https://gis-prod.digital.mass.gov/geoserver/wms?request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=massgis%3AGISDATA.SHORELINES_ARC'}}
    True
    
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', 'GetFeatureInfo', 'DescribeLayer', 'GetLegendGraphic', 'GetStyles']
    
    >>> x = wms.getOperationByName('GetMap').methods
    >>> x == [{'type': 'Get', 'url': 'https://gis-prod.digital.mass.gov/geoserver/wms?SERVICE=WMS&'}]
    True
    
    >>> len(wms.getOperationByName('GetMap').formatOptions)
    41

Test exceptions

    >>> wms.exceptions
    ['application/vnd.ogc.se_xml', 'application/vnd.ogc.se_inimage', 'application/vnd.ogc.se_blank', 'application/json', 'text/javascript']


Lastly, test the getcapabilities and getmap methods

    >>> wms = WebMapService('http://gis-prod.digital.mass.gov/geoserver/wms', version='1.1.1', timeout=120)
    >>> img = wms.getmap(layers=['massgis:GISDATA.SHORELINES_ARC'], styles=[''], srs='EPSG:4326', bbox=(-70.8, 42, -70, 42.8), size=(300, 300), format='image/jpeg', transparent=True)
    >>> out = open(scratch_file('massgis_shoreline.jpg'), 'wb')
    >>> bytes_written = out.write(img.read())
    >>> out.close()
