66from PIL import Image
77
88import requests_mock
9- import cartopy .mpl .geoaxes
10- from cartopy .tests .mpl import ImageTesting
11- import responses
129
1310from geoengine .types import QueryRectangle
1411import geoengine as ge
@@ -20,93 +17,6 @@ class WmsTests(unittest.TestCase):
2017 def setUp (self ) -> None :
2118 ge .reset ()
2219
23- @responses .activate
24- @ImageTesting (['wms' ], tolerance = 0 )
25- def test_ndvi (self ):
26- with requests_mock .Mocker () as m , open ("tests/responses/4326.gml" , "rb" ) as epsg4326_gml :
27- m .post ('http://mock-instance/anonymous' , json = {
28- "id" : "c4983c3e-9b53-47ae-bda9-382223bd5081" ,
29- "project" : None ,
30- "view" : None
31- })
32-
33- m .post ('http://mock-instance/workflow' ,
34- json = {
35- "id" : "5b9508a8-bd34-5a1c-acd6-75bb832d2d38"
36- },
37- request_headers = {'Authorization' : 'Bearer c4983c3e-9b53-47ae-bda9-382223bd5081' })
38-
39- m .get ('http://mock-instance/workflow/5b9508a8-bd34-5a1c-acd6-75bb832d2d38/metadata' ,
40- json = {
41- "type" : "raster" ,
42- "dataType" : "U8" ,
43- "spatialReference" : "EPSG:4326" ,
44- "measurement" : {
45- "type" : "unitless"
46- },
47- "noDataValue" : 0.0
48- },
49- request_headers = {'Authorization' : 'Bearer c4983c3e-9b53-47ae-bda9-382223bd5081' })
50-
51- m .get ('http://epsg.io/4326.gml?download' , body = epsg4326_gml )
52-
53- # Unfortunately, we need a separate library to catch the request from the WMS call
54- with open ("tests/responses/wms_capabilities.xml" , "r" , encoding = "utf-8" ) as wms_capabilities :
55- m .get (
56- # pylint: disable=line-too-long
57- 'http://mock-instance/wms/5b9508a8-bd34-5a1c-acd6-75bb832d2d38?service=WMS&request=GetCapabilities&version=1.3.0' ,
58- text = wms_capabilities .read ())
59-
60- with open ("tests/responses/wms-ndvi.png" , "rb" ) as wms_ndvi :
61- responses .add (
62- # pylint: disable=line-too-long
63- 'GET' ,
64- 'http://mock-instance/wms/5b9508a8-bd34-5a1c-acd6-75bb832d2d38?service=WMS&version=1.3.0&request=GetMap&layers=5b9508a8-bd34-5a1c-acd6-75bb832d2d38&styles=&width=620&height=310&crs=EPSG:4326&bbox=-90.0,-180.0,90.0,180.0&format=image/png&transparent=FALSE&bgcolor=0xFFFFFF&exceptions=XML&time=2014-04-01T12%3A00%3A00.000%2B00%3A00' ,
65- match_querystring = True ,
66- body = wms_ndvi .read (),
67- content_type = 'image/png'
68- )
69-
70- ge .initialize ("http://mock-instance" )
71-
72- workflow_definition = {
73- "type" : "Raster" ,
74- "operator" : {
75- "type" : "GdalSource" ,
76- "params" : {
77- "dataset" : {
78- "type" : "internal" ,
79- "datasetId" : "36574dc3-560a-4b09-9d22-d5945f2b8093"
80- }
81- }
82- }
83- }
84-
85- time = datetime .strptime (
86- '2014-04-01T12:00:00.000Z' , "%Y-%m-%dT%H:%M:%S.%f%z" )
87-
88- workflow = ge .register_workflow (workflow_definition )
89-
90- ax = workflow .plot_image (
91- QueryRectangle (
92- [- 180.0 , - 90.0 , 180.0 , 90.0 ],
93- [time , time ]
94- )
95- )
96-
97- ax .plot ()
98-
99- self .assertEqual (type (ax ), cartopy .mpl .geoaxes .GeoAxesSubplot )
100-
101- # Check requests from the mocker
102- self .assertEqual (len (m .request_history ), 5 )
103-
104- workflow_request = m .request_history [1 ]
105- self .assertEqual (workflow_request .method , "POST" )
106- self .assertEqual (workflow_request .url ,
107- "http://mock-instance/workflow" )
108- self .assertEqual (workflow_request .json (), workflow_definition )
109-
11020 def test_ndvi_image (self ):
11121 with requests_mock .Mocker () as m ,\
11222 open ("tests/responses/wms-ndvi.png" , "rb" ) as ndvi_png ,\
0 commit comments