/[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 2112 - (hide annotations)
Thu Mar 18 08:15:54 2004 UTC (20 years, 11 months ago) by joey
Original Path: trunk/thuban/Extensions/wms/test/test_ogclib.py
File MIME type: text/x-python
File size: 8356 byte(s)
The format specification is a mime-type, not a graphic format, hence
image/jpeg wou ld be the proper format and not JPEG.  We'll also have
to take care of the encoding of / as %2F.

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     Requires the ogclib installed regularily on the system or checked out
14 joey 2112 next to 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    
26     # ----------------------------------------------------------------------
27     # FIXME: Temporary code until PyOGCLib is a standard requirement
28    
29     from sys import path
30    
31     # Assume the PyOGCLib to be checked out next to the thuban main directory
32     pyogclib = "../../../../PyOGCLib"
33     if os.path.isdir (pyogclib) and os.path.isdir (pyogclib + "/ogclib"):
34     path.insert (0, pyogclib)
35     # ----------------------------------------------------------------------
36    
37     try:
38     from ogclib.WMSClient import WMSClient
39     except:
40     print "No PyOGCLib found, hence no tests available."
41     os._exit(-1)
42    
43    
44     class TestOGCLib (unittest.TestCase, WMSClient):
45     """
46     Defines a test environment for the PyOGCLib, i.e. check whether URL
47     strings are built properly.
48     """
49    
50     def compare_URLs (self, foo, bar):
51     """
52     Check if two URLs are equal, i.e.:
53     - check for same base URL
54     - check same number of HTTP GET arguments
55     - check whether all arguments from one URL also exist in the second
56     """
57    
58     foo_tuple = split (foo, "?")
59     bar_tuple = split (bar, "?")
60    
61     # Check for same base URL
62     if foo_tuple[0] != bar_tuple[0]:
63     self.fail ("%s != %s" % (foo_tuple[0], bar_tuple[0]))
64    
65     # Check for same number of HTTP GET arguments
66     if len(foo_tuple) != len(bar_tuple):
67     self.fail ("One URL has no arguments");
68    
69     # Loop through all HTTP GET arguments for existance
70     if len(foo_tuple) > 1 and len(bar_tuple) > 1:
71     foo_opts = split (foo_tuple[1], "&")
72     bar_opts = split (bar_tuple[1], "&")
73    
74     if len(foo_opts) != len(bar_opts):
75 joey 2112 self.fail ("Different number of arguments");
76 joey 2108
77     for part in foo_opts:
78     if part not in bar_opts:
79     self.fail ("%s not in second argument list" % part);
80    
81    
82     def test_compareURLs (self):
83     """Perform some tests for own compare routine"""
84    
85     result = "http://frida.intevation.org/cgi-bin"
86     self.compare_URLs ("http://frida.intevation.org/cgi-bin", result)
87    
88     result = "http://frida.intevation.org/cgi-bin?foo=eins"
89     self.compare_URLs ("http://frida.intevation.org/cgi-bin?foo=eins", result)
90    
91     result = "http://frida.intevation.org/cgi-bin?foo=eins&bar=zwei"
92     self.compare_URLs ("http://frida.intevation.org/cgi-bin?foo=eins&bar=zwei", result)
93    
94     result = "http://frida.intevation.org/cgi-bin?foo=eins&bar=zwei"
95     self.compare_URLs ("http://frida.intevation.org/cgi-bin?bar=zwei&foo=eins", result)
96    
97     result = "http://frida.intevation.org/cgi-bin?foo=eins&bar=zwei&baz=jan&quux=tux"
98     self.compare_URLs ("http://frida.intevation.org/cgi-bin?baz=jan&bar=zwei&quux=tux&foo=eins", result)
99    
100    
101     def test_CapabilityURL (self):
102     """Test the getCapabilitiesURL() method"""
103    
104     frida = "http://frida.intevation.org/cgi-bin/frida_wms?"
105    
106     url = self.getCapabilitiesURL(frida, "1.0")
107     result = frida + "WMTVER=1.0&REQUEST=capabilities"
108     self.compare_URLs (url, result)
109    
110     url = self.getCapabilitiesURL(frida, "1.1")
111     result = frida + "VERSION=1.1&SERVICE=WMS&REQUEST=GetCapabilities"
112     self.compare_URLs (url, result)
113    
114    
115 joey 2109 def test_GetMapURL (self):
116     """Test the getMapURL() method"""
117    
118     frida = "http://frida.intevation.org/cgi-bin/frida_wms?"
119    
120 joey 2112 format = 'image/jpeg'
121     format_enc = 'image%2Fjpeg'
122 joey 2109 width = 400
123     height = 350
124     epsg = 4326
125     bbox = {'minx': -107, 'miny': 40, 'maxx': -109, 'maxy': 41}
126     layers = [ ]
127     styles = [ ]
128     version = '1.1'
129    
130     result_base = frida + "WMTVER=1.0&REQUEST=map" + \
131 joey 2112 "&FORMAT="+format_enc + \
132 joey 2109 "&SRS=EPSG%s%d" % ("%3A", epsg) + \
133     "&BBOX=%f%s%f%s%f%s%f" % (bbox['minx'], "%2C", bbox['miny'], "%2C",
134     bbox['maxx'], "%2C", bbox['maxy']) + \
135     "&WIDTH=%s" % width + "&HEIGHT=%s" % height
136     result = result_base + \
137     "&LAYERS=" + "%2C".join(layers) + \
138     "&STYLES=" + "%2C".join(styles)
139     url = self.getMapURL(frida, format, width, height, epsg,
140     bbox, layers, version=version)
141    
142     # Repeat and continue with version 1.1, as denoted in OGC 01-068r3
143     version = '1.1'
144     result_base = frida + "VERSION=1.1&SERVICE=WMS&REQUEST=GetMap" + \
145 joey 2112 "&FORMAT="+format_enc + \
146 joey 2109 "&SRS=EPSG%s%d" % ("%3A", epsg) + \
147     "&BBOX=%f%s%f%s%f%s%f" % (bbox['minx'], "%2C", bbox['miny'], "%2C",
148     bbox['maxx'], "%2C", bbox['maxy']) + \
149     "&WIDTH=%s" % width + "&HEIGHT=%s" % height
150     result = result_base + \
151     "&LAYERS=" + "%2C".join(layers) + \
152     "&STYLES=" + "%2C".join(styles)
153     url = self.getMapURL(frida, format, width, height, epsg,
154     bbox, layers, version=version)
155     self.compare_URLs (result, url)
156    
157     result += "&TRANSPARENT=TRUE"
158     url = self.getMapURL(frida, format, width, height, epsg,
159     bbox, layers, version=version,
160     transparent=1 )
161     self.compare_URLs (result, url)
162    
163     result += "&BGCOLOR=0xFF00FF"
164     url = self.getMapURL(frida, format, width, height, epsg,
165     bbox, layers, version=version,
166     transparent=1, bgcolor='0xFF00FF')
167     self.compare_URLs (result, url)
168    
169     layers = [ 'foo' ]
170     result = result_base + \
171     "&LAYERS=" + "%2C".join(layers) + \
172     "&STYLES=" + "%2C".join(styles)
173     url = self.getMapURL(frida, format, width, height, epsg,
174     bbox, layers, version=version)
175     self.compare_URLs (result, url)
176    
177     layers.append ('bar')
178     result = result_base + \
179     "&LAYERS=" + "%2C".join(layers) + \
180     "&STYLES=" + "%2C".join(styles)
181     url = self.getMapURL(frida, format, width, height, epsg,
182     bbox, layers, version=version)
183     self.compare_URLs (result, url)
184    
185     styles = [ 'something' ]
186     result = result_base + \
187     "&LAYERS=" + "%2C".join(layers) + \
188     "&STYLES=" + "%2C".join(styles)
189     url = self.getMapURL(frida, format, width, height, epsg,
190     bbox, layers, version=version,
191     styles = styles)
192     self.compare_URLs (result, url)
193    
194     styles.append ('else')
195     result = result_base + \
196     "&LAYERS=" + "%2C".join(layers) + \
197     "&STYLES=" + "%2C".join(styles)
198     url = self.getMapURL(frida, format, width, height, epsg,
199     bbox, layers, version=version,
200     styles = styles)
201     self.compare_URLs (result, url)
202    
203    
204 joey 2108 if __name__ == "__main__":
205     unittest.main()
206 joey 2109
207     """
208    
209     Additional notes:
210     - Parameter names shall not be case sensitive, but parameter
211     values shall be case sensitive. [OGC 01-068r3, 6.4.1, p13]
212    
213     This is not supported by the compare URL method, but may need to
214     in the future.
215    
216     - Some geospatial inforamtion may be available at multiple times,
217     like a whether map or satalite photo. Capabilities may announce
218     available times. [OGC 01-068r3, 6.5.7, p18]
219    
220     This is not yet supported by WMSClient
221    
222     - According to the specs a comma in LAYERS and STYLES list doesn't
223     have to be encoded. Maybe this could cause problems with some
224     servers, just to keep in mind.
225    
226     """

Properties

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26