2011-10-18 02:45:22 +08:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2011-09-10 11:04:30 +08:00
|
|
|
from django.test import TestCase
|
2013-05-11 11:08:45 +08:00
|
|
|
from django.contrib.gis.geos import HAS_GEOS
|
|
|
|
from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
|
|
|
|
from django.utils.unittest import skipUnless
|
2011-10-18 02:45:22 +08:00
|
|
|
|
2013-05-11 11:08:45 +08:00
|
|
|
if HAS_GEOS and HAS_SPATIAL_DB:
|
|
|
|
from django.contrib.gis import admin
|
|
|
|
from django.contrib.gis.geos import Point
|
2011-10-18 02:45:22 +08:00
|
|
|
|
2013-05-11 11:08:45 +08:00
|
|
|
from .models import City
|
2011-09-10 11:04:30 +08:00
|
|
|
|
2013-05-11 11:08:45 +08:00
|
|
|
|
|
|
|
@skipUnless(HAS_GEOS and HAS_SPATIAL_DB, "Geos and spatial db are required.")
|
2011-09-10 11:04:30 +08:00
|
|
|
class GeoAdminTest(TestCase):
|
|
|
|
urls = 'django.contrib.gis.tests.geoadmin.urls'
|
|
|
|
|
2012-06-06 16:40:11 +08:00
|
|
|
def test_ensure_geographic_media(self):
|
2011-09-10 11:04:30 +08:00
|
|
|
geoadmin = admin.site._registry[City]
|
|
|
|
admin_js = geoadmin.media.render_js()
|
|
|
|
self.assertTrue(any([geoadmin.openlayers_url in js for js in admin_js]))
|
2011-10-18 02:45:22 +08:00
|
|
|
|
2012-05-26 03:00:44 +08:00
|
|
|
def test_olmap_OSM_rendering(self):
|
|
|
|
geoadmin = admin.site._registry[City]
|
|
|
|
result = geoadmin.get_map_widget(City._meta.get_field('point'))(
|
|
|
|
).render('point', Point(-79.460734, 40.18476))
|
|
|
|
self.assertIn(
|
|
|
|
"""geodjango_point.layers.base = new OpenLayers.Layer.OSM("OpenStreetMap (Mapnik)");""",
|
|
|
|
result)
|
|
|
|
|
|
|
|
def test_olmap_WMS_rendering(self):
|
2013-05-15 22:45:07 +08:00
|
|
|
geoadmin = admin.GeoModelAdmin(City, admin.site)
|
2012-05-26 03:00:44 +08:00
|
|
|
result = geoadmin.get_map_widget(City._meta.get_field('point'))(
|
|
|
|
).render('point', Point(-79.460734, 40.18476))
|
|
|
|
self.assertIn(
|
2012-05-26 06:02:15 +08:00
|
|
|
"""geodjango_point.layers.base = new OpenLayers.Layer.WMS("OpenLayers WMS", "http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: \'basic\', format: 'image/jpeg'});""",
|
2012-05-26 03:00:44 +08:00
|
|
|
result)
|
2012-06-06 16:40:11 +08:00
|
|
|
|
|
|
|
def test_olwidget_has_changed(self):
|
|
|
|
""" Check that changes are accurately noticed by OpenLayersWidget. """
|
|
|
|
geoadmin = admin.site._registry[City]
|
|
|
|
form = geoadmin.get_changelist_form(None)()
|
2013-01-26 03:50:46 +08:00
|
|
|
has_changed = form.fields['point']._has_changed
|
2012-06-06 16:40:11 +08:00
|
|
|
|
|
|
|
initial = Point(13.4197458572965953, 52.5194108501149799, srid=4326)
|
|
|
|
data_same = "SRID=3857;POINT(1493879.2754093995 6894592.019687599)"
|
|
|
|
data_almost_same = "SRID=3857;POINT(1493879.2754093990 6894592.019687590)"
|
|
|
|
data_changed = "SRID=3857;POINT(1493884.0527237 6894593.8111804)"
|
|
|
|
|
|
|
|
self.assertTrue(has_changed(None, data_changed))
|
|
|
|
self.assertTrue(has_changed(initial, ""))
|
|
|
|
self.assertFalse(has_changed(None, ""))
|
|
|
|
self.assertFalse(has_changed(initial, data_same))
|
|
|
|
self.assertFalse(has_changed(initial, data_almost_same))
|
|
|
|
self.assertTrue(has_changed(initial, data_changed))
|