Added tests for contrib.sitemaps.GenericSitemap.
This commit is contained in:
parent
b427f0d674
commit
12745d8a4f
|
@ -1,3 +1,6 @@
|
|||
from datetime import datetime
|
||||
|
||||
from django.contrib.sitemaps import GenericSitemap
|
||||
from django.test import override_settings
|
||||
|
||||
from .base import SitemapTestsBase
|
||||
|
@ -7,6 +10,27 @@ 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,
|
||||
},
|
||||
priority=0.6,
|
||||
changefreq='monthly',
|
||||
)
|
||||
attr_values = (
|
||||
('date_field', datetime_value),
|
||||
('priority', 0.6),
|
||||
('changefreq', 'monthly'),
|
||||
)
|
||||
for attr_name, expected_value in attr_values:
|
||||
with self.subTest(attr_name=attr_name):
|
||||
self.assertEqual(getattr(generic_sitemap, attr_name), expected_value)
|
||||
self.assertCountEqual(generic_sitemap.queryset, queryset)
|
||||
|
||||
def test_generic_sitemap(self):
|
||||
"A minimal generic sitemap can be rendered"
|
||||
response = self.client.get('/generic/sitemap.xml')
|
||||
|
|
|
@ -4,7 +4,7 @@ from unittest import skipUnless
|
|||
|
||||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
from django.contrib.sitemaps import GenericSitemap, Sitemap
|
||||
from django.contrib.sitemaps import Sitemap
|
||||
from django.contrib.sites.models import Site
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.test import modify_settings, override_settings
|
||||
|
@ -190,7 +190,8 @@ class HTTPSitemapTests(SitemapTestsBase):
|
|||
Check to make sure that the raw item is included with each
|
||||
Sitemap.get_url() url result.
|
||||
"""
|
||||
test_sitemap = GenericSitemap({'queryset': TestModel.objects.order_by('pk').all()})
|
||||
test_sitemap = Sitemap()
|
||||
test_sitemap.items = TestModel.objects.order_by('pk').all
|
||||
|
||||
def is_testmodel(url):
|
||||
return isinstance(url['item'], TestModel)
|
||||
|
|
Loading…
Reference in New Issue