1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Refs #33476 -- Reformatted code with Black.

This commit is contained in:
django-bot
2022-02-03 20:24:19 +01:00
committed by Mariusz Felisiak
parent f68fa8b45d
commit 9c19aff7c7
1992 changed files with 139577 additions and 96284 deletions

View File

@@ -6,21 +6,21 @@ from django.test import TestCase, modify_settings, override_settings
from .models import I18nTestModel, TestModel
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.sitemaps'})
@override_settings(ROOT_URLCONF='sitemaps_tests.urls.http')
@modify_settings(INSTALLED_APPS={"append": "django.contrib.sitemaps"})
@override_settings(ROOT_URLCONF="sitemaps_tests.urls.http")
class SitemapTestsBase(TestCase):
protocol = 'http'
sites_installed = apps.is_installed('django.contrib.sites')
domain = 'example.com' if sites_installed else 'testserver'
protocol = "http"
sites_installed = apps.is_installed("django.contrib.sites")
domain = "example.com" if sites_installed else "testserver"
@classmethod
def setUpTestData(cls):
# Create an object for sitemap content.
TestModel.objects.create(name='Test Object')
cls.i18n_model = I18nTestModel.objects.create(name='Test Object')
TestModel.objects.create(name="Test Object")
cls.i18n_model = I18nTestModel.objects.create(name="Test Object")
def setUp(self):
self.base_url = '%s://%s' % (self.protocol, self.domain)
self.base_url = "%s://%s" % (self.protocol, self.domain)
cache.clear()
@classmethod

View File

@@ -7,11 +7,11 @@ class TestModel(models.Model):
lastmod = models.DateTimeField(null=True)
def get_absolute_url(self):
return '/testmodel/%s/' % self.id
return "/testmodel/%s/" % self.id
class I18nTestModel(models.Model):
name = models.CharField(max_length=100)
def get_absolute_url(self):
return reverse('i18n_testmodel', args=[self.id])
return reverse("i18n_testmodel", args=[self.id])

View File

