File: test_wms_jpl_capabilities.py

package info (click to toggle)
owslib 0.33.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 10,620 kB
  • sloc: xml: 140,558; python: 24,274; makefile: 15
file content (109 lines) | stat: -rw-r--r-- 5,339 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from tests.utils import service_ok
from tests.utils import resource_file

from owslib.wms import WebMapService
import os
from collections import OrderedDict

import pytest


def test_wms_capabilities():
    # 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
    # -----------------

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

    # Check contact info (some of it is missing)
    assert wms.provider.contact.name == 'Lucian Plesea'
    assert 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
    assert wms.provider.contact.organization == 'JPL'
    wms.provider.contact.position

    # Test available content layers
    assert isinstance(wms.items(), list) is True
    assert isinstance(wms.contents, OrderedDict) is True

    # NOTE: Not sure this dictionary interface is right...??
    assert 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']

    assert 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
    assert wms['global_mosaic'].title == 'WMS Global Mosaic, pan sharpened'
    assert wms['global_mosaic'].keywords == []

    ['GlobalMosaic', 'Imagery', 'BaseMaps', 'EarthCover', 'JPL', 'Jet Propulsion Laboratory',
     'Landsat', 'WMS', 'SLD', 'Global']

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

    x = wms['global_mosaic'].styles
    assert 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'},  # noqa
                 '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'}}

    # Expecting a KeyError for invalid names
    with pytest.raises(KeyError):
        wms['utterly bogus'].title
        pytest.fail("Expecting a KeyError for invalid names")

    # Test operations
    assert sorted([op.name for op in wms.operations]) == ['GetCapabilities', 'GetMap', 'GetTileService']

    x = wms.getOperationByName('GetMap').methods
    assert x == [{'type': 'Get', 'url': 'http://wms.jpl.nasa.gov/wms.cgi?'}]

    assert wms.getOperationByName('GetMap').formatOptions == ['image/jpeg', 'image/png', 'image/geotiff',
                                                              'image/tiff', 'application/vnd.google-earth.kml+xml']

    # Test exceptions
    assert wms.exceptions == ['application/vnd.ogc.se_xml']


def test_wms_capabilities_style_without_title():
    xml = open(resource_file('wms_geoserver-cap_no_title.xml'), 'rb').read()
    wms = WebMapService('url', version='1.1.1', xml=xml)


SERVICE_URL = 'http://giswebservices.massgis.state.ma.us/geoserver/wms'


@pytest.mark.xfail(reason="online test")
@pytest.mark.online
def test_wms_getmap():
    assert service_ok(SERVICE_URL)
    # Lastly, test the getcapabilities and getmap methods
    wms = WebMapService(SERVICE_URL, version='1.1.1')