diff options
Diffstat (limited to 'tests/regressiontests/syndication')
| -rw-r--r-- | tests/regressiontests/syndication/feeds.py | 25 | ||||
| -rw-r--r-- | tests/regressiontests/syndication/tests.py | 48 | ||||
| -rw-r--r-- | tests/regressiontests/syndication/urls.py | 3 |
3 files changed, 72 insertions, 4 deletions
diff --git a/tests/regressiontests/syndication/feeds.py b/tests/regressiontests/syndication/feeds.py index 3c5d5a51b5..eabc1f94a8 100644 --- a/tests/regressiontests/syndication/feeds.py +++ b/tests/regressiontests/syndication/feeds.py @@ -21,3 +21,28 @@ class TestRssFeed(feeds.Feed): class TestAtomFeed(TestRssFeed): feed_type = Atom1Feed + +class MyCustomAtom1Feed(Atom1Feed): + """ + Test of a custom feed generator class. + """ + def root_attributes(self): + attrs = super(MyCustomAtom1Feed, self).root_attributes() + attrs[u'django'] = u'rocks' + return attrs + + def add_root_elements(self, handler): + super(MyCustomAtom1Feed, self).add_root_elements(handler) + handler.addQuickElement(u'spam', u'eggs') + + def item_attributes(self, item): + attrs = super(MyCustomAtom1Feed, self).item_attributes(item) + attrs[u'bacon'] = u'yum' + return attrs + + def add_item_elements(self, handler, item): + super(MyCustomAtom1Feed, self).add_item_elements(handler, item) + handler.addQuickElement(u'ministry', u'silly walks') + +class TestCustomFeed(TestAtomFeed): + feed_type = MyCustomAtom1Feed diff --git a/tests/regressiontests/syndication/tests.py b/tests/regressiontests/syndication/tests.py index 142cf47d03..0938f69e5b 100644 --- a/tests/regressiontests/syndication/tests.py +++ b/tests/regressiontests/syndication/tests.py @@ -4,22 +4,64 @@ from xml.dom import minidom from django.test import TestCase from django.test.client import Client from models import Entry +try: + set +except NameError: + from sets import Set as set class SyndicationFeedTest(TestCase): fixtures = ['feeddata.json'] + def assertChildNodes(self, elem, expected): + actual = set([n.nodeName for n in elem.childNodes]) + expected = set(expected) + self.assertEqual(actual, expected) + def test_rss_feed(self): response = self.client.get('/syndication/feeds/rss/') doc = minidom.parseString(response.content) self.assertEqual(len(doc.getElementsByTagName('channel')), 1) - self.assertEqual(len(doc.getElementsByTagName('item')), Entry.objects.count()) + + chan = doc.getElementsByTagName('channel')[0] + self.assertChildNodes(chan, ['title', 'link', 'description', 'language', 'lastBuildDate', 'item']) + + items = chan.getElementsByTagName('item') + self.assertEqual(len(items), Entry.objects.count()) + for item in items: + self.assertChildNodes(item, ['title', 'link', 'description', 'guid']) def test_atom_feed(self): response = self.client.get('/syndication/feeds/atom/') doc = minidom.parseString(response.content) - self.assertEqual(len(doc.getElementsByTagName('feed')), 1) - self.assertEqual(len(doc.getElementsByTagName('entry')), Entry.objects.count()) + + feed = doc.firstChild + self.assertEqual(feed.nodeName, 'feed') + self.assertChildNodes(feed, ['title', 'link', 'id', 'updated', 'entry']) + + entries = feed.getElementsByTagName('entry') + self.assertEqual(len(entries), Entry.objects.count()) + for entry in entries: + self.assertChildNodes(entry, ['title', 'link', 'id', 'summary']) + summary = entry.getElementsByTagName('summary')[0] + self.assertEqual(summary.getAttribute('type'), 'html') + def test_custom_feed_generator(self): + response = self.client.get('/syndication/feeds/custom/') + doc = minidom.parseString(response.content) + + feed = doc.firstChild + self.assertEqual(feed.nodeName, 'feed') + self.assertEqual(feed.getAttribute('django'), 'rocks') + self.assertChildNodes(feed, ['title', 'link', 'id', 'updated', 'entry', 'spam']) + + entries = feed.getElementsByTagName('entry') + self.assertEqual(len(entries), Entry.objects.count()) + for entry in entries: + self.assertEqual(entry.getAttribute('bacon'), 'yum') + self.assertChildNodes(entry, ['title', 'link', 'id', 'summary', 'ministry']) + summary = entry.getElementsByTagName('summary')[0] + self.assertEqual(summary.getAttribute('type'), 'html') + def test_complex_base_url(self): """ Tests that that the base url for a complex feed doesn't raise a 500 diff --git a/tests/regressiontests/syndication/urls.py b/tests/regressiontests/syndication/urls.py index ce3b5056ba..f37222d9b5 100644 --- a/tests/regressiontests/syndication/urls.py +++ b/tests/regressiontests/syndication/urls.py @@ -1,10 +1,11 @@ -from feeds import TestRssFeed, TestAtomFeed, ComplexFeed +from feeds import TestRssFeed, TestAtomFeed, TestCustomFeed, ComplexFeed from django.conf.urls.defaults import patterns feed_dict = { 'complex': ComplexFeed, 'rss': TestRssFeed, 'atom': TestAtomFeed, + 'custom': TestCustomFeed, } urlpatterns = patterns('', |
