mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #34688 -- Removed contrib.sitemaps.ping_google() and ping_google management command.
Thanks Joachim Jablon for the report. Google has deprecated the sitemap ping endpoint, and will be removing it in 6 months ~January 2024.
This commit is contained in:
committed by
Mariusz Felisiak
parent
2584783f46
commit
6d427288e4
@@ -1,18 +0,0 @@
|
||||
from unittest import mock
|
||||
|
||||
from django.core.management import call_command
|
||||
|
||||
from .base import SitemapTestsBase
|
||||
|
||||
|
||||
@mock.patch("django.contrib.sitemaps.management.commands.ping_google.ping_google")
|
||||
class PingGoogleTests(SitemapTestsBase):
|
||||
def test_default(self, ping_google_func):
|
||||
call_command("ping_google")
|
||||
ping_google_func.assert_called_with(sitemap_url=None, sitemap_uses_https=True)
|
||||
|
||||
def test_args(self, ping_google_func):
|
||||
call_command("ping_google", "foo.xml", "--sitemap-uses-http")
|
||||
ping_google_func.assert_called_with(
|
||||
sitemap_url="foo.xml", sitemap_uses_https=False
|
||||
)
|
||||
@@ -1,59 +0,0 @@
|
||||
from unittest import mock
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from django.contrib.sitemaps import SitemapNotFound, _get_sitemap_full_url, ping_google
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.test import modify_settings, override_settings
|
||||
|
||||
from .base import SitemapTestsBase
|
||||
|
||||
|
||||
class PingGoogleTests(SitemapTestsBase):
|
||||
@override_settings(ROOT_URLCONF="sitemaps_tests.urls.sitemap_only")
|
||||
@mock.patch("django.contrib.sitemaps.urlopen")
|
||||
def test_something(self, urlopen):
|
||||
ping_google()
|
||||
params = urlencode(
|
||||
{"sitemap": "https://example.com/sitemap-without-entries/sitemap.xml"}
|
||||
)
|
||||
full_url = "https://www.google.com/webmasters/tools/ping?%s" % params
|
||||
urlopen.assert_called_with(full_url)
|
||||
|
||||
@override_settings(ROOT_URLCONF="sitemaps_tests.urls.sitemap_only")
|
||||
def test_get_sitemap_full_url_global(self):
|
||||
self.assertEqual(
|
||||
_get_sitemap_full_url(None),
|
||||
"https://example.com/sitemap-without-entries/sitemap.xml",
|
||||
)
|
||||
|
||||
@override_settings(ROOT_URLCONF="sitemaps_tests.urls.index_only")
|
||||
def test_get_sitemap_full_url_index(self):
|
||||
self.assertEqual(
|
||||
_get_sitemap_full_url(None), "https://example.com/simple/index.xml"
|
||||
)
|
||||
|
||||
@override_settings(ROOT_URLCONF="sitemaps_tests.urls.empty")
|
||||
def test_get_sitemap_full_url_not_detected(self):
|
||||
msg = (
|
||||
"You didn't provide a sitemap_url, and the sitemap URL couldn't be "
|
||||
"auto-detected."
|
||||
)
|
||||
with self.assertRaisesMessage(SitemapNotFound, msg):
|
||||
_get_sitemap_full_url(None)
|
||||
|
||||
def test_get_sitemap_full_url_exact_url(self):
|
||||
self.assertEqual(
|
||||
_get_sitemap_full_url("/foo.xml"), "https://example.com/foo.xml"
|
||||
)
|
||||
|
||||
def test_get_sitemap_full_url_insecure(self):
|
||||
self.assertEqual(
|
||||
_get_sitemap_full_url("/foo.xml", sitemap_uses_https=False),
|
||||
"http://example.com/foo.xml",
|
||||
)
|
||||
|
||||
@modify_settings(INSTALLED_APPS={"remove": "django.contrib.sites"})
|
||||
def test_get_sitemap_full_url_no_sites(self):
|
||||
msg = "ping_google requires django.contrib.sites, which isn't installed."
|
||||
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
||||
_get_sitemap_full_url(None)
|
||||
@@ -1 +0,0 @@
|
||||
urlpatterns = []
|
||||
@@ -1,13 +0,0 @@
|
||||
from django.contrib.sitemaps import views
|
||||
from django.urls import path
|
||||
|
||||
from .http import simple_sitemaps
|
||||
|
||||
urlpatterns = [
|
||||
path(
|
||||
"simple/index.xml",
|
||||
views.index,
|
||||
{"sitemaps": simple_sitemaps},
|
||||
name="django.contrib.sitemaps.views.index",
|
||||
),
|
||||
]
|
||||
@@ -1,11 +0,0 @@
|
||||
from django.contrib.sitemaps import views
|
||||
from django.urls import path
|
||||
|
||||
urlpatterns = [
|
||||
path(
|
||||
"sitemap-without-entries/sitemap.xml",
|
||||
views.sitemap,
|
||||
{"sitemaps": {}},
|
||||
name="django.contrib.sitemaps.views.sitemap",
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user