/[thuban]/branches/WIP-pyshapelib-bramz/test/test_postgis_db.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/test/test_postgis_db.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1948 - (hide annotations)
Thu Nov 13 18:56:57 2003 UTC (21 years, 3 months ago) by bh
Original Path: trunk/thuban/test/test_postgis_db.py
File MIME type: text/x-python
File size: 24458 byte(s)
(TestPostGISSpecialCases)
(TestPostGISIgnoredColumns): Rename the class to
TestPostGISSpecialCases because that better describes the new
cases
(TestPostGISSpecialCases.test_unsupported_types)
(TestPostGISSpecialCases.test): Rename the method to
test_unsupported_types because we need a more descriptive name now
that there are more methods
(TestPostGISSpecialCases.test_table_name_quoting)
(TestPostGISSpecialCases.test_column_name_quoting)
(TestPostGISSpecialCases.test_shapestore_name_quoting): New test
cases to test quoting of table and column names in PostGISTable
and PostGISShapeStore

1 bh 1605 # Copyright (C) 2003 by Intevation GmbH
2     # Authors:
3     # Bernhard Herzog <[email protected]>
4     #
5     # This program is free software under the GPL (>=v2)
6     # Read the file COPYING coming with the software for details.
7    
8     """Test for Thuban.Model.postgisdb"""
9    
10     import os
11     import unittest
12    
13    
14     try:
15     import psycopg
16     except ImportError:
17     # No psycopg available. Nothing to be done here because the
18     # postgis.py support module determines this too and the tests will
19     # be skipped completely.
20     pass
21    
22     import postgissupport
23    
24     import support
25     support.initthuban()
26    
27 bh 1636 from Thuban.Model.postgisdb import ConnectionError, PostGISConnection, \
28     PostGISTable, PostGISShapeStore
29 bh 1605 from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_STRING, \
30     FIELDTYPE_DOUBLE
31     from Thuban.Model.data import SHAPETYPE_POINT, SHAPETYPE_POLYGON, \
32     SHAPETYPE_ARC, RAW_WKT
33    
34    
35 bh 1620 class NonConnection(PostGISConnection):
36    
37     """Special connection class that doesn't actually connect"""
38    
39     def connect(self):
40     pass
41    
42    
43    
44     class TestBriefDescription(unittest.TestCase):
45    
46     def test(self):
47     """Test PostGISConnection.BriefDescription()"""
48     self.assertEquals(NonConnection("somedb").BriefDescription(),
49     "postgis://@:/somedb")
50     self.assertEquals(NonConnection("db", host="here",
51     port="123").BriefDescription(),
52     "postgis://@here:123/db")
53     self.assertEquals(NonConnection("db", user="me",
54     port="123").BriefDescription(),
55     "postgis://me@:123/db")
56    
57    
58 bh 1605 class TestPostGISConnection(unittest.TestCase):
59    
60     def setUp(self):
61     """Start the server and create a database.
62    
63     The database name will be stored in self.dbname, the server
64     object in self.server and the db object in self.db.
65     """
66     postgissupport.skip_if_no_postgis()
67     self.server = postgissupport.get_test_server()
68     self.dbname = ".".join(self.id().split(".")[-2:])[-31:]
69     self.db = self.server.new_postgis_db(self.dbname)
70    
71     def test_gis_tables_empty(self):
72     """Test PostGISConnection.GISTables() on empty DB"""
73 bh 1634 db = PostGISConnection(dbname = self.dbname,
74     **self.server.connection_params("user"))
75 bh 1605
76     # An empty database doesn't have any GIS tables
77     self.assertEquals(db.GeometryTables(), [])
78    
79     def test_gis_tables_non_empty(self):
80     """Test PostGISConnection.GISTables() on non-empty DB"""
81 bh 1634 db = PostGISConnection(dbname = self.dbname,
82     **self.server.connection_params("user"))
83 bh 1605
84 bh 1634 conn = psycopg.connect("dbname=%s " % self.dbname
85     + self.server.connection_string("admin"))
86 bh 1605 cursor = conn.cursor()
87     cursor.execute("CREATE TABLE test (A INT);")
88     cursor.execute("SELECT AddGeometryColumn(%(dbname)s, 'test',"
89     " 'geometry', -1, 'POINT', 2);",
90     {"dbname": self.dbname})
91     conn.commit()
92    
93     # An empty database doesn't have any GIS tables
94     self.assertEquals(db.GeometryTables(), ["test"])
95    
96    
97 bh 1636 class TestPostgisDBExceptions(unittest.TestCase):
98    
99     def setUp(self):
100     """Start the postgis server and switch on authentication"""
101     postgissupport.skip_if_no_postgis()
102     self.server = postgissupport.get_test_server()
103     self.postgisdb = self.server.get_default_static_data_db()
104     self.server.require_authentication(True)
105    
106     def tearDown(self):
107     """Extend the inherited method to switch off postgresql authentication
108     """
109     self.server.require_authentication(False)
110    
111     def test_no_password(self):
112     """Test PostGISConnection with omitted but required password"""
113     connection_params = self.server.connection_params("user")
114     # remove the password deliberately
115     del connection_params["password"]
116    
117     self.assertRaises(ConnectionError,
118     PostGISConnection, dbname = self.postgisdb.dbname,
119     **connection_params)
120    
121    
122 bh 1948 class TestPostGISSpecialCases(unittest.TestCase):
123 bh 1693
124 bh 1948 """Tests for special cases of PostGIS table usage"""
125    
126 bh 1693 def setUp(self):
127     """Start the server and create a database.
128    
129     The database name will be stored in self.dbname, the server
130     object in self.server and the db object in self.db.
131     """
132     postgissupport.skip_if_no_postgis()
133     self.server = postgissupport.get_test_server()
134     self.dbname = ".".join(self.id().split(".")[-2:])[-31:]
135     self.db = self.server.new_postgis_db(self.dbname)
136    
137 bh 1948 def test_unsupported_types(self):
138 bh 1693 """test PostGISTable on a table with unsupported data types"""
139     stmt = """CREATE TABLE foo (
140     gid integer,
141     ignored bigint,
142     length float);
143     GRANT SELECT ON foo TO PUBLIC;
144     """
145     self.server.execute_sql(self.dbname, "admin", stmt)
146    
147     db = PostGISConnection(dbname = self.dbname,
148     **self.server.connection_params("user"))
149     table = PostGISTable(db, "foo")
150    
151     # The bigint column will be ignored because it's not mapped to a
152     # known integer type, so there are only two colunns
153     self.assertEquals(table.NumColumns(), 2)
154     self.assertEquals(table.Column(0).name, "gid")
155     self.assertEquals(table.Column(1).name, "length")
156    
157 bh 1948 def test_table_name_quoting(self):
158     """Test whether PostGISTable quotes table names properly"""
159     stmt = '''CREATE TABLE "name with ""quotes"" and spaces" (gid integer);
160     GRANT SELECT ON "name with ""quotes"" and spaces" TO PUBLIC;'''
161     self.server.execute_sql(self.dbname, "admin", stmt)
162 bh 1693
163 bh 1948 db = PostGISConnection(dbname = self.dbname,
164     **self.server.connection_params("user"))
165     table = PostGISTable(db, 'name with "quotes" and spaces')
166    
167     self.assertEquals(table.NumColumns(), 1)
168     self.assertEquals(table.Column(0).name, "gid")
169    
170     def test_column_name_quoting(self):
171     """Test whether PostGISTable quotes column names properly"""
172     stmt = '''CREATE TABLE unusual_column_names (
173     gid integer,
174     "with space" float,
175     "with "" quote" integer);
176     INSERT INTO unusual_column_names VALUES (1, 1.0, 0);
177     INSERT INTO unusual_column_names VALUES (2, 2.0, 1);
178     INSERT INTO unusual_column_names VALUES (3, 3.0, 1);
179     GRANT SELECT ON unusual_column_names TO PUBLIC;'''
180     self.server.execute_sql(self.dbname, "admin", stmt)
181    
182     db = PostGISConnection(dbname = self.dbname,
183     **self.server.connection_params("user"))
184     table = PostGISTable(db, 'unusual_column_names')
185    
186     self.assertEquals(table.NumColumns(), 3)
187     self.assertEquals(table.Column(0).name, "gid")
188     self.assertEquals(table.Column(1).name, "with space")
189     self.assertEquals(table.Column(2).name, "with \" quote")
190    
191     # do some queries where the names have to be quoted
192     self.assertEquals(table.ReadRowAsDict(1),
193     {"gid": 1, "with space": 1.0, "with \" quote": 0})
194     self.assertEquals(table.ReadValue(2, 1, row_is_ordinal = True), 3.0)
195     self.assertEquals(table.ReadValue(2, 1, row_is_ordinal = False), 2.0)
196     self.assertEquals(table.ValueRange("with space"), (1.0, 3.0))
197     self.assertEquals(table.UniqueValues("with \" quote"), [0, 1])
198     self.assertEquals(table.SimpleQuery(table.Columns()[2], "==", 1),
199     [2, 3])
200     self.assertEquals(table.SimpleQuery(table.Columns()[0], "==",
201     table.Columns()[1]), [1, 2, 3])
202    
203     def test_shapestore_name_quoting(self):
204     """Test whether PostGISShapeStore quotes table names properly"""
205     postgissupport.skip_if_addgeometrycolumn_does_not_use_quote_ident()
206    
207     # Create a table with a name that needs quoting and a geometry
208     # column whose name has to be quoted
209     stmt = '''CREATE TABLE "table "" name" (gid integer);
210     GRANT SELECT ON "table "" name" TO PUBLIC;'''
211     self.server.execute_sql(self.dbname, "admin", stmt)
212     stmt = """select AddGeometryColumn('%s', 'table \" name',
213     'the \" geom', '-1', 'POINT', 2);"""
214     self.server.execute_sql(self.dbname, "admin", stmt % self.dbname)
215     stmt = '''INSERT INTO "table "" name" VALUES (0,
216     GeometryFromText('POINT(0 0)', -1));'''
217     self.server.execute_sql(self.dbname, "admin", stmt)
218    
219     # Instantiate the table
220     db = PostGISConnection(dbname = self.dbname,
221     **self.server.connection_params("user"))
222     store = PostGISShapeStore(db, "table \" name")
223    
224     # do some queries where the names have to be quoted
225     self.assertEquals(store.NumShapes(), 1)
226     self.assertEquals(store.ShapeType(), SHAPETYPE_POINT)
227     self.assertEquals(store.BoundingBox(), (0, 0, 0, 0))
228     self.assertEquals(store.Shape(0).ShapeID(), 0)
229     self.assertEquals([s.ShapeID() for s in store.AllShapes()], [0])
230     self.assertEquals([s.ShapeID()
231     for s in store.ShapesInRegion((-1, -1, 1, 1))], [0])
232    
233 bh 1605 class PostGISStaticTests(unittest.TestCase, support.FloatComparisonMixin):
234    
235     """Base class for PostGIS tests with static data."""
236    
237     def setUp(self):
238     """Start the server and create a database with static data
239    
240     This method sets the following instance attributes:
241    
242     dbname -- the name of the database
243    
244     server -- The server object
245    
246     db -- the PostGISConnection object
247     """
248     postgissupport.skip_if_no_postgis()
249     self.server = postgissupport.get_test_server()
250     self.postgisdb = self.server.get_default_static_data_db()
251     self.db = PostGISConnection(dbname = self.postgisdb.dbname,
252 bh 1634 **self.server.connection_params("user"))
253 bh 1605
254     def tearDown(self):
255     """Close the database connection"""
256     self.db.Close()
257    
258    
259     class TestPostGISTable(PostGISStaticTests):
260    
261     def setUp(self):
262     """Extend inherited method to set self.table to a PostGISTable"""
263     PostGISStaticTests.setUp(self)
264     self.table = PostGISTable(self.db, "landmarks")
265    
266 bh 1638 def test_dbconn(self):
267     """Test PostGISTable.DBConnection()"""
268     self.failUnless(self.table.DBConnection() is self.db)
269    
270     def test_dbname(self):
271     """Test PostGISTable.TableName()"""
272     self.assertEquals(self.table.TableName(), "landmarks")
273    
274 bh 1658 def test_title(self):
275     """test PostGISTable.Title()"""
276     # The title is currently equal to the tablename
277     self.assertEquals(self.table.Title(), "landmarks")
278    
279 bh 1605 def test_dependencies(self):
280     """Test PostGISTable.Dependencies()"""
281     # A PostGISTable depends on no other data container
282     self.assertEquals(self.table.Dependencies(), ())
283    
284     def test_num_rows(self):
285     """Test PostGISTable.NumRows()"""
286     self.assertEquals(self.table.NumRows(), 34)
287    
288     def test_num_columns(self):
289     """Test PostGISTable.NumColumns()"""
290     # The table in the postgis db has one additional column, "gid",
291     # so there's one more column in the PostGISTable than in the DBF
292     self.assertEquals(self.table.NumColumns(), 7)
293    
294     def test_columns(self):
295     """Test PostGISTable.Columns()"""
296     self.assertEquals(len(self.table.Columns()), 7)
297     self.assertEquals(self.table.Columns()[0].name, "gid")
298     self.assertEquals(self.table.Columns()[0].type, FIELDTYPE_INT)
299     self.assertEquals(self.table.Columns()[0].index, 0)
300     self.assertEquals(self.table.Columns()[1].name, "area")
301     self.assertEquals(self.table.Columns()[1].type, FIELDTYPE_DOUBLE)
302     self.assertEquals(self.table.Columns()[1].index, 1)
303     self.assertEquals(self.table.Columns()[5].name, "clptlabel")
304     self.assertEquals(self.table.Columns()[5].type, FIELDTYPE_STRING)
305     self.assertEquals(self.table.Columns()[5].index, 5)
306    
307     def test_column(self):
308     """Test PostGISTable.Column()"""
309     self.assertEquals(self.table.Column("area").name, "area")
310     self.assertEquals(self.table.Column("area").type, FIELDTYPE_DOUBLE)
311     self.assertEquals(self.table.Column("area").index, 1)
312    
313     def test_has_column(self):
314     """Test PostGISTable.HasColumn()"""
315     self.assert_(self.table.HasColumn("area"))
316     self.failIf(self.table.HasColumn("foo"))
317    
318     def test_read_row_as_dict(self):
319     """Test PostGISTable.ReadRowAsDict()"""
320 bh 1662 self.assertEquals(self.table.ReadRowAsDict(1003),
321     {"gid": 1003,
322 bh 1605 "area": 0.0,
323     "perimeter": 0.0,
324     "clpoint_": 4,
325     "clpoint_id": 24,
326     "clptlabel": "RUINS",
327     "clptflag": 0})
328    
329 bh 1662 def test_read_row_as_dict_row_count_mode(self):
330     """Test PostGISTable.ReadRowAsDict() row count address mode"""
331     self.assertEquals(self.table.ReadRowAsDict(3, row_is_ordinal = 1),
332     {"gid": 1003,
333     "area": 0.0,
334     "perimeter": 0.0,
335     "clpoint_": 4,
336     "clpoint_id": 24,
337     "clptlabel": "RUINS",
338     "clptflag": 0})
339    
340 bh 1605 def test_read_value(self):
341     """Test PostGISTable.ReadValue()"""
342 bh 1662 self.assertEquals(self.table.ReadValue(1003, 4), 24)
343     self.assertEquals(self.table.ReadValue(1003, "clpoint_id"), 24)
344 bh 1605
345 bh 1662 def test_read_value_row_count_mode(self):
346     """Test PostGISTable.ReadValue() row count address mode"""
347     self.assertEquals(self.table.ReadValue(3, 4, row_is_ordinal = 1), 24)
348     self.assertEquals(self.table.ReadValue(3, "clpoint_id",
349     row_is_ordinal = 1),
350     24)
351    
352     def test_row_id_to_ordinal(self):
353     """Test PostGISTable.RowIdToOrdinal()"""
354     self.assertEquals(self.table.RowIdToOrdinal(1005), 5)
355    
356     def test_row_oridnal_to_id(self):
357     """Test PostGISTable.RowOrdinalToId()"""
358     self.assertEquals(self.table.RowOrdinalToId(5), 1005)
359    
360 bh 1605 def test_value_range(self):
361     """Test PostGISTable.ValueRange()"""
362     self.assertEquals(self.table.ValueRange("clpoint_id"), (21, 74))
363    
364     def test_unique_values(self):
365     """Test PostGISTable.UniqueValues()"""
366     values = self.table.UniqueValues("clptlabel")
367     values.sort()
368     self.assertEquals(values, ["BUILDING", "FARM", "HUT","LIGHTHOUSE",
369     "OTHER/UNKNOWN", "RUINS"])
370    
371     def test_simple_query(self):
372     """Test PostGISTable.SimpleQuery()"""
373     table = self.table
374     self.assertEquals(table.SimpleQuery(table.Column("clptlabel"),
375     "==", "FARM"),
376 bh 1662 [1006])
377 bh 1605 self.assertEquals(table.SimpleQuery(table.Column("clpoint_id"),
378     ">", 70),
379 bh 1662 [1024, 1025, 1026])
380 bh 1605 self.assertEquals(table.SimpleQuery(table.Column("clpoint_id"),
381     "<", table.Column("clpoint_")),
382 bh 1662 [1028, 1029, 1030, 1031, 1032, 1033])
383 bh 1605
384    
385     class TestPostGISShapestorePoint(PostGISStaticTests):
386    
387     """Tests for PostGISShapeStore objects with POINT data"""
388    
389     def setUp(self):
390     """Extend inherited method to set self.table to a PostGISShapeStore"""
391     PostGISStaticTests.setUp(self)
392     self.store = PostGISShapeStore(self.db, "landmarks")
393    
394     #
395     # First, some tests that should be independend of the shapetype, so
396     # it shouldn't be necessary to repeat them for other shapetypes
397     #
398    
399     def test_dependencies(self):
400     """Test PostGISShapeStore.Dependencies()"""
401     # A PostGISShapeStore depends on no other data container
402     self.assertEquals(self.store.Dependencies(), ())
403    
404     def test_table(self):
405     """Test PostGISShapeStore.Table() with POINT shapes"""
406     # A PostGISShapeStore is its own table
407     self.assert_(self.store.Table() is self.store)
408    
409     def test_orig_shapestore(self):
410     """Test PostGISShapeStore.OrigShapeStore() with POINT shapes"""
411     # A PostGISShapeStore is not derived from another shape store
412     self.assert_(self.store.OrigShapeStore() is None)
413    
414     def test_raw_format(self):
415     """Test PostGISShapeStore.RawShapeFormat() with POINT shapes"""
416     self.assertEquals(self.store.RawShapeFormat(), RAW_WKT)
417    
418 bh 1658 def test_all_shapes(self):
419     """Test PostGISShapeStore.AllShapes()"""
420     self.assertEquals([s.ShapeID() for s in self.store.AllShapes()],
421 bh 1662 range(1000, 1000 + self.store.NumShapes()))
422 bh 1658
423 bh 1605 #
424     # Shapetype specific tests
425     #
426    
427     def test_shape_type(self):
428     """Test PostGISShapeStore.ShapeType() with POINT shapes"""
429     self.assertEquals(self.store.ShapeType(), SHAPETYPE_POINT)
430    
431     def test_num_shapes(self):
432     """Test PostGISShapeStore.NumShapes() with POINT shapes"""
433     self.assertEquals(self.store.NumShapes(), 34)
434    
435     def test_bounding_box(self):
436     """Test PostGISShapeStore.BoundingBox() with POINT shapes"""
437     self.assertFloatSeqEqual(self.store.BoundingBox(),
438     [-23.806047439575195, 63.405960083007812,
439     -15.12291431427002, 66.36572265625])
440    
441     def test_shape_shapeid(self):
442     """Test PostGISShapeStore.Shape(i).ShapeID() with POINT shapes"""
443 bh 1662 self.assertEquals(self.store.Shape(1005).ShapeID(), 1005)
444 bh 1605
445     def test_shape_points(self):
446     """Test PostGISShapeStore.Shape(i).Points() with POINT shapes"""
447 bh 1662 self.assertPointListEquals(self.store.Shape(1000).Points(),
448 bh 1605 [[(-22.711074829101562, 66.36572265625)]])
449    
450     def test_shape_raw_data(self):
451     """Test PostGISShapeStore.Shape(i).RawData() with POINT shapes"""
452 bh 1662 self.assertEquals(self.store.Shape(1000).RawData(),
453 bh 1605 'POINT(-22.7110748291016 66.36572265625)')
454    
455     def test_shapes_in_region(self):
456     """Test PostGISShapeStore:ShapesInRegion() with POINT shapes"""
457     shapes = self.store.ShapesInRegion((-20.0, 64.0, -24.0, 67))
458     self.assertEquals([s.ShapeID() for s in shapes],
459 bh 1662 [1000, 1001, 1002, 1003, 1004, 1005, 1027])
460 bh 1605
461    
462     class TestPostGISShapestoreArc(PostGISStaticTests):
463    
464     """Tests for PostGISShapeStore objects with MULTILINESTRING data"""
465    
466     def setUp(self):
467     """Extend inherited method to set self.table to a PostGISShapeStore"""
468     PostGISStaticTests.setUp(self)
469     self.store = PostGISShapeStore(self.db, "roads")
470    
471     def test_shape_type(self):
472     """Test PostGISShapeStore.ShapeType() with ARC shapes"""
473     self.assertEquals(self.store.ShapeType(), SHAPETYPE_ARC)
474    
475     def test_num_shapes(self):
476     """Test PostGISShapeStore.NumShapes() with ARC shapes"""
477     self.assertEquals(self.store.NumShapes(), 839)
478    
479     def test_bounding_box(self):
480     """Test PostGISShapeStore.BoundingBox() with ARC shapes"""
481     self.assertFloatSeqEqual(self.store.BoundingBox(),
482     [-24.450359344482422, 63.426830291748047,
483     -13.55668830871582, 66.520111083984375])
484    
485     def test_shape_shapeid(self):
486     """Test PostGISShapeStore.Shape(i).ShapeID() with ARC shapes"""
487     self.assertEquals(self.store.Shape(5).ShapeID(), 5)
488    
489     def test_shape_points(self):
490     """Test PostGISShapeStore.Shape(i).Points() with ARC shapes"""
491     self.assertPointListEquals(self.store.Shape(32).Points(),
492     [[(-15.0821743011474, 66.2773818969726),
493     (-15.0263500213623, 66.2733917236328)]])
494    
495     def test_shape_raw_data(self):
496     """Test PostGISShapeStore.Shape(i).RawData() with ARC shapes"""
497     self.assertEquals(self.store.Shape(32).RawData(),
498     "MULTILINESTRING((-15.0821743011475 66.2773818969727,"
499     "-15.0263500213623 66.2733917236328))")
500    
501     def test_shapes_in_region(self):
502     """Test PostGISShapeStore.ShapesInRegion() with ARC shapes"""
503     shapes = self.store.ShapesInRegion((-24.0, 64.5, -23.5, 65.0))
504     self.assertEquals([s.ShapeID() for s in shapes], [573, 581, 613])
505    
506    
507    
508 bh 1656 class PolygonTests:
509 bh 1605
510 bh 1656 """Test shared by the PLYGON and MULTIPOLYGON tests
511 bh 1605
512 bh 1656 The tests are the same because they are based on the same data.
513     """
514    
515 bh 1605 def test_shape_type(self):
516     """Test PostGISShapeStore.ShapeType() with POLYGON shapes"""
517     self.assertEquals(self.store.ShapeType(), SHAPETYPE_POLYGON)
518    
519     def test_num_shapes(self):
520     """Test PostGISShapeStore.NumShapes() with POLYGON shapes"""
521     self.assertEquals(self.store.NumShapes(), 156)
522    
523     def test_bounding_box(self):
524     """Test PostGISShapeStore.BoundingBox() with POLYGON shapes"""
525     self.assertFloatSeqEqual(self.store.BoundingBox(),
526     [-24.546524047851562, 63.286754608154297,
527     -13.495815277099609, 66.563774108886719])
528    
529     def test_shape_shapeid(self):
530     """Test PostGISShapeStore.Shape(i).ShapeID() with POLYGON shapes"""
531     self.assertEquals(self.store.Shape(5).ShapeID(), 5)
532    
533     def test_shape_points(self):
534     """Test PostGISShapeStore.Shape(i).Points() with POLYGON shapes"""
535     self.assertPointListEquals(self.store.Shape(4).Points(),
536     [[(-22.40639114379882, 64.714111328125),
537     (-22.41621208190918, 64.716003417968),
538     (-22.40605163574218, 64.719200134277),
539     (-22.40639114379882, 64.714111328125)]])
540    
541 bh 1656 def test_shapes_in_region(self):
542     """Test PostGISShapeStore.ShapesInRegion() with POLYGON shapes"""
543     shapes = self.store.ShapesInRegion((-23.0, 65.5, -22.8, 65.25))
544     self.assertEquals([s.ShapeID() for s in shapes],
545     [47, 56, 59, 61, 62, 71, 144])
546    
547    
548     class TestPostGISShapestorePolygon(PolygonTests, PostGISStaticTests):
549    
550     """Tests for PostGISShapeStore objects with POLYGON data"""
551    
552     def setUp(self):
553     """Extend inherited method to set self.table to a PostGISShapeStore"""
554     PostGISStaticTests.setUp(self)
555     self.store = PostGISShapeStore(self.db, "political")
556    
557     def test_shape_type(self):
558     """Test PostGISShapeStore.ShapeType() with POLYGON shapes"""
559     self.assertEquals(self.store.ShapeType(), SHAPETYPE_POLYGON)
560    
561    
562 bh 1605 def test_shape_raw_data(self):
563     """Test PostGISShapeStore.Shape(i).RawData() with POLYGON shapes"""
564     self.assertEquals(self.store.Shape(4).RawData(),
565     "POLYGON((-22.4063911437988 64.714111328125,"
566     "-22.4162120819092 64.7160034179688,"
567     "-22.4060516357422 64.7192001342773,"
568     "-22.4063911437988 64.714111328125))")
569    
570    
571 bh 1656 class TestPostGISShapestoreMultiPolygon(PolygonTests, PostGISStaticTests):
572 bh 1605
573 bh 1656 """Tests for PostGISShapeStore objects with MUTLIPOLYGON data"""
574    
575     def setUp(self):
576     """Extend inherited method to set self.table to a PostGISShapeStore"""
577     PostGISStaticTests.setUp(self)
578     self.store = PostGISShapeStore(self.db, "political_multi")
579    
580     def test_shape_raw_data(self):
581     """Test PostGISShapeStore.Shape(i).RawData() with POLYGON shapes"""
582     self.assertEquals(self.store.Shape(4).RawData(),
583     "MULTIPOLYGON(((-22.4063911437988 64.714111328125,"
584     "-22.4162120819092 64.7160034179688,"
585     "-22.4060516357422 64.7192001342773,"
586     "-22.4063911437988 64.714111328125)))")
587    
588 bh 1693
589    
590 bh 1605 if __name__ == "__main__":
591     support.run_tests()

Properties

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26