'Test the structure and content of feeds generated by Rss201rev2Feed.'

def test_rss2_feed(self):

    response = self.client.get(u'/syndication/rss2/')
    doc = minidom.parseString(response.content)
    feed_elem = doc.getElementsByTagName(u'rss')
    self.assertEqual(len(feed_elem), 1)
    feed = feed_elem[0]
    self.assertEqual(feed.getAttribute(u'version'), u'2.0')
    chan_elem = feed.getElementsByTagName(u'channel')
    self.assertEqual(len(chan_elem), 1)
    chan = chan_elem[0]
    d = Entry.objects.latest(u'date').date
    ltz = tzinfo.LocalTimezone(d)
    last_build_date = rfc2822_date(d.replace(tzinfo=ltz))
    self.assertChildNodes(chan, [u'title', u'link', u'description', u'language', u'lastBuildDate', u'item', u'atom:link', u'ttl', u'copyright', u'category'])
    self.assertChildNodeContent(chan, {u'title': u'My    blog', u'description': u'A    more    thorough    description    of    my    blog.', u'link': u'http://example.com/blog/', u'language': u'en', u'lastBuildDate': last_build_date, u'ttl': u'600', u'copyright': u'Copyright    (c)    2007,    Sally    Smith'})
    self.assertCategories(chan, [u'python', u'django'])
    self.assertChildNodeContent(chan, {u'title': u'My    blog', u'link': u'http://example.com/blog/'})
    self.assertEqual(chan.getElementsByTagName(u'atom:link')[0].getAttribute(u'href'), u'http://example.com/syndication/rss2/')
    d = Entry.objects.get(pk=1).date
    ltz = tzinfo.LocalTimezone(d)
    pub_date = rfc2822_date(d.replace(tzinfo=ltz))
    items = chan.getElementsByTagName(u'item')
    self.assertEqual(len(items), Entry.objects.count())
    self.assertChildNodeContent(items[0], {u'title': u'My    first    entry', u'description': u'Overridden    description:    My    first    entry', u'link': u'http://example.com/blog/1/', u'guid': u'http://example.com/blog/1/', u'pubDate': pub_date, u'author': u'test@example.com    (Sally    Smith)'})
    self.assertCategories(items[0], [u'python', u'testing'])
    for item in items:
        self.assertChildNodes(item, [u'title', u'link', u'description', u'guid', u'category', u'pubDate', u'author'])
        self.assertIsNone(item.getElementsByTagName(u'guid')[0].attributes.get(u'isPermaLink'))
