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:
committed by
Mariusz Felisiak
parent
f68fa8b45d
commit
9c19aff7c7
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user