Silenced some GIS deprecation warnings; refs #22384.

This commit is contained in:
Tim Graham 2014-06-07 19:35:57 -04:00
parent 1a01e24331
commit 250e2b422b
3 changed files with 21 additions and 3 deletions

View File

@ -3,6 +3,7 @@ from __future__ import unicode_literals
from io import BytesIO from io import BytesIO
from unittest import skipUnless from unittest import skipUnless
from xml.dom import minidom from xml.dom import minidom
import warnings
import zipfile import zipfile
from django.conf import settings from django.conf import settings
@ -10,6 +11,7 @@ from django.contrib.gis.geos import HAS_GEOS
from django.contrib.gis.tests.utils import HAS_SPATIAL_DB from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.test import TestCase, modify_settings, override_settings from django.test import TestCase, modify_settings, override_settings
from django.utils.deprecation import RemovedInDjango20Warning
if HAS_GEOS: if HAS_GEOS:
from .models import City, Country from .models import City, Country
@ -33,7 +35,16 @@ class GeoSitemapTest(TestCase):
def test_geositemap_kml(self): def test_geositemap_kml(self):
"Tests KML/KMZ geographic sitemaps." "Tests KML/KMZ geographic sitemaps."
for kml_type in ('kml', 'kmz'): for kml_type in ('kml', 'kmz'):
doc = minidom.parseString(self.client.get('/sitemaps/%s.xml' % kml_type).content) with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=RemovedInDjango20Warning)
# The URL for the sitemaps in urls.py have been updated
# with a name but since reversing by Python path is tried first
# before reversing by name and works since we're giving
# name='django.contrib.gis.sitemaps.views.(kml|kmz)', we need
# to silence the erroneous warning until reversing by dotted
# path is removed. The test will work without modification when
# it's removed.
doc = minidom.parseString(self.client.get('/sitemaps/%s.xml' % kml_type).content)
# Ensuring the right sitemaps namespace is present. # Ensuring the right sitemaps namespace is present.
urlset = doc.firstChild urlset = doc.firstChild

View File

@ -18,6 +18,10 @@ urlpatterns += [
] ]
urlpatterns += [ urlpatterns += [
url(r'^sitemaps/kml/(?P<label>\w+)/(?P<model>\w+)/(?P<field_name>\w+)\.kml$', gis_sitemap_views.kml), url(r'^sitemaps/kml/(?P<label>\w+)/(?P<model>\w+)/(?P<field_name>\w+)\.kml$',
url(r'^sitemaps/kml/(?P<label>\w+)/(?P<model>\w+)/(?P<field_name>\w+)\.kmz$', gis_sitemap_views.kmz), gis_sitemap_views.kml,
name='django.contrib.gis.sitemaps.views.kml'),
url(r'^sitemaps/kml/(?P<label>\w+)/(?P<model>\w+)/(?P<field_name>\w+)\.kmz$',
gis_sitemap_views.kmz,
name='django.contrib.gis.sitemaps.views.kmz'),
] ]

View File

@ -383,4 +383,7 @@ the ``url`` that references :func:`django.contrib.sitemaps.views.sitemap`::
to ensure compatibility when reversing by Python path is removed in Django 2.0. to ensure compatibility when reversing by Python path is removed in Django 2.0.
Similarly for GIS sitemaps, add ``name='django.contrib.gis.sitemaps.views.kml'``
or ``name='django.contrib.gis.sitemaps.views.kmz'``.
.. _security issue: https://www.djangoproject.com/weblog/2014/apr/21/security/#s-issue-unexpected-code-execution-using-reverse .. _security issue: https://www.djangoproject.com/weblog/2014/apr/21/security/#s-issue-unexpected-code-execution-using-reverse