Ticket #14202: patch2.diff

File patch2.diff, 2.4 KB (added by tmitchell, 5 years ago)

Patch incorporating code and tests, applies cleanly to trunk

  • django/utils/feedgenerator.py

    diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py
    index 5ec20f6..9269d82 100644
    a b class RssFeed(SyndicationFeed): 
    226226        handler.addQuickElement(u"title", self.feed['title'])
    227227        handler.addQuickElement(u"link", self.feed['link'])
    228228        handler.addQuickElement(u"description", self.feed['description'])
    229         handler.addQuickElement(u"atom:link", None, {u"rel": u"self", u"href": self.feed['feed_url']})
     229        if self.feed['feed_url'] is not None:
     230            handler.addQuickElement(u"atom:link", None, {u"rel": u"self",
     231                u"href": self.feed['feed_url']})
    230232        if self.feed['language'] is not None:
    231233            handler.addQuickElement(u"language", self.feed['language'])
    232234        for cat in self.feed['categories']:
  • tests/regressiontests/utils/feedgenerator.py

    diff --git a/tests/regressiontests/utils/feedgenerator.py b/tests/regressiontests/utils/feedgenerator.py
    index c62bd2b..4d5063c 100644
    a b class FeedgeneratorTest(unittest.TestCase): 
    6060            "2008-11-14T13:37:00+02:00"
    6161        )
    6262
     63
     64class Issue14202PatchTest(unittest.TestCase):
     65    """
     66    There is a bug in django.utils.feedgenerator.Rss201rev2Feed that has been
     67    reported in #14202 before.
     68
     69    http://code.djangoproject.com/ticket/14202
     70
     71    The feed_url property is optional but was required later on to write the
     72    atom:link attribute to the RSS-feed.
     73
     74    It is perfectly fine to leave the feed_url property as optional since it
     75    is not required by RSS (http://bit.ly/bAZpKT). Therefore the patch only
     76    renders the atom:link attribute if a feed_url is given.
     77    """
     78
     79    def test_feed_without_feed_url_gets_rendered_without_atom_link(self):
     80        feed = feedgenerator.Rss201rev2Feed('title', '/link/', 'descr')
     81        feed_content = feed.writeString('utf-8')
     82
     83        self.assertEquals(feed.feed['feed_url'], None)
     84        self.assertFalse('<atom:link href=' in feed_content)
     85
     86    def test_feed_with_feed_url_gets_rendered_with_atom_link(self):
     87        feed = feedgenerator.Rss201rev2Feed('title', '/link/', 'descr', feed_url='/feed/')
     88        feed_content = feed.writeString('utf-8')
     89
     90        self.assertEquals(feed.feed['feed_url'], '/feed/')
     91        self.assertTrue('<atom:link href="/feed/" rel="self"></atom:link>' in \
     92            feed_content)
     93
Back to Top