diff options
| author | Alexander Rudakov <piercemind@gmail.com> | 2015-12-26 21:01:25 +0300 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-01-23 08:48:31 -0500 |
| commit | 002a4f72c46458514d97f7e54d4fd9416d89899d (patch) | |
| tree | c95c3b0bbe1a77761ae8f4159d4af3adf783808d /tests | |
| parent | 104eddbdf6c31984b5afbdf5477267570de6d0f4 (diff) | |
Fixed #25989 -- Corrected sitemap's Last-Modified header to use the latest lastmod of all sitemaps.
Previously, the lastmod of the last sitemap was always used.
All sitemaps are required to have a lastmod.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/sitemaps_tests/test_http.py | 32 | ||||
| -rw-r--r-- | tests/sitemaps_tests/urls/http.py | 39 |
2 files changed, 71 insertions, 0 deletions
diff --git a/tests/sitemaps_tests/test_http.py b/tests/sitemaps_tests/test_http.py index 399cd35ae6..38a79a03f2 100644 --- a/tests/sitemaps_tests/test_http.py +++ b/tests/sitemaps_tests/test_http.py @@ -110,6 +110,38 @@ class HTTPSitemapTests(SitemapTestsBase): 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')) + + 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')) + + 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['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['Last-Modified'], 'Sat, 20 Apr 2013 05:00:00 GMT') + @skipUnless(settings.USE_I18N, "Internationalization is not enabled") @override_settings(USE_L10N=True) def test_localized_priority(self): diff --git a/tests/sitemaps_tests/urls/http.py b/tests/sitemaps_tests/urls/http.py index df423c7636..fcc5964d7a 100644 --- a/tests/sitemaps_tests/urls/http.py +++ b/tests/sitemaps_tests/urls/http.py @@ -1,3 +1,4 @@ +from collections import OrderedDict from datetime import date, datetime from django.conf.urls import url @@ -55,6 +56,10 @@ class FixedLastmodMixedSitemap(Sitemap): return [o1, o2] +class FixedNewerLastmodSitemap(SimpleSitemap): + lastmod = datetime(2013, 4, 20, 5, 0, 0) + + class DateSiteMap(SimpleSitemap): lastmod = date(2013, 3, 13) @@ -87,6 +92,28 @@ fixed_lastmod__mixed_sitemaps = { 'fixed-lastmod-mixed': FixedLastmodMixedSitemap, } +sitemaps_lastmod_mixed_ascending = OrderedDict([ + ('no-lastmod', EmptySitemap), + ('lastmod', FixedLastmodSitemap), +]) + +sitemaps_lastmod_mixed_descending = OrderedDict([ + ('lastmod', FixedLastmodSitemap), + ('no-lastmod', EmptySitemap), +]) + +sitemaps_lastmod_ascending = OrderedDict([ + ('date', DateSiteMap), + ('datetime', FixedLastmodSitemap), + ('datetime-newer', FixedNewerLastmodSitemap), +]) + +sitemaps_lastmod_descending = OrderedDict([ + ('datetime-newer', FixedNewerLastmodSitemap), + ('datetime', FixedLastmodSitemap), + ('date', DateSiteMap), +]) + generic_sitemaps = { 'generic': GenericSitemap({'queryset': TestModel.objects.all()}), } @@ -123,6 +150,18 @@ urlpatterns = [ url(r'^lastmod/tz-sitemap.xml$', views.sitemap, {'sitemaps': {'tz-sitemap': TimezoneSiteMap}}, name='django.contrib.sitemaps.views.sitemap'), + url(r'^lastmod-sitemaps/mixed-ascending.xml$', views.sitemap, + {'sitemaps': sitemaps_lastmod_mixed_ascending}, + name='django.contrib.sitemaps.views.sitemap'), + url(r'^lastmod-sitemaps/mixed-descending.xml$', views.sitemap, + {'sitemaps': sitemaps_lastmod_mixed_descending}, + name='django.contrib.sitemaps.views.sitemap'), + url(r'^lastmod-sitemaps/ascending.xml$', views.sitemap, + {'sitemaps': sitemaps_lastmod_ascending}, + name='django.contrib.sitemaps.views.sitemap'), + url(r'^lastmod-sitemaps/descending.xml$', views.sitemap, + {'sitemaps': sitemaps_lastmod_descending}, + name='django.contrib.sitemaps.views.sitemap'), url(r'^generic/sitemap\.xml$', views.sitemap, {'sitemaps': generic_sitemaps}, name='django.contrib.sitemaps.views.sitemap'), |
