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 |
joey |
2119 |
from adjustpath import thubandir |
34 |
joey |
2114 |
|
35 |
|
|
from Extensions.wms.parser import WMSCapabilitiesParser |
36 |
|
|
|
37 |
|
|
|
38 |
|
|
class TestWMSCapabilitiesParser (unittest.TestCase, WMSCapabilitiesParser): |
39 |
|
|
""" |
40 |
|
|
Defines a test environment for the class WMSCapabilities. |
41 |
|
|
""" |
42 |
|
|
|
43 |
|
|
def compareLists (self, foo, bar): |
44 |
|
|
""" |
45 |
|
|
Compare two lists |
46 |
|
|
- check same number of elements |
47 |
|
|
- check whether all elements in the first list are part of the second |
48 |
|
|
""" |
49 |
|
|
|
50 |
|
|
# Check for same number of elements |
51 |
|
|
if len(foo) != len(bar): |
52 |
|
|
self.fail ("Different number of elements"); |
53 |
|
|
|
54 |
|
|
# Loop through all elements for existance |
55 |
|
|
for elm in foo: |
56 |
|
|
if elm not in bar: |
57 |
|
|
self.fail ("%s not in second list" % elm); |
58 |
|
|
|
59 |
|
|
|
60 |
|
|
def compareDicts (self, foo, bar): |
61 |
|
|
""" |
62 |
|
|
Compare two dictionaries (hashes) |
63 |
|
|
- check same number of keys |
64 |
|
|
- check whether all keys from the first list are part of the second |
65 |
|
|
""" |
66 |
|
|
|
67 |
|
|
# Check for same number of elements |
68 |
|
|
if len(foo) != len(bar): |
69 |
|
|
self.fail ("Different number of keys"); |
70 |
|
|
|
71 |
|
|
# Loop through all elements for existance |
72 |
|
|
for key in foo.keys(): |
73 |
|
|
if key not in bar: |
74 |
|
|
self.fail ("%s not in second dictionary" % key); |
75 |
|
|
if foo[key] != bar[key]: |
76 |
|
|
self.fail ("%s has different value in second dictionary" % key); |
77 |
|
|
|
78 |
|
|
|
79 |
|
|
def load_frida(self): |
80 |
|
|
""" |
81 |
|
|
Load the locally stored frida capabilities. |
82 |
|
|
http://frida.intevation.org/cgi-bin/frida_wms? |
83 |
|
|
""" |
84 |
|
|
|
85 |
|
|
try: |
86 |
|
|
try: |
87 |
|
|
f = open ("sample.xml", "r") |
88 |
|
|
except: |
89 |
|
|
f = open (os.path.dirname (__file__) + "/sample.xml", "r") |
90 |
|
|
except: |
91 |
|
|
print "Cannot open sample.xml for reading" |
92 |
|
|
else: |
93 |
|
|
xml = f.read (); |
94 |
|
|
f.close() |
95 |
|
|
self.grok (xml) |
96 |
|
|
|
97 |
|
|
|
98 |
|
|
def test_general (self): |
99 |
|
|
""" |
100 |
|
|
Test general attributes extracted from Capabilities XML |
101 |
|
|
""" |
102 |
|
|
|
103 |
|
|
if not self.capabilities: |
104 |
|
|
self.load_frida() |
105 |
|
|
|
106 |
|
|
self.assertEquals (self.getTitle(),'Frida - Freie Vektor-Geodaten Osnabrück') |
107 |
|
|
self.assertEquals (self.getAbstract(),'') |
108 |
|
|
self.assertEquals (self.getFees(),'') |
109 |
|
|
self.assertEquals (self.getAccessConstraints(),'') |
110 |
|
|
formats = ['image/gif', 'image/png', 'image/jpeg', 'image/wbmp'] |
111 |
|
|
self.compareLists (self.getFormats(),formats) |
112 |
|
|
layers = ['Osnabrueck', 'gruenflaechen', 'gewaesser', |
113 |
|
|
'gewaesserpolyl','gewaesserlinien', 'strassen_all', |
114 |
|
|
'strassenhinten', 'strassen', 'beschriftung', |
115 |
|
|
'hauptbeschriftung', 'sehenswuerdigkeiten'] |
116 |
|
|
self.compareLists (self.getLayers(),layers) |
117 |
|
|
self.compareLists (self.getSRS(),[31493]) |
118 |
|
|
|
119 |
|
|
|
120 |
|
|
def test_LayerTitle (self): |
121 |
|
|
""" |
122 |
|
|
Check if layer titles are recognised properly |
123 |
|
|
""" |
124 |
|
|
|
125 |
|
|
if not self.capabilities: |
126 |
|
|
self.load_frida() |
127 |
|
|
|
128 |
|
|
# main layer |
129 |
|
|
self.assertEquals (self.getLayerTitle('Osnabrueck'),'Frida - Freie Vektor-Geodaten Osnabrück') |
130 |
|
|
|
131 |
|
|
# first nested layer |
132 |
|
|
self.assertEquals (self.getLayerTitle('gruenflaechen'),'Grünflächen') |
133 |
|
|
|
134 |
|
|
# first nested layer |
135 |
|
|
self.assertEquals (self.getLayerTitle('gewaesser'),'Gewässer') |
136 |
|
|
|
137 |
|
|
# second nested layer |
138 |
|
|
self.assertEquals (self.getLayerTitle('gewaesserpolyl'),'Gewässerflächen') |
139 |
|
|
|
140 |
|
|
|
141 |
|
|
def test_LayerSRS (self): |
142 |
|
|
""" |
143 |
|
|
Check if the SRS are returned properly |
144 |
|
|
""" |
145 |
|
|
|
146 |
|
|
if not self.capabilities: |
147 |
|
|
self.load_frida() |
148 |
|
|
|
149 |
|
|
# SRS of main layer |
150 |
|
|
self.compareLists (self.getLayerSRS('Osnabrueck'),[31493]) |
151 |
|
|
|
152 |
|
|
# Single SRS of layer without inheritance |
153 |
|
|
self.compareLists (self.getLayerSRS('gruenflaechen'),[31493]) |
154 |
|
|
|
155 |
|
|
# Multiple SRS (new/1.1.1) of layer without inheritance |
156 |
|
|
self.compareLists (self.getLayerSRS('gewaesserpolyl'),[31493, 31494]) |
157 |
|
|
|
158 |
|
|
# Multiple SRS (old/1.0.0) of layer without inheritance |
159 |
|
|
self.compareLists (self.getLayerSRS('gewaesserlinien'),[31493, 31494]) |
160 |
|
|
|
161 |
|
|
# Multiple SRS of layer with inheritance |
162 |
|
|
self.compareLists (self.getLayerSRS('strassenhinten'),[31493, 31494]) |
163 |
|
|
|
164 |
|
|
# Multiple SRS (old/1.0.0) with inheritance |
165 |
|
|
self.compareLists (self.getLayerSRS('strassen'),[31493, 31494, 31495]) |
166 |
|
|
|
167 |
|
|
# Multiple SRS (new/1.1.1) with inheritance |
168 |
|
|
self.compareLists (self.getLayerSRS('beschriftung'),[31493, 31494, 31495]) |
169 |
|
|
|
170 |
|
|
|
171 |
|
|
def test_LatLonBoundingBoxes (self): |
172 |
|
|
""" |
173 |
|
|
Check if the LatLonBoundingBoxes are returned properly |
174 |
|
|
""" |
175 |
|
|
|
176 |
|
|
if not self.capabilities: |
177 |
|
|
self.load_frida() |
178 |
|
|
|
179 |
|
|
# main LatLonBoundingBox |
180 |
|
|
bbox = {'minx': "7.92881", 'miny': "52.2131", |
181 |
|
|
'maxx': "8.18349", 'maxy': "52.341"} |
182 |
|
|
self.compareDicts (self.getLayerLatLonBBox('Osnabrueck'),bbox) |
183 |
|
|
|
184 |
|
|
# inherited LatLonBoundingBox |
185 |
|
|
bbox = {'minx': "7.92881", 'miny': "52.2131", |
186 |
|
|
'maxx': "8.18349", 'maxy': "52.341"} |
187 |
|
|
self.compareDicts (self.getLayerLatLonBBox('gewaesser'),bbox) |
188 |
|
|
|
189 |
|
|
# third layer non-inherited LatLonBoundingBox |
190 |
|
|
bbox = {'minx': "7.93531", 'miny': "52.2328", |
191 |
|
|
'maxx': "8.17739", 'maxy': "52.3353"} |
192 |
|
|
self.compareDicts (self.getLayerLatLonBBox('gewaesserpolyl'),bbox) |
193 |
|
|
|
194 |
|
|
|
195 |
|
|
def test_BBoxSRS (self): |
196 |
|
|
""" |
197 |
|
|
Check if the BoundingBoxSRS' are returned properly |
198 |
|
|
""" |
199 |
|
|
|
200 |
|
|
if not self.capabilities: |
201 |
|
|
self.load_frida() |
202 |
|
|
|
203 |
|
|
# Single SRS:BBox |
204 |
|
|
self.compareLists (self.getLayerBBoxSRS('gruenflaechen'),[31493]) |
205 |
|
|
|
206 |
|
|
# Single inherited SRS:BBox |
207 |
|
|
self.compareLists (self.getLayerBBoxSRS('gewaesser'),[31493]) |
208 |
|
|
|
209 |
|
|
# Multiple SRS:BBox |
210 |
|
|
self.compareLists (self.getLayerBBoxSRS('gewaesserpolyl'),[31493, 31494]) |
211 |
|
|
|
212 |
|
|
|
213 |
|
|
def test_BoundingBoxes (self): |
214 |
|
|
""" |
215 |
|
|
Check if the BoundingBoxes are returned properly |
216 |
|
|
""" |
217 |
|
|
|
218 |
|
|
if not self.capabilities: |
219 |
|
|
self.load_frida() |
220 |
|
|
|
221 |
|
|
# main BoundingBox |
222 |
|
|
bbox = {'minx': "3.427e+06", 'miny': "5.787e+06", |
223 |
|
|
'maxx': "3.4442e+06", 'maxy': "5.801e+06"} |
224 |
|
|
self.compareDicts (self.getLayerBBox('Osnabrueck', 31493),bbox) |
225 |
|
|
|
226 |
|
|
# inherited BoundingBox |
227 |
|
|
self.compareDicts (self.getLayerBBox('gewaesser', 31493),bbox) |
228 |
|
|
|
229 |
|
|
# overwritten BoundingBox |
230 |
|
|
bbox = {'minx': "3.427e+06", 'miny': "5.78901e+06", |
231 |
|
|
'maxx': "3.44173e+06", 'maxy': "5.79952e+06"} |
232 |
|
|
self.compareDicts (self.getLayerBBox('gewaesserlinien', 31493),bbox) |
233 |
|
|
|
234 |
|
|
# multiple BoundingBoxes |
235 |
|
|
bbox = {'minx': "3.42743e+06", 'miny': "5.78919e+06", |
236 |
|
|
'maxx': "3.44381e+06", 'maxy': "5.80038e+06"} |
237 |
|
|
self.compareDicts (self.getLayerBBox('gewaesserpolyl', 31493),bbox) |
238 |
|
|
bbox = {'minx': "3.42742e+06", 'miny': "5.78918e+06", |
239 |
|
|
'maxx': "3.44380e+06", 'maxy': "5.80037e+06"} |
240 |
|
|
self.compareDicts (self.getLayerBBox('gewaesserpolyl', 31494),bbox) |
241 |
|
|
|
242 |
joey |
2119 |
|
243 |
joey |
2114 |
def test_queryable (self): |
244 |
|
|
""" |
245 |
|
|
Check if layers are properly classified queryable or not |
246 |
|
|
""" |
247 |
|
|
|
248 |
|
|
if not self.capabilities: |
249 |
|
|
self.load_frida() |
250 |
|
|
|
251 |
|
|
# implicit setting in main layer |
252 |
|
|
self.assertEquals (self.isQueryable('Osnabrueck'),0) |
253 |
|
|
|
254 |
|
|
# explicit setting in second layer |
255 |
|
|
self.assertEquals (self.isQueryable('gruenflaechen'),0) |
256 |
|
|
|
257 |
|
|
# inherited setting in second layer |
258 |
|
|
self.assertEquals (self.isQueryable('gewaesser'),0) |
259 |
|
|
|
260 |
|
|
# explicit setting in second layer |
261 |
|
|
self.assertEquals (self.isQueryable('sehenswuerdigkeiten'),1) |
262 |
|
|
|
263 |
|
|
# explicit setting in third layer |
264 |
|
|
self.assertEquals (self.isQueryable('strassen'),1) |
265 |
|
|
|
266 |
|
|
|
267 |
|
|
|
268 |
|
|
if __name__ == "__main__": |
269 |
|
|
unittest.main() |