Loading django/contrib/gis/tests/__init__.py +1 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ def geo_suite(): elif postgis: test_models += ['distapp', 'layermap', 'relatedapp'] elif mysql: test_models += ['relatedapp'] test_models += ['relatedapp', 'layermap'] test_suite_names += [ 'test_gdal_driver', Loading django/contrib/gis/tests/layermap/tests.py +8 −5 Original line number Diff line number Diff line import os, unittest from copy import copy from datetime import date from decimal import Decimal from models import City, County, CountyFeat, Interstate, State, city_mapping, co_mapping, cofeat_mapping, inter_mapping from django.contrib.gis.db.backend import SpatialBackend from django.contrib.gis.utils.layermapping import LayerMapping, LayerMapError, InvalidDecimal, MissingForeignKey from django.contrib.gis.gdal import DataSource Loading Loading @@ -85,7 +85,8 @@ class LayerMapTest(unittest.TestCase): lm = LayerMapping(Interstate, inter_shp, inter_mapping) lm.save(silent=True, strict=True) except InvalidDecimal: pass # No transactions for geoms on MySQL; delete added features. if SpatialBackend.mysql: Interstate.objects.all().delete() else: self.fail('Should have failed on strict import with invalid decimal values.') Loading Loading @@ -151,6 +152,7 @@ class LayerMapTest(unittest.TestCase): self.assertRaises(e, LayerMapping, County, co_shp, co_mapping, transform=False, unique=arg) # No source reference system defined in the shapefile, should raise an error. if not SpatialBackend.mysql: self.assertRaises(LayerMapError, LayerMapping, County, co_shp, co_mapping) # Passing in invalid ForeignKey mapping parameters -- must be a dictionary Loading Loading @@ -227,8 +229,9 @@ class LayerMapTest(unittest.TestCase): lm.save(fid_range=slice(None, 1), silent=True, strict=True) # layer[:1] # Only Pueblo & Honolulu counties should be present because of # the `unique` keyword. qs = County.objects.all() # the `unique` keyword. Have to set `order_by` on this QuerySet # or else MySQL will return a different ordering than the other dbs. qs = County.objects.order_by('name') self.assertEqual(2, qs.count()) hi, co = tuple(qs) hi_idx, co_idx = tuple(map(NAMES.index, ('Honolulu', 'Pueblo'))) Loading django/contrib/gis/tests/layermap/tests_mysql.py 0 → 100644 +1 −0 Original line number Diff line number Diff line from tests import * django/contrib/gis/utils/layermapping.py +8 −3 Original line number Diff line number Diff line Loading @@ -116,7 +116,6 @@ from django.contrib.gis.gdal import CoordTransform, DataSource, \ OGRException, OGRGeometry, OGRGeomType, SpatialReference from django.contrib.gis.gdal.field import \ OFTDate, OFTDateTime, OFTInteger, OFTReal, OFTString, OFTTime from django.contrib.gis.models import GeometryColumns, SpatialRefSys from django.db import models, transaction from django.contrib.localflavor.us.models import USStateField Loading Loading @@ -189,6 +188,9 @@ class LayerMapping(object): # Getting the geometry column associated with the model (an # exception will be raised if there is no geometry column). if SpatialBackend.mysql: transform = False else: self.geo_col = self.geometry_column() # Checking the source spatial reference system, and getting Loading Loading @@ -327,6 +329,7 @@ class LayerMapping(object): def check_srs(self, source_srs): "Checks the compatibility of the given spatial reference object." from django.contrib.gis.models import SpatialRefSys if isinstance(source_srs, SpatialReference): sr = source_srs elif isinstance(source_srs, SpatialRefSys): Loading Loading @@ -498,6 +501,7 @@ class LayerMapping(object): #### Other model methods #### def coord_transform(self): "Returns the coordinate transformation object." from django.contrib.gis.models import SpatialRefSys try: # Getting the target spatial reference system target_srs = SpatialRefSys.objects.get(srid=self.geo_col.srid).srs Loading @@ -509,11 +513,12 @@ class LayerMapping(object): def geometry_column(self): "Returns the GeometryColumn model associated with the geographic column." from django.contrib.gis.models import GeometryColumns # Getting the GeometryColumn object. try: db_table = self.model._meta.db_table geo_col = self.geom_field if SpatialBackend.name == 'oracle': if SpatialBackend.oracle: # Making upper case for Oracle. db_table = db_table.upper() geo_col = geo_col.upper() Loading Loading
django/contrib/gis/tests/__init__.py +1 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ def geo_suite(): elif postgis: test_models += ['distapp', 'layermap', 'relatedapp'] elif mysql: test_models += ['relatedapp'] test_models += ['relatedapp', 'layermap'] test_suite_names += [ 'test_gdal_driver', Loading
django/contrib/gis/tests/layermap/tests.py +8 −5 Original line number Diff line number Diff line import os, unittest from copy import copy from datetime import date from decimal import Decimal from models import City, County, CountyFeat, Interstate, State, city_mapping, co_mapping, cofeat_mapping, inter_mapping from django.contrib.gis.db.backend import SpatialBackend from django.contrib.gis.utils.layermapping import LayerMapping, LayerMapError, InvalidDecimal, MissingForeignKey from django.contrib.gis.gdal import DataSource Loading Loading @@ -85,7 +85,8 @@ class LayerMapTest(unittest.TestCase): lm = LayerMapping(Interstate, inter_shp, inter_mapping) lm.save(silent=True, strict=True) except InvalidDecimal: pass # No transactions for geoms on MySQL; delete added features. if SpatialBackend.mysql: Interstate.objects.all().delete() else: self.fail('Should have failed on strict import with invalid decimal values.') Loading Loading @@ -151,6 +152,7 @@ class LayerMapTest(unittest.TestCase): self.assertRaises(e, LayerMapping, County, co_shp, co_mapping, transform=False, unique=arg) # No source reference system defined in the shapefile, should raise an error. if not SpatialBackend.mysql: self.assertRaises(LayerMapError, LayerMapping, County, co_shp, co_mapping) # Passing in invalid ForeignKey mapping parameters -- must be a dictionary Loading Loading @@ -227,8 +229,9 @@ class LayerMapTest(unittest.TestCase): lm.save(fid_range=slice(None, 1), silent=True, strict=True) # layer[:1] # Only Pueblo & Honolulu counties should be present because of # the `unique` keyword. qs = County.objects.all() # the `unique` keyword. Have to set `order_by` on this QuerySet # or else MySQL will return a different ordering than the other dbs. qs = County.objects.order_by('name') self.assertEqual(2, qs.count()) hi, co = tuple(qs) hi_idx, co_idx = tuple(map(NAMES.index, ('Honolulu', 'Pueblo'))) Loading
django/contrib/gis/tests/layermap/tests_mysql.py 0 → 100644 +1 −0 Original line number Diff line number Diff line from tests import *
django/contrib/gis/utils/layermapping.py +8 −3 Original line number Diff line number Diff line Loading @@ -116,7 +116,6 @@ from django.contrib.gis.gdal import CoordTransform, DataSource, \ OGRException, OGRGeometry, OGRGeomType, SpatialReference from django.contrib.gis.gdal.field import \ OFTDate, OFTDateTime, OFTInteger, OFTReal, OFTString, OFTTime from django.contrib.gis.models import GeometryColumns, SpatialRefSys from django.db import models, transaction from django.contrib.localflavor.us.models import USStateField Loading Loading @@ -189,6 +188,9 @@ class LayerMapping(object): # Getting the geometry column associated with the model (an # exception will be raised if there is no geometry column). if SpatialBackend.mysql: transform = False else: self.geo_col = self.geometry_column() # Checking the source spatial reference system, and getting Loading Loading @@ -327,6 +329,7 @@ class LayerMapping(object): def check_srs(self, source_srs): "Checks the compatibility of the given spatial reference object." from django.contrib.gis.models import SpatialRefSys if isinstance(source_srs, SpatialReference): sr = source_srs elif isinstance(source_srs, SpatialRefSys): Loading Loading @@ -498,6 +501,7 @@ class LayerMapping(object): #### Other model methods #### def coord_transform(self): "Returns the coordinate transformation object." from django.contrib.gis.models import SpatialRefSys try: # Getting the target spatial reference system target_srs = SpatialRefSys.objects.get(srid=self.geo_col.srid).srs Loading @@ -509,11 +513,12 @@ class LayerMapping(object): def geometry_column(self): "Returns the GeometryColumn model associated with the geographic column." from django.contrib.gis.models import GeometryColumns # Getting the GeometryColumn object. try: db_table = self.model._meta.db_table geo_col = self.geom_field if SpatialBackend.name == 'oracle': if SpatialBackend.oracle: # Making upper case for Oracle. db_table = db_table.upper() geo_col = geo_col.upper() Loading