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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
import pytest
from tests.utils import service_ok
from owslib.wms import WebMapService
from owslib.util import ServiceException
from owslib.util import ResponseWrapper
SERVICE_URL = 'http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r-t.cgi'
NCWMS2_URL = "http://wms.stccmop.org:8080/ncWMS2/wms"
@pytest.mark.online
@pytest.mark.skipif(not service_ok(SERVICE_URL),
reason="WMS service is unreachable")
def test_wms_getmap_111():
"""MESONET GetMap 1.1.1"""
wms = WebMapService(SERVICE_URL, version='1.1.1')
assert wms.request == '{}?service=WMS&request=GetCapabilities&version=1.1.1'.format(SERVICE_URL)
rsp = wms.getmap(
layers=['nexrad_base_reflect'],
styles=['default'],
srs='EPSG:4326',
bbox=(-126, 24, -66, 50),
size=(250, 250),
format='image/jpeg',
transparent=True)
import owslib.util
assert type(rsp) is ResponseWrapper
@pytest.mark.online
@pytest.mark.skipif(not service_ok(SERVICE_URL),
reason="WMS service is unreachable")
def test_wms_getmap_111_service_exception():
"""GetMap 1.1.1 ServiceException for an invalid CRS"""
wms = WebMapService(SERVICE_URL, version='1.1.1')
try:
wms.getmap(
layers=['nexrad_base_reflect'],
styles=['default'],
srs='EPSG:4328',
bbox=(-126, 24, -66, 50),
size=(250, 250),
format='image/jpeg',
transparent=True)
except ServiceException as e:
assert "msWMSLoadGetMapParams(): WMS server error. Invalid SRS given : SRS must be valid for all requested layers." in str(e) # noqa
else:
assert False
@pytest.mark.online
@pytest.mark.skipif(not service_ok(SERVICE_URL),
reason="WMS service is unreachable")
def test_wms_getmap_130():
"""GetMap 1.3.0"""
wms = WebMapService(SERVICE_URL, version='1.3.0')
rsp = wms.getmap(
layers=['nexrad_base_reflect'],
styles=['default'],
srs='EPSG:4326',
bbox=(-126, 24, -66, 50),
size=(250, 250),
format='image/jpeg',
transparent=True)
assert type(rsp) is ResponseWrapper
@pytest.mark.online
@pytest.mark.skipif(not service_ok(SERVICE_URL),
reason="WMS service is unreachable")
def test_wms_getmap_130_service_exception():
"""GetMap 1.3.0 ServiceException for an invalid CRS"""
wms = WebMapService(SERVICE_URL, version='1.3.0')
try:
wms.getmap(
layers=['nexrad_base_reflect'],
styles=['default'],
srs='EPSG:4328',
bbox=(-126, 24, -66, 50),
size=(250, 250),
format='image/jpeg',
transparent=True)
except ServiceException as e:
assert "msWMSLoadGetMapParams(): WMS server error. Invalid CRS given : CRS must be valid for all requested layers." in str(e) # noqa
else:
assert False
SERVICE_URL_NATIONAL_MAP = 'http://services.nationalmap.gov/ArcGIS/services/geonames/MapServer/WMSServer'
@pytest.mark.online
@pytest.mark.skip(reason="this is a flaky test")
# @pytest.mark.skipif(not service_ok(SERVICE_URL_NATIONAL_MAP),
# reason="WMS service is unreachable")
def test_getmap_130_national_map():
"""National Map"""
# TODO: use flaky tests or fix it: https://pypi.python.org/pypi/pytest-ignore-flaky
url = SERVICE_URL_NATIONAL_MAP
wms = WebMapService(url, version='1.3.0')
rsp = wms.getmap(
layers=['3'],
styles=['default'],
srs='CRS:84',
bbox=(-176.646, 17.7016, -64.8017, 71.2854),
size=(500, 300),
format='image/png',
transparent=True)
assert type(rsp) is ResponseWrapper
assert "service=WMS" in wms.request
assert "version=1.3.0" in wms.request
assert "request=GetMap" in wms.request
assert "layers=3" in wms.request
assert "styles=default" in wms.request
assert "crs=CRS%3A84" in wms.request
assert "box=-176.646%2C17.7016%2C-64.8017%2C71.2854" in wms.request
assert "width=500" in wms.request
assert "height=300" in wms.request
assert "format=image%2Fpng" in wms.request
assert "transparent=TRUE" in wms.request
@pytest.mark.online
@pytest.mark.skipif(not service_ok(NCWMS2_URL), reason="WMS service is unreachable")
def test_ncwms2():
"""Test with an ncWMS2 server.
"""
# Note that this does not exercise the bug in https://github.com/geopython/OWSLib/issues/556
wms = WebMapService(NCWMS2_URL, version='1.3.0')
rsp = wms.getmap(
layers=['f33_thredds/min_temp'],
styles=['default'],
srs='CRS:84',
bbox=(-124.17, 46.02, -123.29, 46.38),
size=(256, 256),
format='image/png',
transparent=True,
mode='32bit',
)
assert type(rsp) is ResponseWrapper
assert "service=WMS" in wms.request
assert "version=1.3.0" in wms.request
assert "request=GetMap" in wms.request
assert "layers=f33_thredds/min_temp" in wms.request
assert "styles=default" in wms.request
assert "crs=CRS%3A84" in wms.request
assert "width=256" in wms.request
assert "height=256" in wms.request
assert "format=image%2Fpng" in wms.request
assert "transparent=TRUE" in wms.request
|