From 4eb97a90f0b4484fb13dd2166a61f9fe7256e9d0 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Fri, 6 Jan 2023 12:55:14 +0100 Subject: [PATCH] Refs #32375 -- Changed default sitemap protocol to https. Per deprecation timeline. --- django/contrib/sitemaps/__init__.py | 14 +------------- docs/ref/contrib/sitemaps.txt | 8 ++++---- docs/releases/5.0.txt | 3 +++ tests/sitemaps_tests/test_generic.py | 16 ++-------------- tests/sitemaps_tests/test_http.py | 3 --- 5 files changed, 10 insertions(+), 34 deletions(-) diff --git a/django/contrib/sitemaps/__init__.py b/django/contrib/sitemaps/__init__.py index df57f1cd5c..5938e34014 100644 --- a/django/contrib/sitemaps/__init__.py +++ b/django/contrib/sitemaps/__init__.py @@ -1,4 +1,3 @@ -import warnings from urllib.parse import urlencode from urllib.request import urlopen @@ -8,7 +7,6 @@ from django.core import paginator from django.core.exceptions import ImproperlyConfigured from django.urls import NoReverseMatch, reverse from django.utils import translation -from django.utils.deprecation import RemovedInDjango50Warning PING_URL = "https://www.google.com/webmasters/tools/ping" @@ -133,17 +131,7 @@ class Sitemap: def get_protocol(self, protocol=None): # Determine protocol - if self.protocol is None and protocol is None: - warnings.warn( - "The default sitemap protocol will be changed from 'http' to " - "'https' in Django 5.0. Set Sitemap.protocol to silence this " - "warning.", - category=RemovedInDjango50Warning, - stacklevel=2, - ) - # RemovedInDjango50Warning: when the deprecation ends, replace 'http' - # with 'https'. - return self.protocol or protocol or "http" + return self.protocol or protocol or "https" def get_domain(self, site=None): # Determine domain diff --git a/docs/ref/contrib/sitemaps.txt b/docs/ref/contrib/sitemaps.txt index 8cd9a22304..5c91529537 100644 --- a/docs/ref/contrib/sitemaps.txt +++ b/docs/ref/contrib/sitemaps.txt @@ -242,12 +242,12 @@ Note: This attribute defines the protocol (``'http'`` or ``'https'``) of the URLs in the sitemap. If it isn't set, the protocol with which the sitemap was requested is used. If the sitemap is built outside the - context of a request, the default is ``'http'``. + context of a request, the default is ``'https'``. - .. deprecated:: 4.0 + .. versionchanged:: 5.0 - The default protocol for sitemaps built outside the context of a - request will change from ``'http'`` to ``'https'`` in Django 5.0. + In older versions, the default protocol for sitemaps built outside + the context of a request was ``'http'``. .. attribute:: Sitemap.limit diff --git a/docs/releases/5.0.txt b/docs/releases/5.0.txt index f90e2f763e..f2904d3359 100644 --- a/docs/releases/5.0.txt +++ b/docs/releases/5.0.txt @@ -264,6 +264,9 @@ to remove usage of these features. * The default value of the ``USE_TZ`` setting is changed from ``False`` to ``True``. +* The default sitemap protocol for sitemaps built outside the context of a + request is changed from ``'http'`` to ``'https'``. + See :ref:`deprecated-features-4.1` for details on these changes, including how to remove usage of these features. diff --git a/tests/sitemaps_tests/test_generic.py b/tests/sitemaps_tests/test_generic.py index 2865c77902..dc998eec93 100644 --- a/tests/sitemaps_tests/test_generic.py +++ b/tests/sitemaps_tests/test_generic.py @@ -1,8 +1,7 @@ from datetime import datetime from django.contrib.sitemaps import GenericSitemap -from django.test import ignore_warnings, override_settings -from django.utils.deprecation import RemovedInDjango50Warning +from django.test import override_settings from .base import SitemapTestsBase from .models import TestModel @@ -79,20 +78,9 @@ class GenericViewsSitemapTests(SitemapTestsBase): with self.subTest(protocol=protocol): self.assertEqual(sitemap.get_protocol(protocol), protocol) - @ignore_warnings(category=RemovedInDjango50Warning) def test_get_protocol_default(self): sitemap = GenericSitemap({"queryset": None}) - self.assertEqual(sitemap.get_protocol(), "http") - - def test_get_protocol_default_warning(self): - sitemap = GenericSitemap({"queryset": None}) - msg = ( - "The default sitemap protocol will be changed from 'http' to " - "'https' in Django 5.0. Set Sitemap.protocol to silence this " - "warning." - ) - with self.assertWarnsMessage(RemovedInDjango50Warning, msg): - sitemap.get_protocol() + self.assertEqual(sitemap.get_protocol(), "https") def test_generic_sitemap_index(self): TestModel.objects.update(lastmod=datetime(2013, 3, 13, 10, 0, 0)) diff --git a/tests/sitemaps_tests/test_http.py b/tests/sitemaps_tests/test_http.py index 12e387757b..1a0c1c3d50 100644 --- a/tests/sitemaps_tests/test_http.py +++ b/tests/sitemaps_tests/test_http.py @@ -271,7 +271,6 @@ class HTTPSitemapTests(SitemapTestsBase): ) % date.today() self.assertXMLEqual(response.content.decode(), expected_content) - @ignore_warnings(category=RemovedInDjango50Warning) def test_sitemap_get_urls_no_site_1(self): """ Check we get ImproperlyConfigured if we don't pass a site object to @@ -282,7 +281,6 @@ class HTTPSitemapTests(SitemapTestsBase): Sitemap().get_urls() @modify_settings(INSTALLED_APPS={"remove": "django.contrib.sites"}) - @ignore_warnings(category=RemovedInDjango50Warning) def test_sitemap_get_urls_no_site_2(self): """ Check we get ImproperlyConfigured when we don't pass a site object to @@ -292,7 +290,6 @@ class HTTPSitemapTests(SitemapTestsBase): with self.assertRaisesMessage(ImproperlyConfigured, self.use_sitemap_err_msg): Sitemap().get_urls() - @ignore_warnings(category=RemovedInDjango50Warning) def test_sitemap_item(self): """ Check to make sure that the raw item is included with each