def setup_test_environment(self): super(CreateModelsTestRunner, self).setup_test_environment() mgr = TestSettingsManager() INSTALLED_APPS = list(settings.INSTALLED_APPS) INSTALLED_APPS.append(OUR_TESTS) mgr.set(INSTALLED_APPS=INSTALLED_APPS)
from django.test import TestCase from django.conf import settings from django.contrib.gis.geos import GEOSGeometry from utils import TestSettingsManager from models import * from maps.fields import * mgr = TestSettingsManager() INSTALLED_APPS = list(settings.INSTALLED_APPS) INSTALLED_APPS.append('maps.tests') mgr.set(INSTALLED_APPS=INSTALLED_APPS) class FlatCollectionTest(TestCase): def test_flatten(self): # A geometry collection with a bunch of stuff inside of a # rectangle. And a few items outside of it. geom = GEOSGeometry( """{ "type": "GeometryCollection", "geometries": [ { "type": "Polygon", "coordinates": [ [ [ -122.443056, 37.787064 ], [ -122.443056, 37.758434 ], [ -122.400999, 37.757891 ], [ -122.403402, 37.787742 ], [ -122.443056, 37.787064 ] ] ] }, { "type": "Point", "coordinates": [ -122.434816, 37.784758 ] }, { "type": "Point", "coordinates": [ -122.410612, 37.781909 ] }, { "type": "Point", "coordinates": [ -122.432241, 37.766983 ] }, { "type": "Point", "coordinates": [ -122.409754, 37.768747 ] }, { "type": "LineString", "coordinates": [ [ -122.415075, 37.784351 ], [ -122.425890, 37.765083 ], [ -122.427435, 37.779466 ] ] }, { "type": "Polygon", "coordinates": [ [ [ -122.438765, 37.778788 ], [ -122.439966, 37.763726 ], [ -122.457132, 37.772139 ], [ -122.438765, 37.778788 ] ] ] }, { "type": "Point", "coordinates": [ -122.415762, 37.792762 ] }, { "type": "Point", "coordinates": [ -122.430696, 37.791541 ] }, { "type": "LineString", "coordinates": [ [ -122.397394, 37.790727 ], [ -122.395849, 37.754498 ], [ -122.448549, 37.761962 ] ] } ] }""", srid=4326) # A geometry collection with nothing inside the rectangle and a # few items outside of it. expected_geom = GEOSGeometry( """{ "type": "GeometryCollection", "geometries": [ { "type": "Polygon", "coordinates": [ [ [ -122.443056, 37.765240 ], [ -122.457132, 37.772139 ], [ -122.443056, 37.777235 ], [ -122.443056, 37.787064 ], [ -122.403402, 37.787742 ], [ -122.400999, 37.757891 ], [ -122.443056, 37.758434 ], [ -122.443056, 37.765240 ] ] ] }, { "type": "Point", "coordinates": [ -122.415762, 37.792762 ] }, { "type": "Point", "coordinates": [ -122.430696, 37.791541 ] }, { "type": "LineString", "coordinates": [ [ -122.397394, 37.790727 ], [ -122.395849, 37.754498 ], [ -122.448549, 37.761962 ] ] } ] }""", srid=4326) self.assertTrue( flatten_collection(geom).equals(expected_geom) or flatten_collection(geom).equals_exact(expected_geom, 0.001))