@@ -10,24 +10,23 @@ from .models import TestModel
@override_settings(ABSOLUTE_URL_OVERRIDES={})
class GenericViewsSitemapTests(SitemapTestsBase):
def test_generic_sitemap_attributes(self):
datetime_value = datetime.now()
queryset = TestModel.objects.all()
generic_sitemap = GenericSitemap(
info_dict={
'queryset': queryset,
'date_field': datetime_value,
"queryset": queryset,
"date_field": datetime_value,
},
priority=0.6,
changefreq='monthly',
protocol='https',
changefreq="monthly",
protocol="https",
)
attr_values = (
('date_field', datetime_value),
('priority', 0.6),
('changefreq', 'monthly'),
('protocol', 'https'),
("date_field", datetime_value),
("priority", 0.6),
("changefreq", "monthly"),
("protocol", "https"),
)
for attr_name, expected_value in attr_values:
with self.subTest(attr_name=attr_name):
@@ -36,48 +35,56 @@ class GenericViewsSitemapTests(SitemapTestsBase):
def test_generic_sitemap(self):
"A minimal generic sitemap can be rendered"
response = self.client.get('/generic/sitemap.xml')
expected = ''
response = self.client.get("/generic/sitemap.xml")
expected = ""
for pk in TestModel.objects.values_list("id", flat=True):
expected += "<url><loc>%s/testmodel/%s/</loc></url>" % (self.base_url, pk)
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
expected_content = (
"""<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
%s
</urlset>
""" % expected
"""
% expected
)
self.assertXMLEqual(response.content.decode(), expected_content)
def test_generic_sitemap_lastmod(self):
test_model = TestModel.objects.first()
TestModel.objects.update(lastmod=datetime(2013, 3, 13, 10, 0, 0))
response = self.client.get('/generic-lastmod/sitemap.xml')
response = self.client.get("/generic-lastmod/sitemap.xml")
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url><loc>%s/testmodel/%s/</loc><lastmod>2013-03-13</lastmod></url>
</urlset>
""" % (self.base_url, test_model.pk)
""" % (
self.base_url,
test_model.pk,
)
self.assertXMLEqual(response.content.decode(), expected_content)
self.assertEqual(response.headers['Last-Modified'], 'Wed, 13 Mar 2013 10:00:00 GMT')
self.assertEqual(
response.headers["Last-Modified"], "Wed, 13 Mar 2013 10:00:00 GMT"
)
def test_get_protocol_defined_in_constructor(self):
for protocol in ['http', 'https']:
for protocol in ["http", "https"]:
with self.subTest(protocol=protocol):
sitemap = GenericSitemap({'queryset': None}, protocol=protocol)
sitemap = GenericSitemap({"queryset": None}, protocol=protocol)
self.assertEqual(sitemap.get_protocol(), protocol)
def test_get_protocol_passed_as_argument(self):
sitemap = GenericSitemap({'queryset': None})
for protocol in ['http', 'https']:
sitemap = GenericSitemap({"queryset": None})
for protocol in ["http", "https"]:
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')
sitemap = GenericSitemap({"queryset": None})
self.assertEqual(sitemap.get_protocol(), "http")
def test_get_protocol_default_warning(self):
sitemap = GenericSitemap({'queryset': None})
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 "
@@ -88,9 +95,9 @@ class GenericViewsSitemapTests(SitemapTestsBase):
def test_generic_sitemap_index(self):
TestModel.objects.update(lastmod=datetime(2013, 3, 13, 10, 0, 0))
response = self.client.get('/generic-lastmod/index.xml')
response = self.client.get("/generic-lastmod/index.xml")
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>http://example.com/simple/sitemap-generic.xml</loc><lastmod>2013-03-13T10:00:00</lastmod></sitemap>
</sitemapindex>"""
self.assertXMLEqual(response.content.decode('utf-8'), expected_content)
self.assertXMLEqual(response.content.decode("utf-8"), expected_content)

View File

@@ -15,210 +15,254 @@ from .models import TestModel
class HTTPSitemapTests(SitemapTestsBase):
use_sitemap_err_msg = (
'To use sitemaps, either enable the sites framework or pass a '
'Site/RequestSite object in your view.'
"To use sitemaps, either enable the sites framework or pass a "
"Site/RequestSite object in your view."
)
def test_simple_sitemap_index(self):
"A simple sitemap index can be rendered"
response = self.client.get('/simple/index.xml')
response = self.client.get("/simple/index.xml")
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>%s/simple/sitemap-simple.xml</loc><lastmod>%s</lastmod></sitemap>
</sitemapindex>
""" % (self.base_url, date.today())
""" % (
self.base_url,
date.today(),
)
self.assertXMLEqual(response.content.decode(), expected_content)
def test_sitemap_not_callable(self):
"""A sitemap may not be callable."""
response = self.client.get('/simple-not-callable/index.xml')
response = self.client.get("/simple-not-callable/index.xml")
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>%s/simple/sitemap-simple.xml</loc><lastmod>%s</lastmod></sitemap>
</sitemapindex>
""" % (self.base_url, date.today())
""" % (
self.base_url,
date.today(),
)
self.assertXMLEqual(response.content.decode(), expected_content)
def test_paged_sitemap(self):
"""A sitemap may have multiple pages."""
response = self.client.get('/simple-paged/index.xml')
response = self.client.get("/simple-paged/index.xml")
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>{0}/simple/sitemap-simple.xml</loc><lastmod>{1}</lastmod></sitemap><sitemap><loc>{0}/simple/sitemap-simple.xml?p=2</loc><lastmod>{1}</lastmod></sitemap>
</sitemapindex>
""".format(self.base_url, date.today())
""".format(
self.base_url, date.today()
)
self.assertXMLEqual(response.content.decode(), expected_content)
@override_settings(TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(__file__), 'templates')],
}])
@override_settings(
TEMPLATES=[
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(os.path.dirname(__file__), "templates")],
}
]
)
def test_simple_sitemap_custom_lastmod_index(self):
"A simple sitemap index can be rendered with a custom template"
response = self.client.get('/simple/custom-lastmod-index.xml')
response = self.client.get("/simple/custom-lastmod-index.xml")
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
<!-- This is a customised template -->
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>%s/simple/sitemap-simple.xml</loc><lastmod>%s</lastmod></sitemap>
</sitemapindex>
""" % (self.base_url, date.today())
""" % (
self.base_url,
date.today(),
)
self.assertXMLEqual(response.content.decode(), expected_content)
def test_simple_sitemap_section(self):
"A simple sitemap section can be rendered"
response = self.client.get('/simple/sitemap-simple.xml')
response = self.client.get("/simple/sitemap-simple.xml")
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
</urlset>
""" % (self.base_url, date.today())
""" % (
self.base_url,
date.today(),
)
self.assertXMLEqual(response.content.decode(), expected_content)
def test_no_section(self):
response = self.client.get('/simple/sitemap-simple2.xml')
self.assertEqual(str(response.context['exception']), "No sitemap available for section: 'simple2'")
response = self.client.get("/simple/sitemap-simple2.xml")
self.assertEqual(
str(response.context["exception"]),
"No sitemap available for section: 'simple2'",
)
self.assertEqual(response.status_code, 404)
def test_empty_page(self):
response = self.client.get('/simple/sitemap-simple.xml?p=0')
self.assertEqual(str(response.context['exception']), 'Page 0 empty')
response = self.client.get("/simple/sitemap-simple.xml?p=0")
self.assertEqual(str(response.context["exception"]), "Page 0 empty")
self.assertEqual(response.status_code, 404)
def test_page_not_int(self):
response = self.client.get('/simple/sitemap-simple.xml?p=test')
self.assertEqual(str(response.context['exception']), "No page 'test'")
response = self.client.get("/simple/sitemap-simple.xml?p=test")
self.assertEqual(str(response.context["exception"]), "No page 'test'")
self.assertEqual(response.status_code, 404)
def test_simple_sitemap(self):
"A simple sitemap can be rendered"
response = self.client.get('/simple/sitemap.xml')
response = self.client.get("/simple/sitemap.xml")
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
</urlset>
""" % (self.base_url, date.today())
""" % (
self.base_url,
date.today(),
)
self.assertXMLEqual(response.content.decode(), expected_content)
@override_settings(TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(__file__), 'templates')],
}])
@override_settings(
TEMPLATES=[
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(os.path.dirname(__file__), "templates")],
}
]
)
def test_simple_custom_sitemap(self):
"A simple sitemap can be rendered with a custom template"
response = self.client.get('/simple/custom-sitemap.xml')
response = self.client.get("/simple/custom-sitemap.xml")
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
<!-- This is a customised template -->
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
</urlset>
""" % (self.base_url, date.today())
""" % (
self.base_url,
date.today(),
)
self.assertXMLEqual(response.content.decode(), expected_content)
def test_sitemap_last_modified(self):
"Last-Modified header is set correctly"
response = self.client.get('/lastmod/sitemap.xml')
self.assertEqual(response.headers['Last-Modified'], 'Wed, 13 Mar 2013 10:00:00 GMT')
response = self.client.get("/lastmod/sitemap.xml")
self.assertEqual(
response.headers["Last-Modified"], "Wed, 13 Mar 2013 10:00:00 GMT"
)
def test_sitemap_last_modified_date(self):
"""
The Last-Modified header should be support dates (without time).
"""
response = self.client.get('/lastmod/date-sitemap.xml')
self.assertEqual(response.headers['Last-Modified'], 'Wed, 13 Mar 2013 00:00:00 GMT')
response = self.client.get("/lastmod/date-sitemap.xml")
self.assertEqual(
response.headers["Last-Modified"], "Wed, 13 Mar 2013 00:00:00 GMT"
)
def test_sitemap_last_modified_tz(self):
"""
The Last-Modified header should be converted from timezone aware dates
to GMT.
"""
response = self.client.get('/lastmod/tz-sitemap.xml')
self.assertEqual(response.headers['Last-Modified'], 'Wed, 13 Mar 2013 15:00:00 GMT')
response = self.client.get("/lastmod/tz-sitemap.xml")
self.assertEqual(
response.headers["Last-Modified"], "Wed, 13 Mar 2013 15:00:00 GMT"
)
def test_sitemap_last_modified_missing(self):
"Last-Modified header is missing when sitemap has no lastmod"
response = self.client.get('/generic/sitemap.xml')
self.assertFalse(response.has_header('Last-Modified'))
response = self.client.get("/generic/sitemap.xml")
self.assertFalse(response.has_header("Last-Modified"))
def test_sitemap_last_modified_mixed(self):
"Last-Modified header is omitted when lastmod not on all items"
response = self.client.get('/lastmod-mixed/sitemap.xml')
self.assertFalse(response.has_header('Last-Modified'))
response = self.client.get("/lastmod-mixed/sitemap.xml")
self.assertFalse(response.has_header("Last-Modified"))
def test_sitemaps_lastmod_mixed_ascending_last_modified_missing(self):
"""
The Last-Modified header is omitted when lastmod isn't found in all
sitemaps. Test sitemaps are sorted by lastmod in ascending order.
"""
response = self.client.get('/lastmod-sitemaps/mixed-ascending.xml')
self.assertFalse(response.has_header('Last-Modified'))
response = self.client.get("/lastmod-sitemaps/mixed-ascending.xml")
self.assertFalse(response.has_header("Last-Modified"))
def test_sitemaps_lastmod_mixed_descending_last_modified_missing(self):
"""
The Last-Modified header is omitted when lastmod isn't found in all
sitemaps. Test sitemaps are sorted by lastmod in descending order.
"""
response = self.client.get('/lastmod-sitemaps/mixed-descending.xml')
self.assertFalse(response.has_header('Last-Modified'))
response = self.client.get("/lastmod-sitemaps/mixed-descending.xml")
self.assertFalse(response.has_header("Last-Modified"))
def test_sitemaps_lastmod_ascending(self):
"""
The Last-Modified header is set to the most recent sitemap lastmod.
Test sitemaps are sorted by lastmod in ascending order.
"""
response = self.client.get('/lastmod-sitemaps/ascending.xml')
self.assertEqual(response.headers['Last-Modified'], 'Sat, 20 Apr 2013 05:00:00 GMT')
response = self.client.get("/lastmod-sitemaps/ascending.xml")
self.assertEqual(
response.headers["Last-Modified"], "Sat, 20 Apr 2013 05:00:00 GMT"
)
def test_sitemaps_lastmod_descending(self):
"""
The Last-Modified header is set to the most recent sitemap lastmod.
Test sitemaps are sorted by lastmod in descending order.
"""
response = self.client.get('/lastmod-sitemaps/descending.xml')
self.assertEqual(response.headers['Last-Modified'], 'Sat, 20 Apr 2013 05:00:00 GMT')
response = self.client.get("/lastmod-sitemaps/descending.xml")
self.assertEqual(
response.headers["Last-Modified"], "Sat, 20 Apr 2013 05:00:00 GMT"
)
def test_sitemap_get_latest_lastmod_none(self):
"""
sitemapindex.lastmod is ommitted when Sitemap.lastmod is
callable and Sitemap.get_latest_lastmod is not implemented
"""
response = self.client.get('/lastmod/get-latest-lastmod-none-sitemap.xml')
self.assertNotContains(response, '<lastmod>')
response = self.client.get("/lastmod/get-latest-lastmod-none-sitemap.xml")
self.assertNotContains(response, "<lastmod>")
def test_sitemap_get_latest_lastmod(self):
"""
sitemapindex.lastmod is included when Sitemap.lastmod is
attribute and Sitemap.get_latest_lastmod is implemented
"""
response = self.client.get('/lastmod/get-latest-lastmod-sitemap.xml')
self.assertContains(response, '<lastmod>2013-03-13T10:00:00</lastmod>')
response = self.client.get("/lastmod/get-latest-lastmod-sitemap.xml")
self.assertContains(response, "<lastmod>2013-03-13T10:00:00</lastmod>")
def test_sitemap_latest_lastmod_timezone(self):
"""
lastmod datestamp shows timezones if Sitemap.get_latest_lastmod
returns an aware datetime.
"""
response = self.client.get('/lastmod/latest-lastmod-timezone-sitemap.xml')
self.assertContains(response, '<lastmod>2013-03-13T10:00:00-05:00</lastmod>')
response = self.client.get("/lastmod/latest-lastmod-timezone-sitemap.xml")
self.assertContains(response, "<lastmod>2013-03-13T10:00:00-05:00</lastmod>")
def test_localized_priority(self):
"""The priority value should not be localized."""
with translation.override('fr'):
self.assertEqual('0,3', localize(0.3))
with translation.override("fr"):
self.assertEqual("0,3", localize(0.3))
# Priorities aren't rendered in localized format.
response = self.client.get('/simple/sitemap.xml')
self.assertContains(response, '<priority>0.5</priority>')
self.assertContains(response, '<lastmod>%s</lastmod>' % date.today())
response = self.client.get("/simple/sitemap.xml")
self.assertContains(response, "<priority>0.5</priority>")
self.assertContains(response, "<lastmod>%s</lastmod>" % date.today())
@modify_settings(INSTALLED_APPS={'remove': 'django.contrib.sites'})
@modify_settings(INSTALLED_APPS={"remove": "django.contrib.sites"})
def test_requestsite_sitemap(self):
# Hitting the flatpages sitemap without the sites framework installed
# doesn't raise an exception.
response = self.client.get('/simple/sitemap.xml')
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
response = self.client.get("/simple/sitemap.xml")
expected_content = (
"""<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url><loc>http://testserver/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
</urlset>
""" % date.today()
"""
% date.today()
)
self.assertXMLEqual(response.content.decode(), expected_content)
@ignore_warnings(category=RemovedInDjango50Warning)
@@ -231,7 +275,7 @@ class HTTPSitemapTests(SitemapTestsBase):
with self.assertRaisesMessage(ImproperlyConfigured, self.use_sitemap_err_msg):
Sitemap().get_urls()
@modify_settings(INSTALLED_APPS={'remove': 'django.contrib.sites'})
@modify_settings(INSTALLED_APPS={"remove": "django.contrib.sites"})
@ignore_warnings(category=RemovedInDjango50Warning)
def test_sitemap_get_urls_no_site_2(self):
"""
@@ -249,10 +293,11 @@ class HTTPSitemapTests(SitemapTestsBase):
Sitemap.get_url() url result.
"""
test_sitemap = Sitemap()
test_sitemap.items = TestModel.objects.order_by('pk').all
test_sitemap.items = TestModel.objects.order_by("pk").all
def is_testmodel(url):
return isinstance(url['item'], TestModel)
return isinstance(url["item"], TestModel)
item_in_url_info = all(map(is_testmodel, test_sitemap.get_urls()))
self.assertTrue(item_in_url_info)
@@ -260,46 +305,51 @@ class HTTPSitemapTests(SitemapTestsBase):
"""
A cached sitemap index can be rendered (#2713).
"""
response = self.client.get('/cached/index.xml')
response = self.client.get("/cached/index.xml")
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>%s/cached/sitemap-simple.xml</loc><lastmod>%s</lastmod></sitemap>
</sitemapindex>
""" % (self.base_url, date.today())
""" % (
self.base_url,
date.today(),
)
self.assertXMLEqual(response.content.decode(), expected_content)
def test_x_robots_sitemap(self):
response = self.client.get('/simple/index.xml')
self.assertEqual(response.headers['X-Robots-Tag'], 'noindex, noodp, noarchive')
response = self.client.get("/simple/index.xml")
self.assertEqual(response.headers["X-Robots-Tag"], "noindex, noodp, noarchive")
response = self.client.get('/simple/sitemap.xml')
self.assertEqual(response.headers['X-Robots-Tag'], 'noindex, noodp, noarchive')
response = self.client.get("/simple/sitemap.xml")
self.assertEqual(response.headers["X-Robots-Tag"], "noindex, noodp, noarchive")
def test_empty_sitemap(self):
response = self.client.get('/empty/sitemap.xml')
response = self.client.get("/empty/sitemap.xml")
self.assertEqual(response.status_code, 200)
@override_settings(LANGUAGES=(('en', 'English'), ('pt', 'Portuguese')))
@override_settings(LANGUAGES=(("en", "English"), ("pt", "Portuguese")))
def test_simple_i18n_sitemap_index(self):
"""
A simple i18n sitemap index can be rendered, without logging variable
lookup errors.
"""
with self.assertNoLogs('django.template', 'DEBUG'):
response = self.client.get('/simple/i18n.xml')
with self.assertNoLogs("django.template", "DEBUG"):
response = self.client.get("/simple/i18n.xml")
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url><loc>{0}/en/i18n/testmodel/{1}/</loc><changefreq>never</changefreq><priority>0.5</priority></url><url><loc>{0}/pt/i18n/testmodel/{1}/</loc><changefreq>never</changefreq><priority>0.5</priority></url>
</urlset>
""".format(self.base_url, self.i18n_model.pk)
""".format(
self.base_url, self.i18n_model.pk
)
self.assertXMLEqual(response.content.decode(), expected_content)
@override_settings(LANGUAGES=(('en', 'English'), ('pt', 'Portuguese')))
@override_settings(LANGUAGES=(("en", "English"), ("pt", "Portuguese")))
def test_alternate_i18n_sitemap_index(self):
"""
A i18n sitemap with alternate/hreflang links can be rendered.
"""
response = self.client.get('/alternates/i18n.xml')
response = self.client.get("/alternates/i18n.xml")
url, pk = self.base_url, self.i18n_model.pk
expected_urls = f"""
<url><loc>{url}/en/i18n/testmodel/{pk}/</loc><changefreq>never</changefreq><priority>0.5</priority>
@@ -310,7 +360,9 @@ class HTTPSitemapTests(SitemapTestsBase):
<xhtml:link rel="alternate" hreflang="en" href="{url}/en/i18n/testmodel/{pk}/"/>
<xhtml:link rel="alternate" hreflang="pt" href="{url}/pt/i18n/testmodel/{pk}/"/>
</url>
""".replace('\n', '')
""".replace(
"\n", ""
)
expected_content = f"""<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
{expected_urls}
@@ -318,12 +370,14 @@ class HTTPSitemapTests(SitemapTestsBase):
"""
self.assertXMLEqual(response.content.decode(), expected_content)
@override_settings(LANGUAGES=(('en', 'English'), ('pt', 'Portuguese'), ('es', 'Spanish')))
@override_settings(
LANGUAGES=(("en", "English"), ("pt", "Portuguese"), ("es", "Spanish"))
)
def test_alternate_i18n_sitemap_limited(self):
"""
A i18n sitemap index with limited languages can be rendered.
"""
response = self.client.get('/limited/i18n.xml')
response = self.client.get("/limited/i18n.xml")
url, pk = self.base_url, self.i18n_model.pk
expected_urls = f"""
<url><loc>{url}/en/i18n/testmodel/{pk}/</loc><changefreq>never</changefreq><priority>0.5</priority>
@@ -334,7 +388,9 @@ class HTTPSitemapTests(SitemapTestsBase):
<xhtml:link rel="alternate" hreflang="en" href="{url}/en/i18n/testmodel/{pk}/"/>
<xhtml:link rel="alternate" hreflang="es" href="{url}/es/i18n/testmodel/{pk}/"/>
</url>
""".replace('\n', '')
""".replace(
"\n", ""
)
expected_content = f"""<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
{expected_urls}
@@ -342,12 +398,12 @@ class HTTPSitemapTests(SitemapTestsBase):
"""
self.assertXMLEqual(response.content.decode(), expected_content)
@override_settings(LANGUAGES=(('en', 'English'), ('pt', 'Portuguese')))
@override_settings(LANGUAGES=(("en", "English"), ("pt", "Portuguese")))
def test_alternate_i18n_sitemap_xdefault(self):
"""
A i18n sitemap index with x-default can be rendered.
"""
response = self.client.get('/x-default/i18n.xml')
response = self.client.get("/x-default/i18n.xml")
url, pk = self.base_url, self.i18n_model.pk
expected_urls = f"""
<url><loc>{url}/en/i18n/testmodel/{pk}/</loc><changefreq>never</changefreq><priority>0.5</priority>
@@ -360,7 +416,9 @@ class HTTPSitemapTests(SitemapTestsBase):
<xhtml:link rel="alternate" hreflang="pt" href="{url}/pt/i18n/testmodel/{pk}/"/>
<xhtml:link rel="alternate" hreflang="x-default" href="{url}/i18n/testmodel/{pk}/"/>
</url>
""".replace('\n', '')
""".replace(
"\n", ""
)
expected_content = f"""<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
{expected_urls}
@@ -369,7 +427,7 @@ class HTTPSitemapTests(SitemapTestsBase):
self.assertXMLEqual(response.content.decode(), expected_content)
def test_sitemap_without_entries(self):
response = self.client.get('/sitemap-without-entries/sitemap.xml')
response = self.client.get("/sitemap-without-entries/sitemap.xml")
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
@@ -381,10 +439,10 @@ class HTTPSitemapTests(SitemapTestsBase):
Not all items have `lastmod`. Therefore the `Last-Modified` header
is not set by the detail or index sitemap view.
"""
index_response = self.client.get('/callable-lastmod-partial/index.xml')
sitemap_response = self.client.get('/callable-lastmod-partial/sitemap.xml')
self.assertNotIn('Last-Modified', index_response)
self.assertNotIn('Last-Modified', sitemap_response)
index_response = self.client.get("/callable-lastmod-partial/index.xml")
sitemap_response = self.client.get("/callable-lastmod-partial/sitemap.xml")
self.assertNotIn("Last-Modified", index_response)
self.assertNotIn("Last-Modified", sitemap_response)
expected_content_index = """<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>http://example.com/simple/sitemap-callable-lastmod.xml</loc></sitemap>
@@ -403,10 +461,14 @@ class HTTPSitemapTests(SitemapTestsBase):
All items in the sitemap have `lastmod`. The `Last-Modified` header
is set for the detail and index sitemap view.
"""
index_response = self.client.get('/callable-lastmod-full/index.xml')
sitemap_response = self.client.get('/callable-lastmod-full/sitemap.xml')
self.assertEqual(index_response.headers['Last-Modified'], 'Thu, 13 Mar 2014 10:00:00 GMT')
self.assertEqual(sitemap_response.headers['Last-Modified'], 'Thu, 13 Mar 2014 10:00:00 GMT')
index_response = self.client.get("/callable-lastmod-full/index.xml")
sitemap_response = self.client.get("/callable-lastmod-full/sitemap.xml")
self.assertEqual(
index_response.headers["Last-Modified"], "Thu, 13 Mar 2014 10:00:00 GMT"
)
self.assertEqual(
sitemap_response.headers["Last-Modified"], "Thu, 13 Mar 2014 10:00:00 GMT"
)
expected_content_index = """<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>http://example.com/simple/sitemap-callable-lastmod.xml</loc><lastmod>2014-03-13T10:00:00</lastmod></sitemap>
@@ -423,27 +485,37 @@ class HTTPSitemapTests(SitemapTestsBase):
# RemovedInDjango50Warning
class DeprecatedTests(SitemapTestsBase):
@override_settings(TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(__file__), 'templates')],
}])
@override_settings(
TEMPLATES=[
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(os.path.dirname(__file__), "templates")],
}
]
)
def test_simple_sitemap_custom_index_warning(self):
msg = 'Calling `__str__` on SitemapIndexItem is deprecated, use the `location` attribute instead.'
msg = "Calling `__str__` on SitemapIndexItem is deprecated, use the `location` attribute instead."
with self.assertRaisesMessage(RemovedInDjango50Warning, msg):
self.client.get('/simple/custom-index.xml')
self.client.get("/simple/custom-index.xml")
@ignore_warnings(category=RemovedInDjango50Warning)
@override_settings(TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(__file__), 'templates')],
}])
@override_settings(
TEMPLATES=[
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(os.path.dirname(__file__), "templates")],
}
]
)
def test_simple_sitemap_custom_index(self):
"A simple sitemap index can be rendered with a custom template"
response = self.client.get('/simple/custom-index.xml')
response = self.client.get("/simple/custom-index.xml")
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
<!-- This is a customised template -->
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
</sitemapindex>
""" % (self.base_url)
""" % (
self.base_url
)
self.assertXMLEqual(response.content.decode(), expected_content)

View File

@@ -5,51 +5,63 @@ from django.test import override_settings
from .base import SitemapTestsBase
@override_settings(ROOT_URLCONF='sitemaps_tests.urls.https')
@override_settings(ROOT_URLCONF="sitemaps_tests.urls.https")
class HTTPSSitemapTests(SitemapTestsBase):
protocol = 'https'
protocol = "https"
def test_secure_sitemap_index(self):
"A secure sitemap index can be rendered"
response = self.client.get('/secure/index.xml')
response = self.client.get("/secure/index.xml")
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>%s/secure/sitemap-simple.xml</loc><lastmod>%s</lastmod></sitemap>
</sitemapindex>
""" % (self.base_url, date.today())
""" % (
self.base_url,
date.today(),
)
self.assertXMLEqual(response.content.decode(), expected_content)
def test_secure_sitemap_section(self):
"A secure sitemap section can be rendered"
response = self.client.get('/secure/sitemap-simple.xml')
response = self.client.get("/secure/sitemap-simple.xml")
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
</urlset>
""" % (self.base_url, date.today())
""" % (
self.base_url,
date.today(),
)
self.assertXMLEqual(response.content.decode(), expected_content)
@override_settings(SECURE_PROXY_SSL_HEADER=False)
class HTTPSDetectionSitemapTests(SitemapTestsBase):
extra = {'wsgi.url_scheme': 'https'}
extra = {"wsgi.url_scheme": "https"}
def test_sitemap_index_with_https_request(self):
"A sitemap index requested in HTTPS is rendered with HTTPS links"
response = self.client.get('/simple/index.xml', **self.extra)
response = self.client.get("/simple/index.xml", **self.extra)
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>%s/simple/sitemap-simple.xml</loc><lastmod>%s</lastmod></sitemap>
</sitemapindex>
""" % (self.base_url.replace('http://', 'https://'), date.today())
""" % (
self.base_url.replace("http://", "https://"),
date.today(),
)
self.assertXMLEqual(response.content.decode(), expected_content)
def test_sitemap_section_with_https_request(self):
"A sitemap section requested in HTTPS is rendered with HTTPS links"
response = self.client.get('/simple/sitemap-simple.xml', **self.extra)
response = self.client.get("/simple/sitemap-simple.xml", **self.extra)
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
</urlset>
""" % (self.base_url.replace('http://', 'https://'), date.today())
""" % (
self.base_url.replace("http://", "https://"),
date.today(),
)
self.assertXMLEqual(response.content.decode(), expected_content)

View File

@@ -5,13 +5,14 @@ from django.core.management import call_command
from .base import SitemapTestsBase
@mock.patch('django.contrib.sitemaps.management.commands.ping_google.ping_google')
@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')
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)
call_command("ping_google", "foo.xml", "--sitemap-uses-http")
ping_google_func.assert_called_with(
sitemap_url="foo.xml", sitemap_uses_https=False
)

View File

@@ -1,9 +1,7 @@
from unittest import mock
from urllib.parse import urlencode
from django.contrib.sitemaps import (
SitemapNotFound, _get_sitemap_full_url, ping_google,
)
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
@@ -11,39 +9,47 @@ from .base import SitemapTestsBase
class PingGoogleTests(SitemapTestsBase):
@override_settings(ROOT_URLCONF='sitemaps_tests.urls.sitemap_only')
@mock.patch('django.contrib.sitemaps.urlopen')
@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
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')
@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')
self.assertEqual(
_get_sitemap_full_url(None),
"https://example.com/sitemap-without-entries/sitemap.xml",
)
@override_settings(ROOT_URLCONF='sitemaps_tests.urls.index_only')
@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')
self.assertEqual(
_get_sitemap_full_url(None), "https://example.com/simple/index.xml"
)
@override_settings(ROOT_URLCONF='sitemaps_tests.urls.empty')
@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')
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'
_get_sitemap_full_url("/foo.xml", sitemap_uses_https=False),
"http://example.com/foo.xml",
)
@modify_settings(INSTALLED_APPS={'remove': 'django.contrib.sites'})
@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):

View File

@@ -13,7 +13,7 @@ from ..models import I18nTestModel, TestModel
class SimpleSitemap(Sitemap):
changefreq = "never"
priority = 0.5
location = '/location/'
location = "/location/"
lastmod = date.today()
def items(self):
@@ -33,7 +33,7 @@ class SimpleI18nSitemap(Sitemap):
i18n = True
def items(self):
return I18nTestModel.objects.order_by('pk').all()
return I18nTestModel.objects.order_by("pk").all()
class AlternatesI18nSitemap(SimpleI18nSitemap):
@@ -41,7 +41,7 @@ class AlternatesI18nSitemap(SimpleI18nSitemap):
class LimitedI18nSitemap(AlternatesI18nSitemap):
languages = ['en', 'es']
languages = ["en", "es"]
class XDefaultI18nSitemap(AlternatesI18nSitemap):
@@ -51,7 +51,7 @@ class XDefaultI18nSitemap(AlternatesI18nSitemap):
class EmptySitemap(Sitemap):
changefreq = "never"
priority = 0.5
location = '/location/'
location = "/location/"
class FixedLastmodSitemap(SimpleSitemap):
@@ -61,7 +61,7 @@ class FixedLastmodSitemap(SimpleSitemap):
class FixedLastmodMixedSitemap(Sitemap):
changefreq = "never"
priority = 0.5
location = '/location/'
location = "/location/"
loop = 0
def items(self):
@@ -85,7 +85,8 @@ class TimezoneSiteMap(SimpleSitemap):
class CallableLastmodPartialSitemap(Sitemap):
"""Not all items have `lastmod`."""
location = '/location/'
location = "/location/"
def items(self):
o1 = TestModel()
@@ -99,7 +100,8 @@ class CallableLastmodPartialSitemap(Sitemap):
class CallableLastmodFullSitemap(Sitemap):
"""All items have `lastmod`."""
location = '/location/'
location = "/location/"
def items(self):
o1 = TestModel()
@@ -115,7 +117,7 @@ class CallableLastmodFullSitemap(Sitemap):
class GetLatestLastmodNoneSiteMap(Sitemap):
changefreq = "never"
priority = 0.5
location = '/location/'
location = "/location/"
def items(self):
return [object()]
@@ -137,216 +139,292 @@ def testmodelview(request, id):
simple_sitemaps = {
'simple': SimpleSitemap,
"simple": SimpleSitemap,
}
simple_i18n_sitemaps = {
'i18n': SimpleI18nSitemap,
"i18n": SimpleI18nSitemap,
}
alternates_i18n_sitemaps = {
'i18n-alternates': AlternatesI18nSitemap,
"i18n-alternates": AlternatesI18nSitemap,
}
limited_i18n_sitemaps = {
'i18n-limited': LimitedI18nSitemap,
"i18n-limited": LimitedI18nSitemap,
}
xdefault_i18n_sitemaps = {
'i18n-xdefault': XDefaultI18nSitemap,
"i18n-xdefault": XDefaultI18nSitemap,
}
simple_sitemaps_not_callable = {
'simple': SimpleSitemap(),
"simple": SimpleSitemap(),
}
simple_sitemaps_paged = {
'simple': SimplePagedSitemap,
"simple": SimplePagedSitemap,
}
empty_sitemaps = {
'empty': EmptySitemap,
"empty": EmptySitemap,
}
fixed_lastmod_sitemaps = {
'fixed-lastmod': FixedLastmodSitemap,
"fixed-lastmod": FixedLastmodSitemap,
}
fixed_lastmod_mixed_sitemaps = {
'fixed-lastmod-mixed': FixedLastmodMixedSitemap,
"fixed-lastmod-mixed": FixedLastmodMixedSitemap,
}
sitemaps_lastmod_mixed_ascending = {
'no-lastmod': EmptySitemap,
'lastmod': FixedLastmodSitemap,
"no-lastmod": EmptySitemap,
"lastmod": FixedLastmodSitemap,
}
sitemaps_lastmod_mixed_descending = {
'lastmod': FixedLastmodSitemap,
'no-lastmod': EmptySitemap,
"lastmod": FixedLastmodSitemap,
"no-lastmod": EmptySitemap,
}
sitemaps_lastmod_ascending = {
'date': DateSiteMap,
'datetime': FixedLastmodSitemap,
'datetime-newer': FixedNewerLastmodSitemap,
"date": DateSiteMap,
"datetime": FixedLastmodSitemap,
"datetime-newer": FixedNewerLastmodSitemap,
}
sitemaps_lastmod_descending = {
'datetime-newer': FixedNewerLastmodSitemap,
'datetime': FixedLastmodSitemap,
'date': DateSiteMap,
"datetime-newer": FixedNewerLastmodSitemap,
"datetime": FixedLastmodSitemap,
"date": DateSiteMap,
}
generic_sitemaps = {
'generic': GenericSitemap({'queryset': TestModel.objects.order_by('pk').all()}),
"generic": GenericSitemap({"queryset": TestModel.objects.order_by("pk").all()}),
}
get_latest_lastmod_none_sitemaps = {
'get-latest-lastmod-none': GetLatestLastmodNoneSiteMap,
"get-latest-lastmod-none": GetLatestLastmodNoneSiteMap,
}
get_latest_lastmod_sitemaps = {
'get-latest-lastmod': GetLatestLastmodSiteMap,
"get-latest-lastmod": GetLatestLastmodSiteMap,
}
latest_lastmod_timezone_sitemaps = {
'latest-lastmod-timezone': TimezoneSiteMap,
"latest-lastmod-timezone": TimezoneSiteMap,
}
generic_sitemaps_lastmod = {
'generic': GenericSitemap({
'queryset': TestModel.objects.order_by('pk').all(),
'date_field': 'lastmod',
}),
"generic": GenericSitemap(
{
"queryset": TestModel.objects.order_by("pk").all(),
"date_field": "lastmod",
}
),
}
callable_lastmod_partial_sitemap = {
'callable-lastmod': CallableLastmodPartialSitemap,
"callable-lastmod": CallableLastmodPartialSitemap,
}
callable_lastmod_full_sitemap = {
'callable-lastmod': CallableLastmodFullSitemap,
"callable-lastmod": CallableLastmodFullSitemap,
}
urlpatterns = [
path('simple/index.xml', views.index, {'sitemaps': simple_sitemaps}),
path('simple-paged/index.xml', views.index, {'sitemaps': simple_sitemaps_paged}),
path('simple-not-callable/index.xml', views.index, {'sitemaps': simple_sitemaps_not_callable}),
path("simple/index.xml", views.index, {"sitemaps": simple_sitemaps}),
path("simple-paged/index.xml", views.index, {"sitemaps": simple_sitemaps_paged}),
path(
'simple/custom-index.xml', views.index,
{'sitemaps': simple_sitemaps, 'template_name': 'custom_sitemap_index.xml'}),
path(
'simple/custom-lastmod-index.xml', views.index,
{'sitemaps': simple_sitemaps, 'template_name': 'custom_sitemap_lastmod_index.xml'},
"simple-not-callable/index.xml",
views.index,
{"sitemaps": simple_sitemaps_not_callable},
),
path(
'simple/sitemap-<section>.xml', views.sitemap,
{'sitemaps': simple_sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
path(
'simple/sitemap.xml', views.sitemap,
{'sitemaps': simple_sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
path(
'simple/i18n.xml', views.sitemap,
{'sitemaps': simple_i18n_sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
path(
'alternates/i18n.xml', views.sitemap,
{'sitemaps': alternates_i18n_sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
path(
'limited/i18n.xml', views.sitemap,
{'sitemaps': limited_i18n_sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
path(
'x-default/i18n.xml', views.sitemap,
{'sitemaps': xdefault_i18n_sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
path(
'simple/custom-sitemap.xml', views.sitemap,
{'sitemaps': simple_sitemaps, 'template_name': 'custom_sitemap.xml'},
name='django.contrib.sitemaps.views.sitemap'),
path(
'empty/sitemap.xml', views.sitemap,
{'sitemaps': empty_sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
path(
'lastmod/sitemap.xml', views.sitemap,
{'sitemaps': fixed_lastmod_sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
path(
'lastmod-mixed/sitemap.xml', views.sitemap,
{'sitemaps': fixed_lastmod_mixed_sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
path(
'lastmod/date-sitemap.xml', views.sitemap,
{'sitemaps': {'date-sitemap': DateSiteMap}},
name='django.contrib.sitemaps.views.sitemap'),
path(
'lastmod/tz-sitemap.xml', views.sitemap,
{'sitemaps': {'tz-sitemap': TimezoneSiteMap}},
name='django.contrib.sitemaps.views.sitemap'),
path(
'lastmod-sitemaps/mixed-ascending.xml', views.sitemap,
{'sitemaps': sitemaps_lastmod_mixed_ascending},
name='django.contrib.sitemaps.views.sitemap'),
path(
'lastmod-sitemaps/mixed-descending.xml', views.sitemap,
{'sitemaps': sitemaps_lastmod_mixed_descending},
name='django.contrib.sitemaps.views.sitemap'),
path(
'lastmod-sitemaps/ascending.xml', views.sitemap,
{'sitemaps': sitemaps_lastmod_ascending},
name='django.contrib.sitemaps.views.sitemap'),
path(
'lastmod-sitemaps/descending.xml', views.sitemap,
{'sitemaps': sitemaps_lastmod_descending},
name='django.contrib.sitemaps.views.sitemap'),
path(
'lastmod/get-latest-lastmod-none-sitemap.xml', views.index,
{'sitemaps': get_latest_lastmod_none_sitemaps},
name='django.contrib.sitemaps.views.index',
"simple/custom-index.xml",
views.index,
{"sitemaps": simple_sitemaps, "template_name": "custom_sitemap_index.xml"},
),
path(
'lastmod/get-latest-lastmod-sitemap.xml', views.index,
{'sitemaps': get_latest_lastmod_sitemaps},
name='django.contrib.sitemaps.views.index',
"simple/custom-lastmod-index.xml",
views.index,
{
"sitemaps": simple_sitemaps,
"template_name": "custom_sitemap_lastmod_index.xml",
},
),
path(
'lastmod/latest-lastmod-timezone-sitemap.xml', views.index,
{'sitemaps': latest_lastmod_timezone_sitemaps},
name='django.contrib.sitemaps.views.index',
"simple/sitemap-<section>.xml",
views.sitemap,
{"sitemaps": simple_sitemaps},
name="django.contrib.sitemaps.views.sitemap",
),
path(
'generic/sitemap.xml', views.sitemap,
{'sitemaps': generic_sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
"simple/sitemap.xml",
views.sitemap,
{"sitemaps": simple_sitemaps},
name="django.contrib.sitemaps.views.sitemap",
),
path(
'generic-lastmod/sitemap.xml', views.sitemap,
{'sitemaps': generic_sitemaps_lastmod},
name='django.contrib.sitemaps.views.sitemap'),
"simple/i18n.xml",
views.sitemap,
{"sitemaps": simple_i18n_sitemaps},
name="django.contrib.sitemaps.views.sitemap",
),
path(
'cached/index.xml', cache_page(1)(views.index),
{'sitemaps': simple_sitemaps, 'sitemap_url_name': 'cached_sitemap'}),
"alternates/i18n.xml",
views.sitemap,
{"sitemaps": alternates_i18n_sitemaps},
name="django.contrib.sitemaps.views.sitemap",
),
path(
'cached/sitemap-<section>.xml', cache_page(1)(views.sitemap),
{'sitemaps': simple_sitemaps}, name='cached_sitemap'),
"limited/i18n.xml",
views.sitemap,
{"sitemaps": limited_i18n_sitemaps},
name="django.contrib.sitemaps.views.sitemap",
),
path(
'sitemap-without-entries/sitemap.xml', views.sitemap,
{'sitemaps': {}}, name='django.contrib.sitemaps.views.sitemap'),
path('callable-lastmod-partial/index.xml', views.index, {'sitemaps': callable_lastmod_partial_sitemap}),
path('callable-lastmod-partial/sitemap.xml', views.sitemap, {'sitemaps': callable_lastmod_partial_sitemap}),
path('callable-lastmod-full/index.xml', views.index, {'sitemaps': callable_lastmod_full_sitemap}),
path('callable-lastmod-full/sitemap.xml', views.sitemap, {'sitemaps': callable_lastmod_full_sitemap}),
"x-default/i18n.xml",
views.sitemap,
{"sitemaps": xdefault_i18n_sitemaps},
name="django.contrib.sitemaps.views.sitemap",
),
path(
'generic-lastmod/index.xml', views.index,
{'sitemaps': generic_sitemaps_lastmod},
name='django.contrib.sitemaps.views.index',
"simple/custom-sitemap.xml",
views.sitemap,
{"sitemaps": simple_sitemaps, "template_name": "custom_sitemap.xml"},
name="django.contrib.sitemaps.views.sitemap",
),
path(
"empty/sitemap.xml",
views.sitemap,
{"sitemaps": empty_sitemaps},
name="django.contrib.sitemaps.views.sitemap",
),
path(
"lastmod/sitemap.xml",
views.sitemap,
{"sitemaps": fixed_lastmod_sitemaps},
name="django.contrib.sitemaps.views.sitemap",
),
path(
"lastmod-mixed/sitemap.xml",
views.sitemap,
{"sitemaps": fixed_lastmod_mixed_sitemaps},
name="django.contrib.sitemaps.views.sitemap",
),
path(
"lastmod/date-sitemap.xml",
views.sitemap,
{"sitemaps": {"date-sitemap": DateSiteMap}},
name="django.contrib.sitemaps.views.sitemap",
),
path(
"lastmod/tz-sitemap.xml",
views.sitemap,
{"sitemaps": {"tz-sitemap": TimezoneSiteMap}},
name="django.contrib.sitemaps.views.sitemap",
),
path(
"lastmod-sitemaps/mixed-ascending.xml",
views.sitemap,
{"sitemaps": sitemaps_lastmod_mixed_ascending},
name="django.contrib.sitemaps.views.sitemap",
),
path(
"lastmod-sitemaps/mixed-descending.xml",
views.sitemap,
{"sitemaps": sitemaps_lastmod_mixed_descending},
name="django.contrib.sitemaps.views.sitemap",
),
path(
"lastmod-sitemaps/ascending.xml",
views.sitemap,
{"sitemaps": sitemaps_lastmod_ascending},
name="django.contrib.sitemaps.views.sitemap",
),
path(
"lastmod-sitemaps/descending.xml",
views.sitemap,
{"sitemaps": sitemaps_lastmod_descending},
name="django.contrib.sitemaps.views.sitemap",
),
path(
"lastmod/get-latest-lastmod-none-sitemap.xml",
views.index,
{"sitemaps": get_latest_lastmod_none_sitemaps},
name="django.contrib.sitemaps.views.index",
),
path(
"lastmod/get-latest-lastmod-sitemap.xml",
views.index,
{"sitemaps": get_latest_lastmod_sitemaps},
name="django.contrib.sitemaps.views.index",
),
path(
"lastmod/latest-lastmod-timezone-sitemap.xml",
views.index,
{"sitemaps": latest_lastmod_timezone_sitemaps},
name="django.contrib.sitemaps.views.index",
),
path(
"generic/sitemap.xml",
views.sitemap,
{"sitemaps": generic_sitemaps},
name="django.contrib.sitemaps.views.sitemap",
),
path(
"generic-lastmod/sitemap.xml",
views.sitemap,
{"sitemaps": generic_sitemaps_lastmod},
name="django.contrib.sitemaps.views.sitemap",
),
path(
"cached/index.xml",
cache_page(1)(views.index),
{"sitemaps": simple_sitemaps, "sitemap_url_name": "cached_sitemap"},
),
path(
"cached/sitemap-<section>.xml",
cache_page(1)(views.sitemap),
{"sitemaps": simple_sitemaps},
name="cached_sitemap",
),
path(
"sitemap-without-entries/sitemap.xml",
views.sitemap,
{"sitemaps": {}},
name="django.contrib.sitemaps.views.sitemap",
),
path(
"callable-lastmod-partial/index.xml",
views.index,
{"sitemaps": callable_lastmod_partial_sitemap},
),
path(
"callable-lastmod-partial/sitemap.xml",
views.sitemap,
{"sitemaps": callable_lastmod_partial_sitemap},
),
path(
"callable-lastmod-full/index.xml",
views.index,
{"sitemaps": callable_lastmod_full_sitemap},
),
path(
"callable-lastmod-full/sitemap.xml",
views.sitemap,
{"sitemaps": callable_lastmod_full_sitemap},
),
path(
"generic-lastmod/index.xml",
views.index,
{"sitemaps": generic_sitemaps_lastmod},
name="django.contrib.sitemaps.views.index",
),
]
urlpatterns += i18n_patterns(
path('i18n/testmodel/<int:id>/', testmodelview, name='i18n_testmodel'),
path("i18n/testmodel/<int:id>/", testmodelview, name="i18n_testmodel"),
)

View File

@@ -5,17 +5,19 @@ from .http import SimpleSitemap
class HTTPSSitemap(SimpleSitemap):
protocol = 'https'
protocol = "https"
secure_sitemaps = {
'simple': HTTPSSitemap,
"simple": HTTPSSitemap,
}
urlpatterns = [
path('secure/index.xml', views.index, {'sitemaps': secure_sitemaps}),
path("secure/index.xml", views.index, {"sitemaps": secure_sitemaps}),
path(
'secure/sitemap-<section>.xml', views.sitemap,
{'sitemaps': secure_sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
"secure/sitemap-<section>.xml",
views.sitemap,
{"sitemaps": secure_sitemaps},
name="django.contrib.sitemaps.views.sitemap",
),
]

View File

@@ -5,6 +5,9 @@ from .http import simple_sitemaps
urlpatterns = [
path(
'simple/index.xml', views.index, {'sitemaps': simple_sitemaps},
name='django.contrib.sitemaps.views.index'),
"simple/index.xml",
views.index,
{"sitemaps": simple_sitemaps},
name="django.contrib.sitemaps.views.index",
),
]

View File

@@ -3,7 +3,9 @@ from django.urls import path
urlpatterns = [
path(
'sitemap-without-entries/sitemap.xml', views.sitemap,
{'sitemaps': {}}, name='django.contrib.sitemaps.views.sitemap',
"sitemap-without-entries/sitemap.xml",
views.sitemap,
{"sitemaps": {}},
name="django.contrib.sitemaps.views.sitemap",
),
]