1# Project: MapServer 2# Purpose: xUnit style Python mapscript tests of OWS Requests 3# Author: Sean Gillies, sgillies@frii.com 4# 5# =========================================================================== 6# Copyright (c) 2004, Sean Gillies 7# 8# Permission is hereby granted, free of charge, to any person obtaining a 9# copy of this software and associated documentation files (the "Software"), 10# to deal in the Software without restriction, including without limitation 11# the rights to use, copy, modify, merge, publish, distribute, sublicense, 12# and/or sell copies of the Software, and to permit persons to whom the 13# Software is furnished to do so, subject to the following conditions: 14# 15# The above copyright notice and this permission notice shall be included 16# in all copies or substantial portions of the Software. 17# 18# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24# DEALINGS IN THE SOFTWARE. 25# =========================================================================== 26 27import unittest 28import mapscript 29from .testing import MapTestCase 30 31 32class OWSRequestTestCase(MapTestCase): 33 34 def testInit(self): 35 """OWSRequestTestCase.testInit: OWS initializer works right""" 36 request = mapscript.OWSRequest() 37 request.setParameter("BBOX", "-0.3, 51.2, 0.3, 51.8") 38 assert request.NumParams == 1 39 assert request.getName(0) == "BBOX" 40 assert request.getValue(0) == "-0.3, 51.2, 0.3, 51.8" 41 42 def testGetParameter(self): 43 """OWSRequestTestCase.testGetParameter: OWS can get request parameters by index""" 44 request = mapscript.OWSRequest() 45 request.setParameter('foo', 'bar') 46 assert request.getValue(0) == 'bar' 47 48 def testGetParameterByName(self): 49 """OWSRequestTestCase.testGetParameterByName: OWS can get request parameters by name""" 50 request = mapscript.OWSRequest() 51 request.setParameter('foo', 'bar') 52 assert request.getValueByName('Foo') == 'bar' 53 54 def testResetParam(self): 55 """OWSRequestTestCase.testResetParam: OWS can reset parameters by name""" 56 request = mapscript.OWSRequest() 57 request.setParameter('foo', 'bar') 58 assert request.NumParams == 1 59 request.setParameter('Foo', 'bra') 60 assert request.NumParams == 1 61 assert request.getValue(0) == 'bra' 62 63 def testLoadWMSRequest(self): 64 """OWSRequestTestCase.testLoadWMSRequest: OWS can load a WMS request""" 65 request = mapscript.OWSRequest() 66 request.setParameter("REQUEST", "GetMap") 67 request.setParameter("VERSION", "1.1.0") 68 request.setParameter("FORMAT", "image/png") 69 request.setParameter("LAYERS", "POINT") 70 request.setParameter("BBOX", "-0.30, 51.20, 0.30, 51.80") 71 request.setParameter("SRS", "EPSG:4326") 72 request.setParameter("HEIGHT", "60") 73 request.setParameter("WIDTH", "60") 74 request.setParameter("STYLES", "") 75 for i in range(self.map.numlayers): 76 self.map.getLayer(i).status = mapscript.MS_ON 77 status = self.map.loadOWSParameters(request) 78 assert status == mapscript.MS_SUCCESS, status 79 self.assertEqual(self.map.height, 60) 80 self.assertEqual(self.map.width, 60) 81 self.assertEqual(self.map.getProjection(), "+init=epsg:4326") 82 # MapServer extents are from middle of the pixel 83 self.assertAlmostEqual(self.map.extent.minx, -0.295) 84 self.assertAlmostEqual(self.map.extent.miny, 51.205) 85 self.assertAlmostEqual(self.map.extent.maxx, 0.295) 86 self.assertAlmostEqual(self.map.extent.maxy, 51.795) 87 img = self.map.draw() 88 img.save("test_load_ows_request.png") 89 90 91if __name__ == '__main__': 92 unittest.main() 93