From 12745d8a4f89b00f360cb6102a25ab244135098c Mon Sep 17 00:00:00 2001 From: chex Date: Sat, 25 Feb 2017 17:54:17 +0500 Subject: [PATCH] Added tests for contrib.sitemaps.GenericSitemap. --- tests/sitemaps_tests/test_generic.py | 24 ++++++++++++++++++++++++ tests/sitemaps_tests/test_http.py | 5 +++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/sitemaps_tests/test_generic.py b/tests/sitemaps_tests/test_generic.py index a345dcdd9fa..4f58006c865 100644 --- a/tests/sitemaps_tests/test_generic.py +++ b/tests/sitemaps_tests/test_generic.py @@ -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') diff --git a/tests/sitemaps_tests/test_http.py b/tests/sitemaps_tests/test_http.py index 8a5c399eed2..42962bb01c7 100644 --- a/tests/sitemaps_tests/test_http.py +++ b/tests/sitemaps_tests/test_http.py @@ -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)