mirror of https://github.com/django/django.git
Fixed #22490 -- Added tests for Feed.get_object().
This commit is contained in:
parent
e92971ccb0
commit
746bb13ceb
1
AUTHORS
1
AUTHORS
|
@ -694,6 +694,7 @@ answer newbie questions, and generally made Django that much better:
|
||||||
Nis Jørgensen <nis@superlativ.dk>
|
Nis Jørgensen <nis@superlativ.dk>
|
||||||
Nowell Strite <https://nowell.strite.org/>
|
Nowell Strite <https://nowell.strite.org/>
|
||||||
Nuno Mariz <nmariz@gmail.com>
|
Nuno Mariz <nmariz@gmail.com>
|
||||||
|
Octavio Peri <octaperi@gmail.com>
|
||||||
oggie rob <oz.robharvey@gmail.com>
|
oggie rob <oz.robharvey@gmail.com>
|
||||||
oggy <ognjen.maric@gmail.com>
|
oggy <ognjen.maric@gmail.com>
|
||||||
Oliver Beattie <oliver@obeattie.com>
|
Oliver Beattie <oliver@obeattie.com>
|
||||||
|
|
|
@ -143,6 +143,26 @@ class TestLanguageFeed(TestRss2Feed):
|
||||||
language = 'de'
|
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):
|
class NaiveDatesFeed(TestAtomFeed):
|
||||||
"""
|
"""
|
||||||
A feed with naive (non-timezone-aware) dates.
|
A feed with naive (non-timezone-aware) dates.
|
||||||
|
|
|
@ -19,3 +19,8 @@ class Entry(models.Model):
|
||||||
class Article(models.Model):
|
class Article(models.Model):
|
||||||
title = models.CharField(max_length=200)
|
title = models.CharField(max_length=200)
|
||||||
entry = models.ForeignKey(Entry, models.CASCADE)
|
entry = models.ForeignKey(Entry, models.CASCADE)
|
||||||
|
updated = models.DateTimeField()
|
||||||
|
published = models.DateTimeField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ['updated']
|
||||||
|
|
|
@ -38,7 +38,12 @@ class FeedTestCase(TestCase):
|
||||||
title='My last entry', updated=datetime.datetime(2013, 1, 20, 0, 0),
|
title='My last entry', updated=datetime.datetime(2013, 1, 20, 0, 0),
|
||||||
published=datetime.datetime(2013, 3, 25, 20, 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):
|
def assertChildNodes(self, elem, expected):
|
||||||
actual = {n.nodeName for n in elem.childNodes}
|
actual = {n.nodeName for n in elem.childNodes}
|
||||||
|
@ -522,3 +527,22 @@ class SyndicationFeedTest(FeedTestCase):
|
||||||
for prefix in prefix_domain_mapping:
|
for prefix in prefix_domain_mapping:
|
||||||
with self.subTest(prefix=prefix):
|
with self.subTest(prefix=prefix):
|
||||||
self.assertEqual(views.add_domain(*prefix[0]), prefix[1])
|
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)
|
||||||
|
|
|
@ -4,6 +4,7 @@ from . import feeds
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('syndication/rss2/', feeds.TestRss2Feed()),
|
path('syndication/rss2/', feeds.TestRss2Feed()),
|
||||||
|
path('syndication/rss2/articles/<int:entry_id>/', feeds.TestGetObjectFeed()),
|
||||||
path(
|
path(
|
||||||
'syndication/rss2/guid_ispermalink_true/',
|
'syndication/rss2/guid_ispermalink_true/',
|
||||||
feeds.TestRss2FeedWithGuidIsPermaLinkTrue()),
|
feeds.TestRss2FeedWithGuidIsPermaLinkTrue()),
|
||||||
|
|
Loading…
Reference in New Issue