diff options
| author | Matt Deacalion Stevens <matt@dirtymonkey.co.uk> | 2013-07-17 20:20:20 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-07-19 10:38:34 -0400 |
| commit | a269ea4fe0a9a7195f1bd8bf5d462f48c226d525 (patch) | |
| tree | 530f23d3577e988407c3a46100ede866a9cb3cbc /tests | |
| parent | e1c737b62fed5b77cb22c2abe01c304bf5aef6f7 (diff) | |
Fixed #14656 -- Added Atom1Feed `published` element
Some feed aggregators make use of the `published` element as well as
the `updated` element (within the Atom standard -- http://bit.ly/2YySb).
The standard allows for these two elements to be present in the same
entry. `Atom1Feed` had implemented the `updated` element which was
incorrectly taking the date from `pubdate`.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/syndication/feeds.py | 20 | ||||
| -rw-r--r-- | tests/syndication/fixtures/feeddata.json | 21 | ||||
| -rw-r--r-- | tests/syndication/models.py | 6 | ||||
| -rw-r--r-- | tests/syndication/tests.py | 78 | ||||
| -rw-r--r-- | tests/syndication/urls.py | 1 |
5 files changed, 108 insertions, 18 deletions
diff --git a/tests/syndication/feeds.py b/tests/syndication/feeds.py index 0956820bf0..1cd5c3d988 100644 --- a/tests/syndication/feeds.py +++ b/tests/syndication/feeds.py @@ -33,7 +33,10 @@ class TestRss2Feed(views.Feed): return "Overridden description: %s" % item def item_pubdate(self, item): - return item.date + return item.published + + def item_updateddate(self, item): + return item.updated item_author_name = 'Sally Smith' item_author_email = 'test@example.com' @@ -72,6 +75,17 @@ class TestAtomFeed(TestRss2Feed): subtitle = TestRss2Feed.description +class TestLatestFeed(TestRss2Feed): + """ + A feed where the latest entry date is an `updated` element. + """ + feed_type = feedgenerator.Atom1Feed + subtitle = TestRss2Feed.description + + def items(self): + return Entry.objects.exclude(pk=5) + + class ArticlesFeed(TestRss2Feed): """ A feed to test no link being defined. Articles have no get_absolute_url() @@ -115,7 +129,7 @@ class NaiveDatesFeed(TestAtomFeed): A feed with naive (non-timezone-aware) dates. """ def item_pubdate(self, item): - return item.date + return item.published class TZAwareDatesFeed(TestAtomFeed): @@ -126,7 +140,7 @@ class TZAwareDatesFeed(TestAtomFeed): # Provide a weird offset so that the test can know it's getting this # specific offset and not accidentally getting on from # settings.TIME_ZONE. - return item.date.replace(tzinfo=tzinfo.FixedOffset(42)) + return item.published.replace(tzinfo=tzinfo.FixedOffset(42)) class TestFeedUrlFeed(TestAtomFeed): diff --git a/tests/syndication/fixtures/feeddata.json b/tests/syndication/fixtures/feeddata.json index 167115c925..52e5028fcd 100644 --- a/tests/syndication/fixtures/feeddata.json +++ b/tests/syndication/fixtures/feeddata.json @@ -4,7 +4,8 @@ "pk": 1, "fields": { "title": "My first entry", - "date": "1850-01-01 12:30:00" + "updated": "1850-01-01 12:30:00", + "published": "1066-09-25 20:15:00" } }, { @@ -12,7 +13,8 @@ "pk": 2, "fields": { "title": "My second entry", - "date": "2008-01-02 12:30:00" + "updated": "2008-01-02 12:30:00", + "published": "2006-03-17 18:00:00" } }, { @@ -20,7 +22,8 @@ "pk": 3, "fields": { "title": "My third entry", - "date": "2008-01-02 13:30:00" + "updated": "2008-01-02 13:30:00", + "published": "2005-06-14 10:45:00" } }, { @@ -28,7 +31,17 @@ "pk": 4, "fields": { "title": "A & B < C > D", - "date": "2008-01-03 13:30:00" + "updated": "2008-01-03 13:30:00", + "published": "2005-11-25 12:11:23" + } + }, + { + "model": "syndication.entry", + "pk": 5, + "fields": { + "title": "My last entry", + "updated": "2013-01-20 00:00:00", + "published": "2013-03-25 20:00:00" } }, { diff --git a/tests/syndication/models.py b/tests/syndication/models.py index 10b3fe3a0c..166acd69ca 100644 --- a/tests/syndication/models.py +++ b/tests/syndication/models.py @@ -5,10 +5,11 @@ from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Entry(models.Model): title = models.CharField(max_length=200) - date = models.DateTimeField() + updated = models.DateTimeField() + published = models.DateTimeField() class Meta: - ordering = ('date',) + ordering = ('updated',) def __str__(self): return self.title @@ -24,4 +25,3 @@ class Article(models.Model): def __str__(self): return self.title - diff --git a/tests/syndication/tests.py b/tests/syndication/tests.py index 1627f7182b..d3b0058d53 100644 --- a/tests/syndication/tests.py +++ b/tests/syndication/tests.py @@ -58,7 +58,7 @@ class SyndicationFeedTest(FeedTestCase): chan = chan_elem[0] # Find the last build date - d = Entry.objects.latest('date').date + d = Entry.objects.latest('published').published ltz = tzinfo.LocalTimezone(d) last_build_date = rfc2822_date(d.replace(tzinfo=ltz)) @@ -88,7 +88,7 @@ class SyndicationFeedTest(FeedTestCase): ) # Find the pubdate of the first feed item - d = Entry.objects.get(pk=1).date + d = Entry.objects.get(pk=1).published ltz = tzinfo.LocalTimezone(d) pub_date = rfc2822_date(d.replace(tzinfo=ltz)) @@ -203,10 +203,61 @@ class SyndicationFeedTest(FeedTestCase): entries = feed.getElementsByTagName('entry') self.assertEqual(len(entries), Entry.objects.count()) for entry in entries: - self.assertChildNodes(entry, ['title', 'link', 'id', 'summary', 'category', 'updated', 'rights', 'author']) + self.assertChildNodes(entry, [ + 'title', + 'link', + 'id', + 'summary', + 'category', + 'updated', + 'published', + 'rights', + 'author', + ]) summary = entry.getElementsByTagName('summary')[0] self.assertEqual(summary.getAttribute('type'), 'html') + def test_atom_feed_published_and_updated_elements(self): + """ + Test that the published and updated elements are not + the same and now adhere to RFC 4287. + """ + response = self.client.get('/syndication/atom/') + feed = minidom.parseString(response.content).firstChild + entries = feed.getElementsByTagName('entry') + + published = entries[0].getElementsByTagName('published')[0].firstChild.wholeText + updated = entries[0].getElementsByTagName('updated')[0].firstChild.wholeText + + self.assertNotEqual(published, updated) + + def test_latest_post_date(self): + """ + Test that both the published and updated dates are + considered when determining the latest post date. + """ + # this feed has a `published` element with the latest date + response = self.client.get('/syndication/atom/') + feed = minidom.parseString(response.content).firstChild + updated = feed.getElementsByTagName('updated')[0].firstChild.wholeText + + d = Entry.objects.latest('published').published + ltz = tzinfo.LocalTimezone(d) + latest_published = rfc3339_date(d.replace(tzinfo=ltz)) + + self.assertEqual(updated, latest_published) + + # this feed has an `updated` element with the latest date + response = self.client.get('/syndication/latest/') + feed = minidom.parseString(response.content).firstChild + updated = feed.getElementsByTagName('updated')[0].firstChild.wholeText + + d = Entry.objects.exclude(pk=5).latest('updated').updated + ltz = tzinfo.LocalTimezone(d) + latest_updated = rfc3339_date(d.replace(tzinfo=ltz)) + + self.assertEqual(updated, latest_updated) + def test_custom_feed_generator(self): response = self.client.get('/syndication/custom/') feed = minidom.parseString(response.content).firstChild @@ -219,7 +270,18 @@ class SyndicationFeedTest(FeedTestCase): self.assertEqual(len(entries), Entry.objects.count()) for entry in entries: self.assertEqual(entry.getAttribute('bacon'), 'yum') - self.assertChildNodes(entry, ['title', 'link', 'id', 'summary', 'ministry', 'rights', 'author', 'updated', 'category']) + self.assertChildNodes(entry, [ + 'title', + 'link', + 'id', + 'summary', + 'ministry', + 'rights', + 'author', + 'updated', + 'published', + 'category', + ]) summary = entry.getElementsByTagName('summary')[0] self.assertEqual(summary.getAttribute('type'), 'html') @@ -245,7 +307,7 @@ class SyndicationFeedTest(FeedTestCase): doc = minidom.parseString(response.content) updated = doc.getElementsByTagName('updated')[0].firstChild.wholeText - d = Entry.objects.latest('date').date + d = Entry.objects.latest('published').published ltz = tzinfo.LocalTimezone(d) latest = rfc3339_date(d.replace(tzinfo=ltz)) @@ -257,12 +319,12 @@ class SyndicationFeedTest(FeedTestCase): """ response = self.client.get('/syndication/aware-dates/') doc = minidom.parseString(response.content) - updated = doc.getElementsByTagName('updated')[0].firstChild.wholeText - self.assertEqual(updated[-6:], '+00:42') + published = doc.getElementsByTagName('published')[0].firstChild.wholeText + self.assertEqual(published[-6:], '+00:42') def test_feed_last_modified_time(self): response = self.client.get('/syndication/naive-dates/') - self.assertEqual(response['Last-Modified'], 'Thu, 03 Jan 2008 19:30:00 GMT') + self.assertEqual(response['Last-Modified'], 'Tue, 26 Mar 2013 01:00:00 GMT') # No last-modified when feed has no item_pubdate response = self.client.get('/syndication/no_pubdate/') diff --git a/tests/syndication/urls.py b/tests/syndication/urls.py index 1dd7e92332..06a75a4e68 100644 --- a/tests/syndication/urls.py +++ b/tests/syndication/urls.py @@ -15,6 +15,7 @@ urlpatterns = patterns('django.contrib.syndication.views', (r'^syndication/rss091/$', feeds.TestRss091Feed()), (r'^syndication/no_pubdate/$', feeds.TestNoPubdateFeed()), (r'^syndication/atom/$', feeds.TestAtomFeed()), + (r'^syndication/latest/$', feeds.TestLatestFeed()), (r'^syndication/custom/$', feeds.TestCustomFeed()), (r'^syndication/naive-dates/$', feeds.NaiveDatesFeed()), (r'^syndication/aware-dates/$', feeds.TZAwareDatesFeed()), |
