Ticket #15277: 15277.2.patch
File 15277.2.patch, 3.9 KB (added by , 13 years ago) |
---|
-
django/contrib/gis/tests/__init__.py
diff --git django/contrib/gis/tests/__init__.py django/contrib/gis/tests/__init__.py index 3d04242..14f1ccc 100644
def geodjango_suite(apps=True): 61 61 from django.contrib.gis.tests import test_measure 62 62 suite.addTest(test_measure.suite()) 63 63 64 # Adding the ogrinspect tests. 65 from django.contrib.gis.tests import test_ogrinspect 66 suite.addTest(test_ogrinspect.suite()) 67 64 68 # Adding GDAL tests, and any test suite that depends on GDAL, to the 65 69 # suite if GDAL is available. 66 70 from django.contrib.gis.gdal import HAS_GDAL -
new file django/contrib/gis/tests/test_ogrinspect.py
diff --git django/contrib/gis/tests/test_ogrinspect.py django/contrib/gis/tests/test_ogrinspect.py new file mode 100644 index 0000000..1e79b86
- + 1 import os 2 from django.contrib.gis.utils.ogrinspect import ogrinspect 3 from django.contrib.gis.geometry.test_data import TEST_DATA 4 from django.utils import unittest 5 6 class OGRInspectTest(unittest.TestCase): 7 def test_poly(self): 8 shp_file = os.path.join(TEST_DATA, 'test_poly', 'test_poly.shp') 9 model_def = ogrinspect(shp_file, 'MyModel') 10 11 expected = [ 12 '# This is an auto-generated Django model module created by ogrinspect.', 13 'from django.contrib.gis.db import models', 14 '', 15 'class MyModel(models.Model):', 16 ' float = models.FloatField()', 17 ' int = models.FloatField()', 18 ' str = models.CharField(max_length=80)', 19 ' geom = models.PolygonField(srid=-1)', 20 ' objects = models.GeoManager()', 21 ] 22 23 self.assertEqual(model_def, '\n'.join(expected)) 24 25 def test_date_field(self): 26 shp_file = os.path.join(TEST_DATA, 'cities', 'cities.shp') 27 model_def = ogrinspect(shp_file, 'City') 28 29 expected = [ 30 '# This is an auto-generated Django model module created by ogrinspect.', 31 'from django.contrib.gis.db import models', 32 '', 33 'class City(models.Model):', 34 ' name = models.CharField(max_length=80)', 35 ' population = models.FloatField()', 36 ' density = models.FloatField()', 37 ' created = models.DateField()', 38 ' geom = models.PointField(srid=-1)', 39 ' objects = models.GeoManager()', 40 ] 41 42 self.assertEqual(model_def, '\n'.join(expected)) 43 44 def suite(): 45 s = unittest.TestSuite() 46 s.addTest(unittest.makeSuite(OGRInspectTest)) 47 return s 48 49 def run(verbosity=2): 50 unittest.TextTestRunner(verbosity=verbosity).run(suite()) 51 52 if __name__=="__main__": 53 run() -
django/contrib/gis/utils/ogrinspect.py
diff --git django/contrib/gis/utils/ogrinspect.py django/contrib/gis/utils/ogrinspect.py index fe4443c..aa4e209 100644
Author: Travis Pinney, Dane Springmeyer, & Justin Bronn 8 8 from itertools import izip 9 9 # Requires GDAL to use. 10 10 from django.contrib.gis.gdal import DataSource 11 from django.contrib.gis.gdal.field import OFTDate, OFTDateTime, OFTInteger, OFTReal, OFTString 11 from django.contrib.gis.gdal.field import OFTDate, OFTDateTime, OFTInteger, OFTReal, OFTString, OFTTime 12 12 13 13 def mapping(data_source, geom_name='geom', layer_key=0, multi_geom=False): 14 14 """ … … def _ogrinspect(data_source, model_name, geom_name='geom', layer_key=0, srid=Non 189 189 yield ' %s = models.DateField(%s)' % (mfield, kwargs_str[2:]) 190 190 elif field_type is OFTDateTime: 191 191 yield ' %s = models.DateTimeField(%s)' % (mfield, kwargs_str[2:]) 192 elif field_type is OFT Date:192 elif field_type is OFTTime: 193 193 yield ' %s = models.TimeField(%s)' % (mfield, kwargs_str[2:]) 194 194 else: 195 195 raise TypeError('Unknown field type %s in %s' % (field_type, mfield))