Example #1
0
 def test_rfc2822_date_with_timezone(self):
     """
     Test rfc2822_date() correctly formats datetime objects with tzinfo.
     """
     self.assertEqual(
         feedgenerator.rfc2822_date(datetime.datetime(2008, 11, 14, 13, 37, 0, tzinfo=tzinfo.FixedOffset(datetime.timedelta(minutes=60)))),
         "Fri, 14 Nov 2008 13:37:00 +0100"
     )
Example #2
0
 def test_rfc2822_date_without_time(self):
     """
     Test rfc2822_date() correctly formats date objects.
     """
     self.assertEqual(
         feedgenerator.rfc2822_date(datetime.date(2008, 11, 14)),
         "Fri, 14 Nov 2008 00:00:00 -0000"
     )
Example #3
0
 def test_rfc2822_date(self):
     """
     Test rfc2822_date() correctly formats datetime objects.
     """
     self.assertEqual(
         feedgenerator.rfc2822_date(datetime.datetime(2008, 11, 14, 13, 37, 0)),
         "Fri, 14 Nov 2008 13:37:00 -0000"
     )
Example #4
0
    def test_rss2_feed(self):
        """
        Test the structure and content of feeds generated by Rss201rev2Feed.
        """
        response = self.client.get('/syndication/rss2/')
        doc = minidom.parseString(response.content)

        # Making sure there's only 1 `rss` element and that the correct
        # RSS version was specified.
        feed_elem = doc.getElementsByTagName('rss')
        self.assertEqual(len(feed_elem), 1)
        feed = feed_elem[0]
        self.assertEqual(feed.getAttribute('version'), '2.0')

        # Making sure there's only one `channel` element w/in the
        # `rss` element.
        chan_elem = feed.getElementsByTagName('channel')
        self.assertEqual(len(chan_elem), 1)
        chan = chan_elem[0]

        # Find the last build date
        d = Entry.objects.latest('date').date
        ltz = tzinfo.LocalTimezone(d)
        last_build_date = rfc2822_date(d.replace(tzinfo=ltz))

        self.assertChildNodes(chan, ['title', 'link', 'description', 'language', 'lastBuildDate', 'item', 'atom:link', 'ttl', 'copyright', 'category'])
        self.assertChildNodeContent(chan, {
            'title': 'My blog',
            'description': 'A more thorough description of my blog.',
            'link': 'http://example.com/blog/',
            'language': 'en',
            'lastBuildDate': last_build_date,
            #'atom:link': '',
            'ttl': '600',
            'copyright': 'Copyright (c) 2007, Sally Smith',
        })
        self.assertCategories(chan, ['python', 'django'])

        # Ensure the content of the channel is correct
        self.assertChildNodeContent(chan, {
            'title': 'My blog',
            'link': 'http://example.com/blog/',
        })

        # Check feed_url is passed
        self.assertEqual(
            chan.getElementsByTagName('atom:link')[0].getAttribute('href'),
            'http://example.com/syndication/rss2/'
        )

        # Find the pubdate of the first feed item
        d = Entry.objects.get(pk=1).date
        ltz = tzinfo.LocalTimezone(d)
        pub_date = rfc2822_date(d.replace(tzinfo=ltz))

        items = chan.getElementsByTagName('item')
        self.assertEqual(len(items), Entry.objects.count())
        self.assertChildNodeContent(items[0], {
            'title': 'My first entry',
            'description': 'Overridden description: My first entry',
            'link': 'http://example.com/blog/1/',
            'guid': 'http://example.com/blog/1/',
            'pubDate': pub_date,
            'author': '[email protected] (Sally Smith)',
        })
        self.assertCategories(items[0], ['python', 'testing'])

        for item in items:
            self.assertChildNodes(item, ['title', 'link', 'description', 'guid', 'category', 'pubDate', 'author'])