mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Add a test for the geo-enabled inspectdb command
This commit is contained in:
		| @@ -9,5 +9,6 @@ class AllOGRFields(models.Model): | |||||||
|     f_datetime = models.DateTimeField() |     f_datetime = models.DateTimeField() | ||||||
|     f_time = models.TimeField() |     f_time = models.TimeField() | ||||||
|     geom = models.PolygonField() |     geom = models.PolygonField() | ||||||
|  |     point = models.PointField() | ||||||
|  |  | ||||||
|     objects = models.GeoManager() |     objects = models.GeoManager() | ||||||
|   | |||||||
| @@ -3,11 +3,13 @@ from __future__ import unicode_literals | |||||||
| import os | import os | ||||||
| from unittest import skipUnless | from unittest import skipUnless | ||||||
|  |  | ||||||
|  | from django.core.management import call_command | ||||||
| from django.db import connections | from django.db import connections | ||||||
| from django.test import TestCase | from django.test import TestCase | ||||||
| from django.contrib.gis.gdal import HAS_GDAL | from django.contrib.gis.gdal import HAS_GDAL | ||||||
| from django.contrib.gis.geometry.test_data import TEST_DATA | from django.contrib.gis.geometry.test_data import TEST_DATA | ||||||
| from django.contrib.gis.tests.utils import HAS_SPATIAL_DB | from django.contrib.gis.tests.utils import HAS_SPATIAL_DB | ||||||
|  | from django.utils.six import StringIO | ||||||
|  |  | ||||||
| if HAS_GDAL: | if HAS_GDAL: | ||||||
|     from django.contrib.gis.gdal import Driver |     from django.contrib.gis.gdal import Driver | ||||||
| @@ -16,6 +18,22 @@ if HAS_GDAL: | |||||||
|     from .models import AllOGRFields |     from .models import AllOGRFields | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @skipUnless(HAS_GDAL and HAS_SPATIAL_DB, "GDAL and spatial db are required.") | ||||||
|  | class InspectDbTests(TestCase): | ||||||
|  |     def test_geom_columns(self): | ||||||
|  |         """ | ||||||
|  |         Test the geo-enabled inspectdb command. | ||||||
|  |         """ | ||||||
|  |         out = StringIO() | ||||||
|  |         call_command('inspectdb', | ||||||
|  |                  table_name_filter=lambda tn:tn.startswith('inspectapp_'), | ||||||
|  |                  stdout=out) | ||||||
|  |         output = out.getvalue() | ||||||
|  |         self.assertIn('geom = models.PolygonField()', output) | ||||||
|  |         self.assertIn('point = models.PointField()', output) | ||||||
|  |         self.assertIn('objects = models.GeoManager()', output) | ||||||
|  |  | ||||||
|  |  | ||||||
| @skipUnless(HAS_GDAL and HAS_SPATIAL_DB, "GDAL and spatial db are required.") | @skipUnless(HAS_GDAL and HAS_SPATIAL_DB, "GDAL and spatial db are required.") | ||||||
| class OGRInspectTest(TestCase): | class OGRInspectTest(TestCase): | ||||||
|     maxDiff = 1024 |     maxDiff = 1024 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user