/[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 2057 - (hide annotations)
Tue Feb 10 15:51:57 2004 UTC (21 years ago) by bh
Original Path: trunk/thuban/test/test_postgis_db.py
File MIME type: text/x-python
File size: 26803 byte(s)
* Thuban/Model/postgisdb.py (quote_identifier): Fix typo in
doc-string
(PostGISShapeStore._fetch_table_information): New. Extend
inherited method to retrieve srid
(PostGISShapeStore.BoundingBox): Handle tables without data.
extent yields NULL for those
(PostGISShapeStore.ShapesInRegion): Use the srid of the table.

* test/test_postgis_db.py
(TestPostGISSpecialCases.test_shapestore_empty_table): New test
for the special case of a table without any data
(TestPostGISShapestorePointSRID): New class with tests for a table
that uses srids
(PolygonTests): Fix a doc-string typo

* test/postgissupport.py (PostGISDatabase.__init__): New parameter
reference_systems with a specification of spacial reference
systems to create in the new db.
(PostgreSQLServer.new_postgis_db)
(PostgreSQLServer.get_static_data_db): New parameter
reference_systems to be passed through ultimately to
PostGISDatabase.  In new_postgis_db also check whether an existing
db already has the right srids
(PostgreSQLServer.get_default_static_data_db): Add srids and a
table that uses srids
(PostGISDatabase.initdb): Create the entries for the reference
systems
(PostGISDatabase.has_data): Add reference_systems parameter to
check for those too
(upload_shapefile): New parameter srid to create tables with a
specific srid

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