diff --git a/AUTHORS b/AUTHORS index bb18fe15db..f1a4315c8d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -694,6 +694,7 @@ answer newbie questions, and generally made Django that much better: Nis Jørgensen Nowell Strite Nuno Mariz + Octavio Peri oggie rob oggy Oliver Beattie diff --git a/tests/syndication_tests/feeds.py b/tests/syndication_tests/feeds.py index adc3b2e56c..520f8c3ecd 100644 --- a/tests/syndication_tests/feeds.py +++ b/tests/syndication_tests/feeds.py @@ -143,6 +143,26 @@ class TestLanguageFeed(TestRss2Feed): language = 'de' +class TestGetObjectFeed(TestRss2Feed): + def get_object(self, request, entry_id): + return Entry.objects.get(pk=entry_id) + + def items(self, obj): + return Article.objects.filter(entry=obj) + + def item_link(self, item): + return '%sarticle/%s/' % (item.entry.get_absolute_url(), item.pk) + + def item_comments(self, item): + return '%scomments' % self.item_link(item) + + def item_description(self, item): + return 'Article description: %s' % item.title + + def item_title(self, item): + return 'Title: %s' % item.title + + class NaiveDatesFeed(TestAtomFeed): """ A feed with naive (non-timezone-aware) dates. diff --git a/tests/syndication_tests/models.py b/tests/syndication_tests/models.py index 0ca47c24eb..f31a7e2f2f 100644 --- a/tests/syndication_tests/models.py +++ b/tests/syndication_tests/models.py @@ -19,3 +19,8 @@ class Entry(models.Model): class Article(models.Model): title = models.CharField(max_length=200) entry = models.ForeignKey(Entry, models.CASCADE) + updated = models.DateTimeField() + published = models.DateTimeField() + + class Meta: + ordering = ['updated'] diff --git a/tests/syndication_tests/tests.py b/tests/syndication_tests/tests.py index b763bba6cb..35b68e849b 100644 --- a/tests/syndication_tests/tests.py +++ b/tests/syndication_tests/tests.py @@ -38,7 +38,12 @@ class FeedTestCase(TestCase): title='My last entry', updated=datetime.datetime(2013, 1, 20, 0, 0), published=datetime.datetime(2013, 3, 25, 20, 0) ) - cls.a1 = Article.objects.create(title='My first article', entry=cls.e1) + cls.a1 = Article.objects.create( + title='My first article', + entry=cls.e1, + updated=datetime.datetime(1986, 11, 21, 9, 12, 18), + published=datetime.datetime(1986, 10, 21, 9, 12, 18), + ) def assertChildNodes(self, elem, expected): actual = {n.nodeName for n in elem.childNodes} @@ -522,3 +527,22 @@ class SyndicationFeedTest(FeedTestCase): for prefix in prefix_domain_mapping: with self.subTest(prefix=prefix): self.assertEqual(views.add_domain(*prefix[0]), prefix[1]) + + def test_get_object(self): + response = self.client.get('/syndication/rss2/articles/%s/' % self.e1.pk) + doc = minidom.parseString(response.content) + feed = doc.getElementsByTagName('rss')[0] + chan = feed.getElementsByTagName('channel')[0] + items = chan.getElementsByTagName('item') + + self.assertChildNodeContent(items[0], { + 'comments': '/blog/1/article/1/comments', + 'description': 'Article description: My first article', + 'link': 'http://example.com/blog/1/article/1/', + 'title': 'Title: My first article', + 'pubDate': rfc2822_date(timezone.make_aware(self.a1.published, TZ)), + }) + + def test_get_non_existent_object(self): + response = self.client.get('/syndication/rss2/articles/0/') + self.assertEqual(response.status_code, 404) diff --git a/tests/syndication_tests/urls.py b/tests/syndication_tests/urls.py index bff7bd0c8d..438aa6f508 100644 --- a/tests/syndication_tests/urls.py +++ b/tests/syndication_tests/urls.py @@ -4,6 +4,7 @@ from . import feeds urlpatterns = [ path('syndication/rss2/', feeds.TestRss2Feed()), + path('syndication/rss2/articles//', feeds.TestGetObjectFeed()), path( 'syndication/rss2/guid_ispermalink_true/', feeds.TestRss2FeedWithGuidIsPermaLinkTrue()),