1 |
joey |
2114 |
# -*- encoding: iso-8859-1 -*- |
2 |
|
|
# |
3 |
|
|
# Copyright (c) 2004 by Intevation GmbH |
4 |
|
|
# Authors: |
5 |
|
|
# Martin Schulze <[email protected]> |
6 |
|
|
# |
7 |
|
|
# This program is free software; you can redistribute it and/or modify |
8 |
|
|
# it under the terms of the GNU General Public License as published by |
9 |
|
|
# the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
# (at your option) any later version. |
11 |
|
|
# |
12 |
|
|
# This program is distributed in the hope that it will be useful, |
13 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
# GNU General Public License for more details. |
16 |
|
|
# |
17 |
|
|
# You should have received a copy of the GNU General Public License |
18 |
|
|
# along with this program; if not, write to the Free Software |
19 |
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
|
|
|
21 |
|
|
""" |
22 |
|
|
Test for WMSCapabilitiesParser from ../parser.py |
23 |
|
|
|
24 |
|
|
""" |
25 |
|
|
|
26 |
|
|
__version__ = "$Revision$" |
27 |
|
|
# $Source$ |
28 |
|
|
# $Id$ |
29 |
|
|
|
30 |
|
|
import os |
31 |
|
|
import unittest |
32 |
|
|
|
33 |
|
|
from sys import path |
34 |
|
|
|
35 |
|
|
# Add the main Thuban directory so the path so that all modules are |
36 |
|
|
# accessible as expected |
37 |
|
|
# |
38 |
|
|
if os.path.dirname (__file__) == "" or os.path.dirname (__file__) == ".": |
39 |
|
|
path.insert (0, os.path.abspath ("../../../")) |
40 |
|
|
else: |
41 |
|
|
path.insert (0, os.path.abspath (os.path.dirname(__file__) + "/../../..")) |
42 |
|
|
|
43 |
|
|
|
44 |
|
|
from Extensions.wms.parser import WMSCapabilitiesParser |
45 |
|
|
|
46 |
|
|
|
47 |
|
|
class TestWMSCapabilitiesParser (unittest.TestCase, WMSCapabilitiesParser): |
48 |
|
|
""" |
49 |
|
|
Defines a test environment for the class WMSCapabilities. |
50 |
|
|
""" |
51 |
|
|
|
52 |
|
|
def compareLists (self, foo, bar): |
53 |
|
|
""" |
54 |
|
|
Compare two lists |
55 |
|
|
- check same number of elements |
56 |
|
|
- check whether all elements in the first list are part of the second |
57 |
|
|
""" |
58 |
|
|
|
59 |
|
|
# Check for same number of elements |
60 |
|
|
if len(foo) != len(bar): |
61 |
|
|
self.fail ("Different number of elements"); |
62 |
|
|
|
63 |
|
|
# Loop through all elements for existance |
64 |
|
|
for elm in foo: |
65 |
|
|
if elm not in bar: |
66 |
|
|
self.fail ("%s not in second list" % elm); |
67 |
|
|
|
68 |
|
|
|
69 |
|
|
def compareDicts (self, foo, bar): |
70 |
|
|
""" |
71 |
|
|
Compare two dictionaries (hashes) |
72 |
|
|
- check same number of keys |
73 |
|
|
- check whether all keys from the first list are part of the second |
74 |
|
|
""" |
75 |
|
|
|
76 |
|
|
# Check for same number of elements |
77 |
|
|
if len(foo) != len(bar): |
78 |
|
|
self.fail ("Different number of keys"); |
79 |
|
|
|
80 |
|
|
# Loop through all elements for existance |
81 |
|
|
for key in foo.keys(): |
82 |
|
|
if key not in bar: |
83 |
|
|
self.fail ("%s not in second dictionary" % key); |
84 |
|
|
if foo[key] != bar[key]: |
85 |
|
|
self.fail ("%s has different value in second dictionary" % key); |
86 |
|
|
|
87 |
|
|
|
88 |
|
|
def load_frida(self): |
89 |
|
|
""" |
90 |
|
|
Load the locally stored frida capabilities. |
91 |
|
|
http://frida.intevation.org/cgi-bin/frida_wms? |
92 |
|
|
""" |
93 |
|
|
|
94 |
|
|
try: |
95 |
|
|
try: |
96 |
|
|
f = open ("sample.xml", "r") |
97 |
|
|
except: |
98 |
|
|
f = open (os.path.dirname (__file__) + "/sample.xml", "r") |
99 |
|
|
except: |
100 |
|
|
print "Cannot open sample.xml for reading" |
101 |
|
|
else: |
102 |
|
|
xml = f.read (); |
103 |
|
|
f.close() |
104 |
|
|
self.grok (xml) |
105 |
|
|
|
106 |
|
|
|
107 |
|
|
def test_general (self): |
108 |
|
|
""" |
109 |
|
|
Test general attributes extracted from Capabilities XML |
110 |
|
|
""" |
111 |
|
|
|
112 |
|
|
if not self.capabilities: |
113 |
|
|
self.load_frida() |
114 |
|
|
|
115 |
|
|
self.assertEquals (self.getTitle(),'Frida - Freie Vektor-Geodaten Osnabrück') |
116 |
|
|
self.assertEquals (self.getAbstract(),'') |
117 |
|
|
self.assertEquals (self.getFees(),'') |
118 |
|
|
self.assertEquals (self.getAccessConstraints(),'') |
119 |
|
|
formats = ['image/gif', 'image/png', 'image/jpeg', 'image/wbmp'] |
120 |
|
|
self.compareLists (self.getFormats(),formats) |
121 |
|
|
layers = ['Osnabrueck', 'gruenflaechen', 'gewaesser', |
122 |
|
|
'gewaesserpolyl','gewaesserlinien', 'strassen_all', |
123 |
|
|
'strassenhinten', 'strassen', 'beschriftung', |
124 |
|
|
'hauptbeschriftung', 'sehenswuerdigkeiten'] |
125 |
|
|
self.compareLists (self.getLayers(),layers) |
126 |
|
|
self.compareLists (self.getSRS(),[31493]) |
127 |
|
|
|
128 |
|
|
|
129 |
|
|
def test_LayerTitle (self): |
130 |
|
|
""" |
131 |
|
|
Check if layer titles are recognised properly |
132 |
|
|
""" |
133 |
|
|
|
134 |
|
|
if not self.capabilities: |
135 |
|
|
self.load_frida() |
136 |
|
|
|
137 |
|
|
# main layer |
138 |
|
|
self.assertEquals (self.getLayerTitle('Osnabrueck'),'Frida - Freie Vektor-Geodaten Osnabrück') |
139 |
|
|
|
140 |
|
|
# first nested layer |
141 |
|
|
self.assertEquals (self.getLayerTitle('gruenflaechen'),'Grünflächen') |
142 |
|
|
|
143 |
|
|
# first nested layer |
144 |
|
|
self.assertEquals (self.getLayerTitle('gewaesser'),'Gewässer') |
145 |
|
|
|
146 |
|
|
# second nested layer |
147 |
|
|
self.assertEquals (self.getLayerTitle('gewaesserpolyl'),'Gewässerflächen') |
148 |
|
|
|
149 |
|
|
|
150 |
|
|
def test_LayerSRS (self): |
151 |
|
|
""" |
152 |
|
|
Check if the SRS are returned properly |
153 |
|
|
""" |
154 |
|
|
|
155 |
|
|
if not self.capabilities: |
156 |
|
|
self.load_frida() |
157 |
|
|
|
158 |
|
|
# SRS of main layer |
159 |
|
|
self.compareLists (self.getLayerSRS('Osnabrueck'),[31493]) |
160 |
|
|
|
161 |
|
|
# Single SRS of layer without inheritance |
162 |
|
|
self.compareLists (self.getLayerSRS('gruenflaechen'),[31493]) |
163 |
|
|
|
164 |
|
|
# Multiple SRS (new/1.1.1) of layer without inheritance |
165 |
|
|
self.compareLists (self.getLayerSRS('gewaesserpolyl'),[31493, 31494]) |
166 |
|
|
|
167 |
|
|
# Multiple SRS (old/1.0.0) of layer without inheritance |
168 |
|
|
self.compareLists (self.getLayerSRS('gewaesserlinien'),[31493, 31494]) |
169 |
|
|
|
170 |
|
|
# Multiple SRS of layer with inheritance |
171 |
|
|
self.compareLists (self.getLayerSRS('strassenhinten'),[31493, 31494]) |
172 |
|
|
|
173 |
|
|
# Multiple SRS (old/1.0.0) with inheritance |
174 |
|
|
self.compareLists (self.getLayerSRS('strassen'),[31493, 31494, 31495]) |
175 |
|
|
|
176 |
|
|
# Multiple SRS (new/1.1.1) with inheritance |
177 |
|
|
self.compareLists (self.getLayerSRS('beschriftung'),[31493, 31494, 31495]) |
178 |
|
|
|
179 |
|
|
|
180 |
|
|
def test_LatLonBoundingBoxes (self): |
181 |
|
|
""" |
182 |
|
|
Check if the LatLonBoundingBoxes are returned properly |
183 |
|
|
""" |
184 |
|
|
|
185 |
|
|
if not self.capabilities: |
186 |
|
|
self.load_frida() |
187 |
|
|
|
188 |
|
|
# main LatLonBoundingBox |
189 |
|
|
bbox = {'minx': "7.92881", 'miny': "52.2131", |
190 |
|
|
'maxx': "8.18349", 'maxy': "52.341"} |
191 |
|
|
self.compareDicts (self.getLayerLatLonBBox('Osnabrueck'),bbox) |
192 |
|
|
|
193 |
|
|
# inherited LatLonBoundingBox |
194 |
|
|
bbox = {'minx': "7.92881", 'miny': "52.2131", |
195 |
|
|
'maxx': "8.18349", 'maxy': "52.341"} |
196 |
|
|
self.compareDicts (self.getLayerLatLonBBox('gewaesser'),bbox) |
197 |
|
|
|
198 |
|
|
# third layer non-inherited LatLonBoundingBox |
199 |
|
|
bbox = {'minx': "7.93531", 'miny': "52.2328", |
200 |
|
|
'maxx': "8.17739", 'maxy': "52.3353"} |
201 |
|
|
self.compareDicts (self.getLayerLatLonBBox('gewaesserpolyl'),bbox) |
202 |
|
|
|
203 |
|
|
|
204 |
|
|
def test_BBoxSRS (self): |
205 |
|
|
""" |
206 |
|
|
Check if the BoundingBoxSRS' are returned properly |
207 |
|
|
""" |
208 |
|
|
|
209 |
|
|
if not self.capabilities: |
210 |
|
|
self.load_frida() |
211 |
|
|
|
212 |
|
|
# Single SRS:BBox |
213 |
|
|
self.compareLists (self.getLayerBBoxSRS('gruenflaechen'),[31493]) |
214 |
|
|
|
215 |
|
|
# Single inherited SRS:BBox |
216 |
|
|
self.compareLists (self.getLayerBBoxSRS('gewaesser'),[31493]) |
217 |
|
|
|
218 |
|
|
# Multiple SRS:BBox |
219 |
|
|
self.compareLists (self.getLayerBBoxSRS('gewaesserpolyl'),[31493, 31494]) |
220 |
|
|
|
221 |
|
|
|
222 |
|
|
def test_BoundingBoxes (self): |
223 |
|
|
""" |
224 |
|
|
Check if the BoundingBoxes are returned properly |
225 |
|
|
""" |
226 |
|
|
|
227 |
|
|
if not self.capabilities: |
228 |
|
|
self.load_frida() |
229 |
|
|
|
230 |
|
|
# main BoundingBox |
231 |
|
|
bbox = {'minx': "3.427e+06", 'miny': "5.787e+06", |
232 |
|
|
'maxx': "3.4442e+06", 'maxy': "5.801e+06"} |
233 |
|
|
self.compareDicts (self.getLayerBBox('Osnabrueck', 31493),bbox) |
234 |
|
|
|
235 |
|
|
# inherited BoundingBox |
236 |
|
|
self.compareDicts (self.getLayerBBox('gewaesser', 31493),bbox) |
237 |
|
|
|
238 |
|
|
# overwritten BoundingBox |
239 |
|
|
bbox = {'minx': "3.427e+06", 'miny': "5.78901e+06", |
240 |
|
|
'maxx': "3.44173e+06", 'maxy': "5.79952e+06"} |
241 |
|
|
self.compareDicts (self.getLayerBBox('gewaesserlinien', 31493),bbox) |
242 |
|
|
|
243 |
|
|
# multiple BoundingBoxes |
244 |
|
|
bbox = {'minx': "3.42743e+06", 'miny': "5.78919e+06", |
245 |
|
|
'maxx': "3.44381e+06", 'maxy': "5.80038e+06"} |
246 |
|
|
self.compareDicts (self.getLayerBBox('gewaesserpolyl', 31493),bbox) |
247 |
|
|
bbox = {'minx': "3.42742e+06", 'miny': "5.78918e+06", |
248 |
|
|
'maxx': "3.44380e+06", 'maxy': "5.80037e+06"} |
249 |
|
|
self.compareDicts (self.getLayerBBox('gewaesserpolyl', 31494),bbox) |
250 |
|
|
|
251 |
|
|
def test_queryable (self): |
252 |
|
|
""" |
253 |
|
|
Check if layers are properly classified queryable or not |
254 |
|
|
""" |
255 |
|
|
|
256 |
|
|
if not self.capabilities: |
257 |
|
|
self.load_frida() |
258 |
|
|
|
259 |
|
|
# implicit setting in main layer |
260 |
|
|
self.assertEquals (self.isQueryable('Osnabrueck'),0) |
261 |
|
|
|
262 |
|
|
# explicit setting in second layer |
263 |
|
|
self.assertEquals (self.isQueryable('gruenflaechen'),0) |
264 |
|
|
|
265 |
|
|
# inherited setting in second layer |
266 |
|
|
self.assertEquals (self.isQueryable('gewaesser'),0) |
267 |
|
|
|
268 |
|
|
# explicit setting in second layer |
269 |
|
|
self.assertEquals (self.isQueryable('sehenswuerdigkeiten'),1) |
270 |
|
|
|
271 |
|
|
# explicit setting in third layer |
272 |
|
|
self.assertEquals (self.isQueryable('strassen'),1) |
273 |
|
|
|
274 |
|
|
|
275 |
|
|
|
276 |
|
|
if __name__ == "__main__": |
277 |
|
|
unittest.main() |