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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2142 - (hide annotations)
Tue Mar 30 16:28:56 2004 UTC (20 years, 11 months ago) by joey
Original Path: trunk/thuban/Extensions/wms/test/test_parser.py
File MIME type: text/x-python
File size: 8503 byte(s)
Added a new test to ensure None is returned for a non-existing SRS.

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

Properties

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26