Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

GeoDjango test suite housekeeping. Moved data into fixtures for `rela…

…tedapp` and `distapp` tests, and made both use Django's `TestCase`; moved functionality out of `GeoDjangoTestSuiteRunner` to allow future re-use in `runtests.py` (refs #10420); compressed test app fixtures and cleaned up imports.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14776 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0f879195a6bf2778359020e2f8afff4b6e670ca1 1 parent fb391b8
Justin Bronn authored December 02, 2010
166  django/contrib/gis/tests/__init__.py
... ...
@@ -1,15 +1,12 @@
1  
-import sys
2  
-
3 1
 from django.conf import settings
4  
-from django.db.models import get_app
5 2
 from django.test.simple import build_suite, DjangoTestSuiteRunner
6 3
 from django.utils import unittest
7 4
 
8  
-
9 5
 def run_tests(*args, **kwargs):
10 6
     from django.test.simple import run_tests as base_run_tests
11 7
     return base_run_tests(*args, **kwargs)
12 8
 
  9
+
13 10
 def run_gis_tests(test_labels, verbosity=1, interactive=True, failfast=False, extra_tests=None):
14 11
     import warnings
15 12
     warnings.warn(
@@ -19,94 +16,121 @@ def run_gis_tests(test_labels, verbosity=1, interactive=True, failfast=False, ex
19 16
     test_runner = GeoDjangoTestSuiteRunner(verbosity=verbosity, interactive=interactive, failfast=failfast)
20 17
     return test_runner.run_tests(test_labels, extra_tests=extra_tests)
21 18
 
22  
-class GeoDjangoTestSuiteRunner(DjangoTestSuiteRunner):
23 19
 
24  
-    def setup_test_environment(self, **kwargs):
25  
-        super(GeoDjangoTestSuiteRunner, self).setup_test_environment(**kwargs)
  20
+def geo_apps(namespace=True):
  21
+    """
  22
+    Returns a list of GeoDjango test applications that reside in
  23
+    `django.contrib.gis.tests` that can be used with the current
  24
+    database and the spatial libraries that are installed.
  25
+    """
  26
+    from django.db import connection
  27
+    from django.contrib.gis.geos import GEOS_PREPARE
  28
+    from django.contrib.gis.gdal import HAS_GDAL
26 29
 
27  
-        from django.db import connection
28  
-        from django.contrib.gis.geos import GEOS_PREPARE
29  
-        from django.contrib.gis.gdal import HAS_GDAL
  30
+    apps = ['geoapp', 'relatedapp']
30 31
 
31  
-        # Getting and storing the original values of INSTALLED_APPS and
32  
-        # the ROOT_URLCONF.
33  
-        self.old_installed = getattr(settings, 'INSTALLED_APPS', None)
34  
-        self.old_root_urlconf = getattr(settings, 'ROOT_URLCONF', None)
35  
-        self.old_site_id = getattr(settings, 'SITE_ID', None)
  32
+    # No distance queries on MySQL.
  33
+    if not connection.ops.mysql:
  34
+        apps.append('distapp')
  35
+
  36
+    # Test geography support with PostGIS 1.5+.
  37
+    if connection.ops.postgis and connection.ops.geography:
  38
+        apps.append('geogapp')
  39
+
  40
+    # The following GeoDjango test apps depend on GDAL support.
  41
+    if HAS_GDAL:
  42
+        # 3D apps use LayerMapping, which uses GDAL.
  43
+        if connection.ops.postgis and GEOS_PREPARE:
  44
+            apps.append('geo3d')
  45
+
  46
+        apps.append('layermap')
  47
+
  48
+    if namespace:
  49
+        return ['django.contrib.gis.tests.%s' % app
  50
+                for app in apps]
  51
+    else:
  52
+        return apps
  53
+
  54
+
  55
+def geodjango_suite():
  56
+    """
  57
+    Returns a TestSuite consisting only of GeoDjango tests that can be run.
  58
+    """
  59
+    import sys
  60
+    from django.db.models import get_app
  61
+
  62
+    suite = unittest.TestSuite()
  63
+
  64
+    # Adding the GEOS tests.
  65
+    from django.contrib.gis.geos import tests as geos_tests
  66
+    suite.addTest(geos_tests.suite())
36 67
 
37  
-        # Tests that require use of a spatial database (e.g., creation of models)
38  
-        self.geo_apps = ['geoapp', 'relatedapp']
39  
-        if connection.ops.postgis and connection.ops.geography:
40  
-            # Test geography support with PostGIS 1.5+.
41  
-            self.geo_apps.append('geogapp')
  68
+    # Adding the measurment tests.
  69
+    from django.contrib.gis.tests import test_measure
  70
+    suite.addTest(test_measure.suite())
42 71
 
43  
-        if HAS_GDAL:
44  
-            # The following GeoDjango test apps depend on GDAL support.
45  
-            if not connection.ops.mysql:
46  
-                self.geo_apps.append('distapp')
  72
+    # Adding GDAL tests, and any test suite that depends on GDAL, to the
  73
+    # suite if GDAL is available.
  74
+    from django.contrib.gis.gdal import HAS_GDAL
  75
+    if HAS_GDAL:
  76
+        from django.contrib.gis.gdal import tests as gdal_tests
  77
+        suite.addTest(gdal_tests.suite())
47 78
 
48  
-            # 3D apps use LayerMapping, which uses GDAL.
49  
-            if connection.ops.postgis and GEOS_PREPARE:
50  
-                self.geo_apps.append('geo3d')
  79
+        from django.contrib.gis.tests import test_spatialrefsys, test_geoforms
  80
+        suite.addTest(test_spatialrefsys.suite())
  81
+        suite.addTest(test_geoforms.suite())
  82
+    else:
  83
+        sys.stderr.write('GDAL not available - no tests requiring GDAL will be run.\n')
51 84
 
52  
-            self.geo_apps.append('layermap')
  85
+    # Add GeoIP tests to the suite, if the library and data is available.
  86
+    from django.contrib.gis.utils import HAS_GEOIP
  87
+    if HAS_GEOIP and hasattr(settings, 'GEOIP_PATH'):
  88
+        from django.contrib.gis.tests import test_geoip
  89
+        suite.addTest(test_geoip.suite())
  90
+
  91
+    # Finally, adding the suites for each of the GeoDjango test apps.
  92
+    for app_name in geo_apps(namespace=False):
  93
+        suite.addTest(build_suite(get_app(app_name)))
  94
+
  95
+    return suite
  96
+
  97
+
  98
+class GeoDjangoTestSuiteRunner(DjangoTestSuiteRunner):
  99
+
  100
+    def setup_test_environment(self, **kwargs):
  101
+        super(GeoDjangoTestSuiteRunner, self).setup_test_environment(**kwargs)
  102
+
  103
+        # Saving original values of INSTALLED_APPS, ROOT_URLCONF, and SITE_ID.
  104
+        self.old_installed = getattr(settings, 'INSTALLED_APPS', None)
  105
+        self.old_root_urlconf = getattr(settings, 'ROOT_URLCONF', '')
  106
+        self.old_site_id = getattr(settings, 'SITE_ID', None)
53 107
 
54 108
         # Constructing the new INSTALLED_APPS, and including applications
55  
-        # within the GeoDjango test namespace (`self.geo_apps`).
  109
+        # within the GeoDjango test namespace.
56 110
         new_installed =  ['django.contrib.sites',
57 111
                           'django.contrib.sitemaps',
58 112
                           'django.contrib.gis',
59 113
                           ]
60  
-        new_installed.extend(['django.contrib.gis.tests.%s' % app
61  
-                              for app in self.geo_apps])
  114
+
  115
+        # Calling out to `geo_apps` to get GeoDjango applications supported
  116
+        # for testing.
  117
+        new_installed.extend(geo_apps())
62 118
         settings.INSTALLED_APPS = new_installed
63 119
 
64  
-        # Setting the URLs.
65  
-        settings.ROOT_URLCONF = 'django.contrib.gis.tests.urls'
  120
+        # SITE_ID needs to be set
66 121
         settings.SITE_ID = 1
67 122
 
  123
+        # ROOT_URLCONF needs to be set, else `AttributeErrors` are raised
  124
+        # when TestCases are torn down that have `urls` defined.
  125
+        settings.ROOT_URLCONF = ''
  126
+
  127
+
68 128
     def teardown_test_environment(self, **kwargs):
69 129
         super(GeoDjangoTestSuiteRunner, self).teardown_test_environment(**kwargs)
70 130
         settings.INSTALLED_APPS = self.old_installed
71 131
         settings.ROOT_URLCONF = self.old_root_urlconf
72 132
         settings.SITE_ID = self.old_site_id
73 133
 
  134
+
74 135
     def build_suite(self, test_labels, extra_tests=None, **kwargs):
75  
-        """
76  
-        This method is overridden to construct a suite consisting only of tests
77  
-        for GeoDjango.
78  
-        """
79  
-        suite = unittest.TestSuite()
80  
-
81  
-        # Adding the GEOS tests.
82  
-        from django.contrib.gis.geos import tests as geos_tests
83  
-        suite.addTest(geos_tests.suite())
84  
-
85  
-        # Adding the measurment tests.
86  
-        from django.contrib.gis.tests import test_measure
87  
-        suite.addTest(test_measure.suite())
88  
-
89  
-        # Adding GDAL tests, and any test suite that depends on GDAL, to the
90  
-        # suite if GDAL is available.
91  
-        from django.contrib.gis.gdal import HAS_GDAL
92  
-        if HAS_GDAL:
93  
-            from django.contrib.gis.gdal import tests as gdal_tests
94  
-            suite.addTest(gdal_tests.suite())
95  
-
96  
-            from django.contrib.gis.tests import test_spatialrefsys, test_geoforms
97  
-            suite.addTest(test_spatialrefsys.suite())
98  
-            suite.addTest(test_geoforms.suite())
99  
-        else:
100  
-            sys.stderr.write('GDAL not available - no tests requiring GDAL will be run.\n')
101  
-
102  
-        # Add GeoIP tests to the suite, if the library and data is available.
103  
-        from django.contrib.gis.utils import HAS_GEOIP
104  
-        if HAS_GEOIP and hasattr(settings, 'GEOIP_PATH'):
105  
-            from django.contrib.gis.tests import test_geoip
106  
-            suite.addTest(test_geoip.suite())
107  
-
108  
-        # Finally, adding the suites for each of the GeoDjango test apps.
109  
-        for app_name in self.geo_apps:
110  
-            suite.addTest(build_suite(get_app(app_name)))
111  
-
112  
-        return suite
  136
+        return geodjango_suite()
36  django/contrib/gis/tests/distapp/data.py
... ...
@@ -1,36 +0,0 @@
1  
-au_cities = (('Wollongong', 150.902, -34.4245),
2  
-             ('Shellharbour', 150.87, -34.5789),
3  
-             ('Thirroul', 150.924, -34.3147),
4  
-             ('Mittagong', 150.449, -34.4509),
5  
-             ('Batemans Bay', 150.175, -35.7082),
6  
-             ('Canberra', 144.963, -37.8143),
7  
-             ('Melbourne', 145.963, -37.8143),
8  
-             ('Sydney', 151.26071, -33.887034),
9  
-             ('Hobart', 147.33, -42.8827),
10  
-             ('Adelaide', 138.6, -34.9258),
11  
-             ('Hillsdale', 151.231341, -33.952685),
12  
-             )
13  
-
14  
-stx_cities = (('Downtown Houston', -95.363151, 29.763374),
15  
-              ('West University Place', -95.448601, 29.713803),
16  
-              ('Southside Place', -95.436920, 29.705777),
17  
-              ('Bellaire', -95.458732, 29.705614),
18  
-              ('Pearland', -95.287303, 29.563568),
19  
-              ('Galveston', -94.797489, 29.301336),
20  
-              ('Sealy', -96.156952, 29.780918),
21  
-              ('San Antonio', -98.493183, 29.424170),
22  
-              ('Saint Hedwig', -98.199820, 29.414197),
23  
-              )
24  
-
25  
-# Data from U.S. Census ZCTA cartographic boundary file for Texas (`zt48_d00.shp`).
26  
-stx_zips = (('77002', 'POLYGON ((-95.365015 29.772327, -95.362415 29.772327, -95.360915 29.771827, -95.354615 29.771827, -95.351515 29.772527, -95.350915 29.765327, -95.351015 29.762436, -95.350115 29.760328, -95.347515 29.758528, -95.352315 29.753928, -95.356415 29.756328, -95.358215 29.754028, -95.360215 29.756328, -95.363415 29.757128, -95.364014 29.75638, -95.363415 29.753928, -95.360015 29.751828, -95.361815 29.749528, -95.362715 29.750028, -95.367516 29.744128, -95.369316 29.745128, -95.373916 29.744128, -95.380116 29.738028, -95.387916 29.727929, -95.388516 29.729629, -95.387916 29.732129, -95.382916 29.737428, -95.376616 29.742228, -95.372616 29.747228, -95.378601 29.750846, -95.378616 29.752028, -95.378616 29.754428, -95.376016 29.754528, -95.374616 29.759828, -95.373616 29.761128, -95.371916 29.763928, -95.372316 29.768727, -95.365884 29.76791, -95.366015 29.767127, -95.358715 29.765327, -95.358615 29.766327, -95.359115 29.767227, -95.360215 29.767027, -95.362783 29.768267, -95.365315 29.770527, -95.365015 29.772327))'),
27  
-            ('77005', 'POLYGON ((-95.447918 29.727275, -95.428017 29.728729, -95.421117 29.729029, -95.418617 29.727629, -95.418517 29.726429, -95.402117 29.726629, -95.402117 29.725729, -95.395316 29.725729, -95.391916 29.726229, -95.389716 29.725829, -95.396517 29.715429, -95.397517 29.715929, -95.400917 29.711429, -95.411417 29.715029, -95.418417 29.714729, -95.418317 29.70623, -95.440818 29.70593, -95.445018 29.70683, -95.446618 29.70763, -95.447418 29.71003, -95.447918 29.727275))'),
28  
-            ('77025', 'POLYGON ((-95.418317 29.70623, -95.414717 29.706129, -95.414617 29.70533, -95.418217 29.70533, -95.419817 29.69533, -95.419484 29.694196, -95.417166 29.690901, -95.414517 29.69433, -95.413317 29.69263, -95.412617 29.68973, -95.412817 29.68753, -95.414087 29.685055, -95.419165 29.685428, -95.421617 29.68513, -95.425717 29.67983, -95.425017 29.67923, -95.424517 29.67763, -95.427418 29.67763, -95.438018 29.664631, -95.436713 29.664411, -95.440118 29.662231, -95.439218 29.661031, -95.437718 29.660131, -95.435718 29.659731, -95.431818 29.660331, -95.441418 29.656631, -95.441318 29.656331, -95.441818 29.656131, -95.441718 29.659031, -95.441118 29.661031, -95.446718 29.656431, -95.446518 29.673431, -95.446918 29.69013, -95.447418 29.71003, -95.446618 29.70763, -95.445018 29.70683, -95.440818 29.70593, -95.418317 29.70623))'),
29  
-            ('77401', 'POLYGON ((-95.447918 29.727275, -95.447418 29.71003, -95.446918 29.69013, -95.454318 29.68893, -95.475819 29.68903, -95.475819 29.69113, -95.484419 29.69103, -95.484519 29.69903, -95.480419 29.70133, -95.480419 29.69833, -95.474119 29.69833, -95.474119 29.70453, -95.472719 29.71283, -95.468019 29.71293, -95.468219 29.720229, -95.464018 29.720229, -95.464118 29.724529, -95.463018 29.725929, -95.459818 29.726129, -95.459918 29.720329, -95.451418 29.720429, -95.451775 29.726303, -95.451318 29.727029, -95.447918 29.727275))'),
30  
-            )
31  
-
32  
-interstates = (('I-25', 'LINESTRING(-104.4780170766108 36.66698791870694, -104.4468522338495 36.79925409393386, -104.46212692626 36.9372149776075, -104.5126119783768 37.08163268820887, -104.5247764602161 37.29300499892048, -104.7084397427668 37.49150259925398, -104.8126599016282 37.69514285621863, -104.8452887035466 37.87613395659479, -104.7160169341003 38.05951763337799, -104.6165437927668 38.30432045855106, -104.6437227858174 38.53979986564737, -104.7596170387259 38.7322907594295, -104.8380078676822 38.89998460604341, -104.8501253693506 39.09980189213358, -104.8791648316464 39.24368776457503, -104.8635041274215 39.3785278162751, -104.8894471170052 39.5929228239605, -104.9721242843344 39.69528482419685, -105.0112104500356 39.7273080432394, -105.0010368577104 39.76677607811571, -104.981835619 39.81466504121967, -104.9858891550477 39.88806911250832, -104.9873548059578 39.98117234571016, -104.9766220487419 40.09796423450692, -104.9818565932953 40.36056530662884, -104.9912746373997 40.74904484447656)'),
33  
-               )
34  
-
35  
-stx_interstates = (('I-10', 'LINESTRING(924952.5 4220931.6,925065.3 4220931.6,929568.4 4221057.8)'),
36  
-                   )
BIN  django/contrib/gis/tests/distapp/fixtures/initial_data.json.gz
Binary file not shown
39  django/contrib/gis/tests/distapp/tests.py
... ...
@@ -1,18 +1,17 @@
1  
-import os, unittest
  1
+import os
2 2
 from decimal import Decimal
3 3
 
4 4
 from django.db import connection
5 5
 from django.db.models import Q
6  
-from django.contrib.gis.gdal import DataSource
7 6
 from django.contrib.gis.geos import GEOSGeometry, Point, LineString
8 7
 from django.contrib.gis.measure import D # alias for Distance
9 8
 from django.contrib.gis.tests.utils import oracle, postgis, spatialite, no_oracle, no_spatialite
  9
+from django.test import TestCase
10 10
 
11 11
 from models import AustraliaCity, Interstate, SouthTexasInterstate, \
12 12
     SouthTexasCity, SouthTexasCityFt, CensusZipcode, SouthTexasZipcode
13  
-from data import au_cities, interstates, stx_interstates, stx_cities, stx_zips
14 13
 
15  
-class DistanceTest(unittest.TestCase):
  14
+class DistanceTest(TestCase):
16 15
 
17 16
     # A point we are testing distances with -- using a WGS84
18 17
     # coordinate that'll be implicitly transormed to that to
@@ -28,37 +27,12 @@ def get_names(self, qs):
28 27
         return cities
29 28
 
30 29
     def test01_init(self):
31  
-        "Initialization of distance models."
32  
-
33  
-        # Loading up the cities.
34  
-        def load_cities(city_model, data_tup):
35  
-            for name, x, y in data_tup:
36  
-                city_model(name=name, point=Point(x, y, srid=4326)).save()
37  
-
38  
-        def load_interstates(imodel, data_tup):
39  
-            for name, wkt in data_tup:
40  
-                imodel(name=name, path=wkt).save()
41  
-
42  
-        load_cities(SouthTexasCity, stx_cities)
43  
-        load_cities(SouthTexasCityFt, stx_cities)
44  
-        load_cities(AustraliaCity, au_cities)
45  
-
  30
+        "Test initialization of distance models."
46 31
         self.assertEqual(9, SouthTexasCity.objects.count())
47 32
         self.assertEqual(9, SouthTexasCityFt.objects.count())
48 33
         self.assertEqual(11, AustraliaCity.objects.count())
49  
-
50  
-        # Loading up the South Texas Zip Codes.
51  
-        for name, wkt in stx_zips:
52  
-            poly = GEOSGeometry(wkt, srid=4269)
53  
-            SouthTexasZipcode(name=name, poly=poly).save()
54  
-            CensusZipcode(name=name, poly=poly).save()
55 34
         self.assertEqual(4, SouthTexasZipcode.objects.count())
56 35
         self.assertEqual(4, CensusZipcode.objects.count())
57  
-
58  
-        # Loading up the Interstates.
59  
-        load_interstates(Interstate, interstates)
60  
-        load_interstates(SouthTexasInterstate, stx_interstates)
61  
-
62 36
         self.assertEqual(1, Interstate.objects.count())
63 37
         self.assertEqual(1, SouthTexasInterstate.objects.count())
64 38
 
@@ -382,8 +356,3 @@ def test09_measurement_null_fields(self):
382 356
         z = SouthTexasZipcode.objects.distance(htown.point).area().get(name='78212')
383 357
         self.assertEqual(None, z.distance)
384 358
         self.assertEqual(None, z.area)
385  
-
386  
-def suite():
387  
-    s = unittest.TestSuite()
388  
-    s.addTest(unittest.makeSuite(DistanceTest))
389  
-    return s
11  django/contrib/gis/tests/geo3d/tests.py
... ...
@@ -1,4 +1,6 @@
1  
-import os, re, unittest
  1
+import os
  2
+import re
  3
+from django.utils.unittest import TestCase
2 4
 from django.contrib.gis.db.models import Union, Extent3D
3 5
 from django.contrib.gis.geos import GEOSGeometry, Point, Polygon
4 6
 from django.contrib.gis.utils import LayerMapping, LayerMapError
@@ -49,7 +51,7 @@ def gen_bbox():
49 51
     bbox_3d = Polygon(tuple((x, y, z) for (x, y), z in zip(bbox_2d[0].coords, bbox_z)), srid=32140)    
50 52
     return bbox_2d, bbox_3d
51 53
 
52  
-class Geo3DTest(unittest.TestCase):
  54
+class Geo3DTest(TestCase):
53 55
     """
54 56
     Only a subset of the PostGIS routines are 3D-enabled, and this TestCase
55 57
     tries to test the features that can handle 3D and that are also 
@@ -227,8 +229,3 @@ def test07_translate(self):
227 229
         for ztrans in ztranslations:
228 230
             for city in City3D.objects.translate(0, 0, ztrans):
229 231
                 self.assertEqual(city_dict[city.name][2] + ztrans, city.translate.z)
230  
-
231  
-def suite():
232  
-    s = unittest.TestSuite()
233  
-    s.addTest(unittest.makeSuite(Geo3DTest))
234  
-    return s
97  django/contrib/gis/tests/geoapp/fixtures/initial_data.json
0 additions, 97 deletions not shown
BIN  django/contrib/gis/tests/geoapp/fixtures/initial_data.json.gz
Binary file not shown
23  django/contrib/gis/tests/geoapp/test_feeds.py
... ...
@@ -1,13 +1,12 @@
1 1
 from xml.dom import minidom
2  
-
3  
-from django.test import Client
4  
-from django.utils import unittest
  2
+from django.test import TestCase
5 3
 
6 4
 from models import City
7 5
 
8 6
 
9  
-class GeoFeedTest(unittest.TestCase):
10  
-    client = Client()
  7
+class GeoFeedTest(TestCase):
  8
+
  9
+    urls = 'django.contrib.gis.tests.geoapp.urls'
11 10
 
12 11
     def assertChildNodes(self, elem, expected):
13 12
         "Taken from regressiontests/syndication/tests.py."
@@ -18,9 +17,9 @@ def assertChildNodes(self, elem, expected):
18 17
     def test_geofeed_rss(self):
19 18
         "Tests geographic feeds using GeoRSS over RSSv2."
20 19
         # Uses `GEOSGeometry` in `item_geometry`
21  
-        doc1 = minidom.parseString(self.client.get('/geoapp/feeds/rss1/').content)
  20
+        doc1 = minidom.parseString(self.client.get('/feeds/rss1/').content)
22 21
         # Uses a 2-tuple in `item_geometry`
23  
-        doc2 = minidom.parseString(self.client.get('/geoapp/feeds/rss2/').content)
  22
+        doc2 = minidom.parseString(self.client.get('/feeds/rss2/').content)
24 23
         feed1, feed2 = doc1.firstChild, doc2.firstChild
25 24
 
26 25
         # Making sure the box got added to the second GeoRSS feed.
@@ -43,8 +42,8 @@ def test_geofeed_rss(self):
43 42
 
44 43
     def test_geofeed_atom(self):
45 44
         "Testing geographic feeds using GeoRSS over Atom."
46  
-        doc1 = minidom.parseString(self.client.get('/geoapp/feeds/atom1/').content)
47  
-        doc2 = minidom.parseString(self.client.get('/geoapp/feeds/atom2/').content)
  45
+        doc1 = minidom.parseString(self.client.get('/feeds/atom1/').content)
  46
+        doc2 = minidom.parseString(self.client.get('/feeds/atom2/').content)
48 47
         feed1, feed2 = doc1.firstChild, doc2.firstChild
49 48
 
50 49
         # Making sure the box got added to the second GeoRSS feed.
@@ -62,7 +61,7 @@ def test_geofeed_atom(self):
62 61
 
63 62
     def test_geofeed_w3c(self):
64 63
         "Testing geographic feeds using W3C Geo."
65  
-        doc = minidom.parseString(self.client.get('/geoapp/feeds/w3cgeo1/').content)
  64
+        doc = minidom.parseString(self.client.get('/feeds/w3cgeo1/').content)
66 65
         feed = doc.firstChild
67 66
         # Ensuring the geo namespace was added to the <feed> element.
68 67
         self.assertEqual(feed.getAttribute(u'xmlns:geo'), u'http://www.w3.org/2003/01/geo/wgs84_pos#')
@@ -75,5 +74,5 @@ def test_geofeed_w3c(self):
75 74
             self.assertChildNodes(item, ['title', 'link', 'description', 'guid', 'geo:lat', 'geo:lon'])
76 75
 
77 76
         # Boxes and Polygons aren't allowed in W3C Geo feeds.
78  
-        self.assertRaises(ValueError, self.client.get, '/geoapp/feeds/w3cgeo2/') # Box in <channel>
79  
-        self.assertRaises(ValueError, self.client.get, '/geoapp/feeds/w3cgeo3/') # Polygons in <entry>
  77
+        self.assertRaises(ValueError, self.client.get, '/feeds/w3cgeo2/') # Box in <channel>
  78
+        self.assertRaises(ValueError, self.client.get, '/feeds/w3cgeo3/') # Polygons in <entry>
15  django/contrib/gis/tests/geoapp/test_sitemaps.py
... ...
@@ -1,15 +1,14 @@
1 1
 import cStringIO
2 2
 from xml.dom import minidom
3 3
 import zipfile
4  
-
5  
-from django.test import Client
6  
-from django.utils import unittest
  4
+from django.test import TestCase
7 5
 
8 6
 from models import City, Country
9 7
 
10 8
 
11  
-class GeoSitemapTest(unittest.TestCase):
12  
-    client = Client()
  9
+class GeoSitemapTest(TestCase):
  10
+
  11
+    urls = 'django.contrib.gis.tests.geoapp.urls'
13 12
 
14 13
     def assertChildNodes(self, elem, expected):
15 14
         "Taken from regressiontests/syndication/tests.py."
@@ -20,7 +19,7 @@ def assertChildNodes(self, elem, expected):
20 19
     def test_geositemap_index(self):
21 20
         "Tests geographic sitemap index."
22 21
         # Getting the geo index.
23  
-        doc = minidom.parseString(self.client.get('/geoapp/sitemap.xml').content)
  22
+        doc = minidom.parseString(self.client.get('/sitemap.xml').content)
24 23
         index = doc.firstChild
25 24
         self.assertEqual(index.getAttribute(u'xmlns'), u'http://www.sitemaps.org/schemas/sitemap/0.9')
26 25
         self.assertEqual(3, len(index.getElementsByTagName('sitemap')))
@@ -28,7 +27,7 @@ def test_geositemap_index(self):
28 27
     def test_geositemap_kml(self):
29 28
         "Tests KML/KMZ geographic sitemaps."
30 29
         for kml_type in ('kml', 'kmz'):
31  
-            doc = minidom.parseString(self.client.get('/geoapp/sitemaps/%s.xml' % kml_type).content)
  30
+            doc = minidom.parseString(self.client.get('/sitemaps/%s.xml' % kml_type).content)
32 31
 
33 32
             # Ensuring the right sitemaps namespaces are present.
34 33
             urlset = doc.firstChild
@@ -68,7 +67,7 @@ def test_geositemap_georss(self):
68 67
         "Tests GeoRSS geographic sitemaps."
69 68
         from feeds import feed_dict
70 69
 
71  
-        doc = minidom.parseString(self.client.get('/geoapp/sitemaps/georss.xml').content)
  70
+        doc = minidom.parseString(self.client.get('/sitemaps/georss.xml').content)
72 71
 
73 72
         # Ensuring the right sitemaps namespaces are present.
74 73
         urlset = doc.firstChild
15  django/contrib/gis/tests/geoapp/tests.py
... ...
@@ -1,10 +1,11 @@
1  
-import re, os, unittest
  1
+import re
2 2
 from django.db import connection
3 3
 from django.contrib.gis import gdal
4  
-from django.contrib.gis.geos import *
  4
+from django.contrib.gis.geos import fromstr, GEOSGeometry, \
  5
+    Point, LineString, LinearRing, Polygon, GeometryCollection
5 6
 from django.contrib.gis.measure import Distance
6 7
 from django.contrib.gis.tests.utils import \
7  
-    no_mysql, no_oracle, no_postgis, no_spatialite, \
  8
+    no_mysql, no_oracle, no_spatialite, \
8 9
     mysql, oracle, postgis, spatialite
9 10
 from django.test import TestCase
10 11
 
@@ -732,11 +733,3 @@ def test29_force_rhr(self):
732 733
 from test_feeds import GeoFeedTest
733 734
 from test_regress import GeoRegressionTests
734 735
 from test_sitemaps import GeoSitemapTest
735  
-
736  
-def suite():
737  
-    s = unittest.TestSuite()
738  
-    s.addTest(unittest.makeSuite(GeoModelTest))
739  
-    s.addTest(unittest.makeSuite(GeoFeedTest))
740  
-    s.addTest(unittest.makeSuite(GeoSitemapTest))
741  
-    s.addTest(unittest.makeSuite(GeoRegressionTests))
742  
-    return s
11  django/contrib/gis/tests/layermap/tests.py
... ...
@@ -1,8 +1,8 @@
1 1
 import os
2 2
 from decimal import Decimal
3 3
 
4  
-from django.utils import unittest
5 4
 from django.utils.copycompat import copy
  5
+from django.utils.unittest import TestCase
6 6
 
7 7
 from django.contrib.gis.gdal import DataSource
8 8
 from django.contrib.gis.tests.utils import mysql
@@ -10,7 +10,7 @@
10 10
 
11 11
 from models import City, County, CountyFeat, Interstate, ICity1, ICity2, State, city_mapping, co_mapping, cofeat_mapping, inter_mapping
12 12
 
13  
-shp_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'data'))
  13
+shp_path = os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir, 'data'))
14 14
 city_shp = os.path.join(shp_path, 'cities', 'cities.shp')
15 15
 co_shp = os.path.join(shp_path, 'counties', 'counties.shp')
16 16
 inter_shp = os.path.join(shp_path, 'interstates', 'interstates.shp')
@@ -20,7 +20,7 @@
20 20
 NUMS   = [1, 2, 1, 19, 1] # Number of polygons for each.
21 21
 STATES = ['Texas', 'Texas', 'Texas', 'Hawaii', 'Colorado']
22 22
 
23  
-class LayerMapTest(unittest.TestCase):
  23
+class LayerMapTest(TestCase):
24 24
 
25 25
     def test01_init(self):
26 26
         "Testing LayerMapping initialization."
@@ -265,8 +265,3 @@ def test06_model_inheritance(self):
265 265
 
266 266
         self.assertEqual(6, ICity1.objects.count())
267 267
         self.assertEqual(3, ICity2.objects.count())
268  
-
269  
-def suite():
270  
-    s = unittest.TestSuite()
271  
-    s.addTest(unittest.makeSuite(LayerMapTest))
272  
-    return s
BIN  django/contrib/gis/tests/relatedapp/fixtures/initial_data.json.gz
Binary file not shown
87  django/contrib/gis/tests/relatedapp/tests.py
... ...
@@ -1,23 +1,13 @@
1  
-import os, unittest
2  
-from django.contrib.gis.geos import *
  1
+from django.test import TestCase
  2
+
  3
+from django.contrib.gis.geos import GEOSGeometry, Point, MultiPoint
3 4
 from django.contrib.gis.db.models import Collect, Count, Extent, F, Union
4 5
 from django.contrib.gis.geometry.backend import Geometry
5  
-from django.contrib.gis.tests.utils import mysql, oracle, postgis, spatialite, no_mysql, no_oracle, no_spatialite
6  
-from django.conf import settings
7  
-from models import City, Location, DirectoryEntry, Parcel, Book, Author, Article
8  
-
9  
-cities = (('Aurora', 'TX', -97.516111, 33.058333),
10  
-          ('Roswell', 'NM', -104.528056, 33.387222),
11  
-          ('Kecksburg', 'PA',  -79.460734, 40.18476),
12  
-           )
  6
+from django.contrib.gis.tests.utils import mysql, oracle, no_mysql, no_oracle, no_spatialite
13 7
 
14  
-class RelatedGeoModelTest(unittest.TestCase):
  8
+from models import City, Location, DirectoryEntry, Parcel, Book, Author, Article
15 9
 
16  
-    def test01_setup(self):
17  
-        "Setting up for related model tests."
18  
-        for name, state, lon, lat in cities:
19  
-            loc = Location.objects.create(point=Point(lon, lat))
20  
-            c = City.objects.create(name=name, state=state, location=loc)
  10
+class RelatedGeoModelTest(TestCase):
21 11
 
22 12
     def test02_select_related(self):
23 13
         "Testing `select_related` on geographic models (see #7126)."
@@ -25,6 +15,13 @@ def test02_select_related(self):
25 15
         qs2 = City.objects.select_related()
26 16
         qs3 = City.objects.select_related('location')
27 17
 
  18
+        # Reference data for what's in the fixtures.
  19
+        cities = (
  20
+            ('Aurora', 'TX', -97.516111, 33.058333),
  21
+            ('Roswell', 'NM', -104.528056, 33.387222),
  22
+            ('Kecksburg', 'PA',  -79.460734, 40.18476),
  23
+        )
  24
+
28 25
         for qs in (qs1, qs2, qs3):
29 26
             for ref, c in zip(cities, qs):
30 27
                 nm, st, lon, lat = ref
@@ -63,11 +60,11 @@ def test04a_related_extent_aggregate(self):
63 60
         # This combines the Extent and Union aggregates into one query
64 61
         aggs = City.objects.aggregate(Extent('location__point'))
65 62
 
66  
-        # One for all locations, one that excludes Roswell.
67  
-        all_extent = (-104.528060913086, 33.0583305358887,-79.4607315063477, 40.1847610473633)
68  
-        txpa_extent = (-97.51611328125, 33.0583305358887,-79.4607315063477, 40.1847610473633)
  63
+        # One for all locations, one that excludes New Mexico (Roswell).
  64
+        all_extent = (-104.528056, 29.763374, -79.460734, 40.18476)
  65
+        txpa_extent = (-97.516111, 29.763374, -79.460734, 40.18476)
69 66
         e1 = City.objects.extent(field_name='location__point')
70  
-        e2 = City.objects.exclude(name='Roswell').extent(field_name='location__point')
  67
+        e2 = City.objects.exclude(state='NM').extent(field_name='location__point')
71 68
         e3 = aggs['location__point__extent']
72 69
 
73 70
         # The tolerance value is to four decimal places because of differences
@@ -83,10 +80,12 @@ def test04b_related_union_aggregate(self):
83 80
         aggs = City.objects.aggregate(Union('location__point'))
84 81
 
85 82
         # These are the points that are components of the aggregate geographic
86  
-        # union that is returned.
  83
+        # union that is returned.  Each point # corresponds to City PK.
87 84
         p1 = Point(-104.528056, 33.387222)
88 85
         p2 = Point(-97.516111, 33.058333)
89 86
         p3 = Point(-79.460734, 40.18476)
  87
+        p4 = Point(-96.801611, 32.782057)
  88
+        p5 = Point(-95.363151, 29.763374)
90 89
 
91 90
         # Creating the reference union geometry depending on the spatial backend,
92 91
         # as Oracle will have a different internal ordering of the component
@@ -94,14 +93,15 @@ def test04b_related_union_aggregate(self):
94 93
         # query that includes limiting information in the WHERE clause (in other
95 94
         # words a `.filter()` precedes the call to `.unionagg()`).
96 95
         if oracle:
97  
-            ref_u1 = MultiPoint(p3, p1, p2, srid=4326)
  96
+            ref_u1 = MultiPoint(p4, p5, p3, p1, p2, srid=4326)
98 97
             ref_u2 = MultiPoint(p3, p2, srid=4326)
99 98
         else:
100  
-            ref_u1 = MultiPoint(p1, p2, p3, srid=4326)
  99
+            # Looks like PostGIS points by longitude value.
  100
+            ref_u1 = MultiPoint(p1, p2, p4, p5, p3, srid=4326)
101 101
             ref_u2 = MultiPoint(p2, p3, srid=4326)
102 102
 
103 103
         u1 = City.objects.unionagg(field_name='location__point')
104  
-        u2 = City.objects.exclude(name='Roswell').unionagg(field_name='location__point')
  104
+        u2 = City.objects.exclude(name__in=('Roswell', 'Houston', 'Dallas', 'Fort Worth')).unionagg(field_name='location__point')
105 105
         u3 = aggs['location__point__union']
106 106
 
107 107
         self.assertEqual(ref_u1, u1)
@@ -187,17 +187,10 @@ def test08_defer_only(self):
187 187
 
188 188
     def test09_pk_relations(self):
189 189
         "Ensuring correct primary key column is selected across relations. See #10757."
190  
-        # Adding two more cities, but this time making sure that their location
191  
-        # ID values do not match their City ID values.
192  
-        loc1 = Location.objects.create(point='POINT (-95.363151 29.763374)')
193  
-        loc2 = Location.objects.create(point='POINT (-96.801611 32.782057)')
194  
-        dallas = City.objects.create(name='Dallas', state='TX', location=loc2)
195  
-        houston = City.objects.create(name='Houston', state='TX', location=loc1)
196  
-
197 190
         # The expected ID values -- notice the last two location IDs
198  
-        # are out of order.  We want to make sure that the related
199  
-        # location ID column is selected instead of ID column for
200  
-        # the city.
  191
+        # are out of order.  Dallas and Houston have location IDs that differ
  192
+        # from their PKs -- this is done to ensure that the related location
  193
+        # ID column is selected instead of ID column for the city.
201 194
         city_ids = (1, 2, 3, 4, 5)
202 195
         loc_ids = (1, 2, 3, 5, 4)
203 196
         ids_qs = City.objects.order_by('id').values('id', 'location__id')
@@ -232,10 +225,8 @@ def test11_geoquery_pickle(self):
232 225
     @no_oracle
233 226
     def test12a_count(self):
234 227
         "Testing `Count` aggregate use with the `GeoManager` on geo-fields."
235  
-        # Creating a new City, 'Fort Worth', that uses the same location
236  
-        # as Dallas.
  228
+        # The City, 'Fort Worth' uses the same location as Dallas.
237 229
         dallas = City.objects.get(name='Dallas')
238  
-        ftworth = City.objects.create(name='Fort Worth', state='TX', location=dallas.location)
239 230
 
240 231
         # Count annotation should be 2 for the Dallas location now.
241 232
         loc = Location.objects.annotate(num_cities=Count('city')).get(id=dallas.location.id)
@@ -243,18 +234,9 @@ def test12a_count(self):
243 234
 
244 235
     def test12b_count(self):
245 236
         "Testing `Count` aggregate use with the `GeoManager` on non geo-fields. See #11087."
246  
-        # Creating some data for the Book/Author non-geo models that
247  
-        # use GeoManager.  See #11087.
248  
-        tp = Author.objects.create(name='Trevor Paglen')
249  
-        Book.objects.create(title='Torture Taxi', author=tp)
250  
-        Book.objects.create(title='I Could Tell You But Then You Would Have to be Destroyed by Me', author=tp)
251  
-        Book.objects.create(title='Blank Spots on the Map', author=tp)
252  
-        wp = Author.objects.create(name='William Patry')
253  
-        Book.objects.create(title='Patry on Copyright', author=wp)
254  
-
255 237
         # Should only be one author (Trevor Paglen) returned by this query, and
256  
-        # the annotation should have 3 for the number of books.  Also testing
257  
-        # with a `GeoValuesQuerySet` (see #11489).
  238
+        # the annotation should have 3 for the number of books, see #11087.
  239
+        # Also testing with a `GeoValuesQuerySet`, see #11489.
258 240
         qs = Author.objects.annotate(num_books=Count('books')).filter(num_books__gt=1)
259 241
         vqs = Author.objects.values('name').annotate(num_books=Count('books')).filter(num_books__gt=1)
260 242
         self.assertEqual(1, len(qs))
@@ -280,7 +262,7 @@ def test14_collect(self):
280 262
         # SELECT AsText(ST_Collect("relatedapp_location"."point")) FROM "relatedapp_city" LEFT OUTER JOIN
281 263
         #    "relatedapp_location" ON ("relatedapp_city"."location_id" = "relatedapp_location"."id")
282 264
         #    WHERE "relatedapp_city"."state" = 'TX';
283  
-        ref_geom = fromstr('MULTIPOINT(-97.516111 33.058333,-96.801611 32.782057,-95.363151 29.763374,-96.801611 32.782057)')
  265
+        ref_geom = GEOSGeometry('MULTIPOINT(-97.516111 33.058333,-96.801611 32.782057,-95.363151 29.763374,-96.801611 32.782057)')
284 266
 
285 267
         c1 = City.objects.filter(state='TX').collect(field_name='location__point')
286 268
         c2 = City.objects.filter(state='TX').aggregate(Collect('location__point'))['location__point__collect']
@@ -298,10 +280,5 @@ def test15_invalid_select_related(self):
298 280
         # keyword.  The TypeError is swallowed if QuerySet is actually
299 281
         # evaluated as list generation swallows TypeError in CPython.
300 282
         sql = str(qs.query)
301  
-        
302  
-    # TODO: Related tests for KML, GML, and distance lookups.
303 283
 
304  
-def suite():
305  
-    s = unittest.TestSuite()
306  
-    s.addTest(unittest.makeSuite(RelatedGeoModelTest))
307  
-    return s
  284
+    # TODO: Related tests for KML, GML, and distance lookups.
6  django/contrib/gis/tests/urls.py
... ...
@@ -1,6 +0,0 @@
1  
-from django.conf.urls.defaults import *
2  
-
3  
-urlpatterns = patterns('',
4  
-                       (r'^geoapp/', include('django.contrib.gis.tests.geoapp.urls')),
5  
-                       )
6  
-                        

0 notes on commit 0f87919

Please sign in to comment.
Something went wrong with that request. Please try again.