/[thuban]/branches/WIP-pyshapelib-bramz/Extensions/wms/test/test_ogclib.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/Extensions/wms/test/test_ogclib.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2734 - (hide annotations)
Thu Mar 1 12:42:59 2007 UTC (18 years ago) by bramz
File MIME type: text/x-python
File size: 9919 byte(s)
made a copy
1 joey 2108 # Copyright (c) 2004 by Intevation GmbH
2     # Authors:
3     # Martin Schulze <[email protected]>
4     #
5     # This program is free software under the GPL (>=v2)
6     # Read the file COPYING coming with Thuban for details.
7    
8     """
9 joey 2112 Test for the PyOGCLib from Sean C. Gillies <[email protected]>
10 joey 2108
11     http://www.sourceforge.net/projects/pyogclib
12    
13 joey 2113 Requires the ogclib installed regularily on the system, accessible via
14     PYTHONPATH or checked out alongside the Thuban checkout.
15 joey 2108 """
16    
17     __version__ = "$Revision$"
18     # $Source$
19     # $Id$
20    
21     import os
22     import unittest
23    
24     from string import split
25 joey 2113 from sys import path
26 joey 2108
27 joey 2116 from adjustpath import thubandir
28 joey 2118 path.insert(0, thubandir + "/test")
29 joey 2113
30 joey 2116 import support
31    
32 joey 2108 # ----------------------------------------------------------------------
33     # FIXME: Temporary code until PyOGCLib is a standard requirement
34    
35     from sys import path
36    
37     # Assume the PyOGCLib to be checked out next to the thuban main directory
38 joey 2113 # setting PYTHONPATH accordingly is fine as well
39     #
40 joey 2118 pyogclib = os.path.abspath(thubandir + "/../PyOGCLib")
41     if os.path.isdir(pyogclib) and os.path.isdir(pyogclib + "/ogclib"):
42     path.insert(0, pyogclib)
43 joey 2108 # ----------------------------------------------------------------------
44    
45 joey 2116 _pyogclib_import_error = None
46 joey 2108 try:
47     from ogclib.WMSClient import WMSClient
48 joey 2116 except ImportError, extra:
49     _pyogclib_import_error = str(extra)
50 joey 2108
51    
52 joey 2118 class TestOGCLib(unittest.TestCase):
53 joey 2108 """
54     Defines a test environment for the PyOGCLib, i.e. check whether URL
55     strings are built properly.
56     """
57    
58 joey 2116 wmsclient = None
59    
60 joey 2118 def setUp(self):
61 joey 2116 skip_if_no_ogclib()
62     self.wmsclient = WMSClient()
63    
64 joey 2118 def compare_URLs(self, foo, bar):
65 joey 2108 """
66     Check if two URLs are equal, i.e.:
67     - check for same base URL
68     - check same number of HTTP GET arguments
69     - check whether all arguments from one URL also exist in the second
70     """
71    
72 joey 2118 foo_tuple = split(foo, "?")
73     bar_tuple = split(bar, "?")
74 joey 2108
75     # Check for same base URL
76     if foo_tuple[0] != bar_tuple[0]:
77 joey 2118 self.fail("%s != %s" %(foo_tuple[0], bar_tuple[0]))
78 joey 2108
79 joey 2336 # Check for same length of entire HTTP GET argument string
80 joey 2108 if len(foo_tuple) != len(bar_tuple):
81 joey 2118 self.fail("One URL has no arguments");
82 joey 2108
83     # Loop through all HTTP GET arguments for existance
84     if len(foo_tuple) > 1 and len(bar_tuple) > 1:
85 joey 2118 foo_opts = split(foo_tuple[1], "&")
86     bar_opts = split(bar_tuple[1], "&")
87 joey 2108
88     if len(foo_opts) != len(bar_opts):
89 joey 2118 self.fail("Different number of arguments");
90 joey 2108
91     for part in foo_opts:
92     if part not in bar_opts:
93 joey 2118 self.fail("%s not in second argument list" % part);
94 joey 2108
95    
96 joey 2118 def test_compareURLs(self):
97 joey 2108 """Perform some tests for own compare routine"""
98    
99 joey 2430 # Compare same base URL
100 joey 2108 result = "http://frida.intevation.org/cgi-bin"
101 joey 2118 self.compare_URLs("http://frida.intevation.org/cgi-bin", result)
102 joey 2108
103 joey 2430 # Compare different base URL with same length
104     self.assertRaises(AssertionError, self.compare_URLs, "http://frida.intevation.org/cgi-lib", result)
105    
106     # Compare same bse with one argument
107 joey 2108 result = "http://frida.intevation.org/cgi-bin?foo=eins"
108 joey 2118 self.compare_URLs("http://frida.intevation.org/cgi-bin?foo=eins", result)
109 joey 2108
110 joey 2430 # Compare same base URL differnt first argument
111     self.assertRaises(AssertionError, self.compare_URLs, "http://frida.intevation.org/cgi-bin?bar=eins", result)
112    
113     # Compare same base with two arguments
114 joey 2108 result = "http://frida.intevation.org/cgi-bin?foo=eins&bar=zwei"
115 joey 2118 self.compare_URLs("http://frida.intevation.org/cgi-bin?foo=eins&bar=zwei", result)
116     self.compare_URLs("http://frida.intevation.org/cgi-bin?bar=zwei&foo=eins", result)
117 joey 2108
118 joey 2430 # Compare same base with different two arguments
119     self.assertRaises(AssertionError, self.compare_URLs, "http://frida.intevation.org/cgi-bin?foo=zwei&bar=eins", result)
120    
121     # Compare same base with three arguments
122 joey 2108 result = "http://frida.intevation.org/cgi-bin?foo=eins&bar=zwei&baz=jan&quux=tux"
123 joey 2430 self.compare_URLs("http://frida.intevation.org/cgi-bin?foo=eins&bar=zwei&baz=jan&quux=tux", result)
124 joey 2118 self.compare_URLs("http://frida.intevation.org/cgi-bin?baz=jan&bar=zwei&quux=tux&foo=eins", result)
125 joey 2108
126 joey 2430 # Compare same base with different three arguments
127     testurl = "http://frida.intevation.org/cgi-bin?baz=jan&foo=zwei&quux=tux&bar=eins"
128     self.assertRaises(AssertionError, self.compare_URLs, testurl, result)
129 joey 2108
130 joey 2430
131 joey 2118 def test_CapabilityURL(self):
132 joey 2108 """Test the getCapabilitiesURL() method"""
133    
134     frida = "http://frida.intevation.org/cgi-bin/frida_wms?"
135    
136 joey 2116 url = self.wmsclient.getCapabilitiesURL(frida, "1.0")
137 joey 2108 result = frida + "WMTVER=1.0&REQUEST=capabilities"
138 joey 2118 self.compare_URLs(url, result)
139 joey 2108
140 joey 2116 url = self.wmsclient.getCapabilitiesURL(frida, "1.1")
141 joey 2108 result = frida + "VERSION=1.1&SERVICE=WMS&REQUEST=GetCapabilities"
142 joey 2118 self.compare_URLs(url, result)
143 joey 2108
144    
145 joey 2118 def test_GetMapURL(self):
146 joey 2109 """Test the getMapURL() method"""
147    
148     frida = "http://frida.intevation.org/cgi-bin/frida_wms?"
149    
150 joey 2112 format = 'image/jpeg'
151     format_enc = 'image%2Fjpeg'
152 joey 2109 width = 400
153     height = 350
154     epsg = 4326
155     bbox = {'minx': -107, 'miny': 40, 'maxx': -109, 'maxy': 41}
156     layers = [ ]
157     styles = [ ]
158     version = '1.1'
159    
160     result_base = frida + "WMTVER=1.0&REQUEST=map" + \
161 joey 2112 "&FORMAT="+format_enc + \
162 joey 2118 "&SRS=EPSG%s%d" %("%3A", epsg) + \
163     "&BBOX=%f%s%f%s%f%s%f" %(bbox['minx'], "%2C", bbox['miny'], "%2C",
164 joey 2109 bbox['maxx'], "%2C", bbox['maxy']) + \
165     "&WIDTH=%s" % width + "&HEIGHT=%s" % height
166     result = result_base + \
167     "&LAYERS=" + "%2C".join(layers) + \
168     "&STYLES=" + "%2C".join(styles)
169 joey 2116 url = self.wmsclient.getMapURL(frida, format, width, height, epsg,
170 joey 2109 bbox, layers, version=version)
171    
172     # Repeat and continue with version 1.1, as denoted in OGC 01-068r3
173     version = '1.1'
174     result_base = frida + "VERSION=1.1&SERVICE=WMS&REQUEST=GetMap" + \
175 joey 2112 "&FORMAT="+format_enc + \
176 joey 2118 "&SRS=EPSG%s%d" %("%3A", epsg) + \
177     "&BBOX=%f%s%f%s%f%s%f" %(bbox['minx'], "%2C", bbox['miny'], "%2C",
178 joey 2109 bbox['maxx'], "%2C", bbox['maxy']) + \
179     "&WIDTH=%s" % width + "&HEIGHT=%s" % height
180     result = result_base + \
181     "&LAYERS=" + "%2C".join(layers) + \
182     "&STYLES=" + "%2C".join(styles)
183 joey 2116 url = self.wmsclient.getMapURL(frida, format, width, height, epsg,
184 joey 2109 bbox, layers, version=version)
185 joey 2118 self.compare_URLs(result, url)
186 joey 2109
187     result += "&TRANSPARENT=TRUE"
188 joey 2116 url = self.wmsclient.getMapURL(frida, format, width, height, epsg,
189 joey 2109 bbox, layers, version=version,
190     transparent=1 )
191 joey 2118 self.compare_URLs(result, url)
192 joey 2109
193     result += "&BGCOLOR=0xFF00FF"
194 joey 2116 url = self.wmsclient.getMapURL(frida, format, width, height, epsg,
195 joey 2109 bbox, layers, version=version,
196     transparent=1, bgcolor='0xFF00FF')
197 joey 2118 self.compare_URLs(result, url)
198 joey 2109
199     layers = [ 'foo' ]
200     result = result_base + \
201     "&LAYERS=" + "%2C".join(layers) + \
202     "&STYLES=" + "%2C".join(styles)
203 joey 2116 url = self.wmsclient.getMapURL(frida, format, width, height, epsg,
204 joey 2109 bbox, layers, version=version)
205 joey 2118 self.compare_URLs(result, url)
206 joey 2109
207 joey 2118 layers.append('bar')
208 joey 2109 result = result_base + \
209     "&LAYERS=" + "%2C".join(layers) + \
210     "&STYLES=" + "%2C".join(styles)
211 joey 2116 url = self.wmsclient.getMapURL(frida, format, width, height, epsg,
212 joey 2109 bbox, layers, version=version)
213 joey 2118 self.compare_URLs(result, url)
214 joey 2109
215     styles = [ 'something' ]
216     result = result_base + \
217     "&LAYERS=" + "%2C".join(layers) + \
218     "&STYLES=" + "%2C".join(styles)
219 joey 2116 url = self.wmsclient.getMapURL(frida, format, width, height, epsg,
220 joey 2109 bbox, layers, version=version,
221     styles = styles)
222 joey 2118 self.compare_URLs(result, url)
223 joey 2109
224 joey 2118 styles.append('else')
225 joey 2109 result = result_base + \
226     "&LAYERS=" + "%2C".join(layers) + \
227     "&STYLES=" + "%2C".join(styles)
228 joey 2116 url = self.wmsclient.getMapURL(frida, format, width, height, epsg,
229 joey 2109 bbox, layers, version=version,
230     styles = styles)
231 joey 2118 self.compare_URLs(result, url)
232 joey 2109
233    
234 joey 2116 def skip_if_no_ogclib():
235     if _pyogclib_import_error is not None:
236     raise support.SkipTest(_pyogclib_import_error)
237     # raise support.SkipTest("No PyOGCLib found, hence no tests available.")
238    
239    
240 joey 2108 if __name__ == "__main__":
241 joey 2116 support.run_tests()
242 joey 2109
243     """
244    
245     Additional notes:
246     - Parameter names shall not be case sensitive, but parameter
247     values shall be case sensitive. [OGC 01-068r3, 6.4.1, p13]
248    
249     This is not supported by the compare URL method, but may need to
250     in the future.
251    
252     - Some geospatial inforamtion may be available at multiple times,
253     like a whether map or satalite photo. Capabilities may announce
254     available times. [OGC 01-068r3, 6.5.7, p18]
255    
256     This is not yet supported by WMSClient
257    
258     - According to the specs a comma in LAYERS and STYLES list doesn't
259     have to be encoded. Maybe this could cause problems with some
260     servers, just to keep in mind.
261    
262     """

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26