2011-10-17 00:40:19 +02:00
|
|
|
import os
|
|
|
|
import re
|
2012-10-19 12:19:01 +02:00
|
|
|
|
2011-10-17 00:40:19 +02:00
|
|
|
from sqlalchemy import Table
|
2012-10-19 12:19:01 +02:00
|
|
|
from nose.plugins.skip import SkipTest
|
|
|
|
|
|
|
|
from ckan.model import Session, repo, meta, engine_is_sqlite
|
|
|
|
from ckanext.spatial.model.package_extent import setup as spatial_db_setup, define_spatial_tables
|
|
|
|
from ckanext.harvest.model import setup as harvest_model_setup
|
2011-10-17 00:40:19 +02:00
|
|
|
|
|
|
|
def setup_postgis_tables():
|
|
|
|
|
|
|
|
conn = Session.connection()
|
|
|
|
script_path = os.path.join(os.path.dirname(os.path.abspath( __file__ )), 'scripts', 'postgis.sql')
|
|
|
|
script = open(script_path,'r').read()
|
|
|
|
for cmd in script.split(';'):
|
|
|
|
cmd = re.sub(r'--(.*)|[\n\t]','',cmd)
|
|
|
|
if len(cmd):
|
|
|
|
conn.execute(cmd)
|
|
|
|
|
|
|
|
Session.commit()
|
|
|
|
|
|
|
|
|
|
|
|
class SpatialTestBase:
|
|
|
|
|
|
|
|
db_srid = 4326
|
|
|
|
|
|
|
|
geojson_examples = {
|
|
|
|
'point':'{"type":"Point","coordinates":[100.0,0.0]}',
|
2012-02-22 13:26:52 +01:00
|
|
|
'point_2':'{"type":"Point","coordinates":[20,10]}',
|
2011-10-17 00:40:19 +02:00
|
|
|
'line':'{"type":"LineString","coordinates":[[100.0,0.0],[101.0,1.0]]}',
|
|
|
|
'polygon':'{"type":"Polygon","coordinates":[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]]]}',
|
|
|
|
'polygon_holes':'{"type":"Polygon","coordinates":[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]],[[100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2]]]}',
|
|
|
|
'multipoint':'{"type":"MultiPoint","coordinates":[[100.0,0.0],[101.0,1.0]]}',
|
|
|
|
'multiline':'{"type":"MultiLineString","coordinates":[[[100.0,0.0],[101.0,1.0]],[[102.0,2.0],[103.0,3.0]]]}',
|
|
|
|
'multipolygon':'{"type":"MultiPolygon","coordinates":[[[[102.0,2.0],[103.0,2.0],[103.0,3.0],[102.0,3.0],[102.0,2.0]]],[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]],[[100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2]]]]}'}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setup_class(cls):
|
2012-10-19 12:19:01 +02:00
|
|
|
if engine_is_sqlite():
|
|
|
|
raise SkipTest("PostGIS is required for this test")
|
|
|
|
|
2011-10-17 00:40:19 +02:00
|
|
|
# This will create the PostGIS tables (geometry_columns and
|
|
|
|
# spatial_ref_sys) which were deleted when rebuilding the database
|
|
|
|
table = Table('geometry_columns', meta.metadata)
|
|
|
|
if not table.exists():
|
|
|
|
setup_postgis_tables()
|
|
|
|
|
2012-02-07 17:50:46 +01:00
|
|
|
spatial_db_setup()
|
|
|
|
|
2012-10-19 12:19:01 +02:00
|
|
|
# Setup the harvest tables
|
|
|
|
harvest_model_setup()
|
2011-10-17 00:40:19 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def teardown_class(cls):
|
|
|
|
repo.rebuild_db()
|
|
|
|
|