|
@@ -70,6 +70,7 @@ class OGRInspectTest(TestCase):
|
|
|
'# This is an auto-generated Django model module created by ogrinspect.',
|
|
|
'from django.contrib.gis.db import models',
|
|
|
'',
|
|
|
+ '',
|
|
|
'class MyModel(models.Model):',
|
|
|
' float = models.FloatField()',
|
|
|
' int = models.{}()'.format('BigIntegerField' if GDAL_VERSION >= (2, 0) else 'FloatField'),
|
|
@@ -96,6 +97,7 @@ class OGRInspectTest(TestCase):
|
|
|
'# This is an auto-generated Django model module created by ogrinspect.',
|
|
|
'from django.contrib.gis.db import models',
|
|
|
'',
|
|
|
+ '',
|
|
|
'class City(models.Model):',
|
|
|
' name = models.CharField(max_length=80)',
|
|
|
' population = models.{}()'.format('BigIntegerField' if GDAL_VERSION >= (2, 0) else 'FloatField'),
|
|
@@ -126,6 +128,7 @@ class OGRInspectTest(TestCase):
|
|
|
'# This is an auto-generated Django model module created by ogrinspect.\n'
|
|
|
'from django.contrib.gis.db import models\n'
|
|
|
'\n'
|
|
|
+ '\n'
|
|
|
'class Measurement(models.Model):\n'
|
|
|
))
|
|
|
|
|
@@ -148,6 +151,24 @@ class OGRInspectTest(TestCase):
|
|
|
output = out.getvalue()
|
|
|
self.assertIn('class City(models.Model):', output)
|
|
|
|
|
|
+ def test_mapping_option(self):
|
|
|
+ expected = (
|
|
|
+ " geom = models.PointField(srid=-1)\n"
|
|
|
+ "\n"
|
|
|
+ "\n"
|
|
|
+ "# Auto-generated `LayerMapping` dictionary for City model\n"
|
|
|
+ "city_mapping = {\n"
|
|
|
+ " 'name': 'Name',\n"
|
|
|
+ " 'population': 'Population',\n"
|
|
|
+ " 'density': 'Density',\n"
|
|
|
+ " 'created': 'Created',\n"
|
|
|
+ " 'geom': 'POINT',\n"
|
|
|
+ "}\n")
|
|
|
+ shp_file = os.path.join(TEST_DATA, 'cities', 'cities.shp')
|
|
|
+ out = StringIO()
|
|
|
+ call_command('ogrinspect', shp_file, '--mapping', 'City', stdout=out)
|
|
|
+ self.assertIn(expected, out.getvalue())
|
|
|
+
|
|
|
|
|
|
def get_ogr_db_string():
|
|
|
"""
|