Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a couple of extra syndication tests, and generally sanitized th…

…e existing ones. Refs #6547.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8310 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 899ca54fe2a289bee4dfbed9f5ef6fc9024def72 1 parent efaa891
Jacob Kaplan-Moss jacobian authored
2  django/contrib/syndication/feeds.py
View
@@ -81,7 +81,7 @@ def get_feed(self, url=None):
current_site = Site.objects.get_current()
else:
current_site = RequestSite(self.request)
-
+
link = self.__get_dynamic_attr('link', obj)
link = add_domain(current_site.domain, link)
23 tests/regressiontests/syndication/feeds.py
View
@@ -0,0 +1,23 @@
+from django.core.exceptions import ObjectDoesNotExist
+from django.contrib.syndication import feeds
+from django.utils.feedgenerator import Atom1Feed
+
+class ComplexFeed(feeds.Feed):
+ def get_object(self, bits):
+ if len(bits) != 1:
+ raise ObjectDoesNotExist
+ return None
+
+class TestRssFeed(feeds.Feed):
+ link = "/blog/"
+ title = 'My blog'
+
+ def items(self):
+ from models import Entry
+ return Entry.objects.all()
+
+ def item_link(self, item):
+ return "/blog/%s/" % item.pk
+
+class TestAtomFeed(TestRssFeed):
+ feed_type = Atom1Feed
26 tests/regressiontests/syndication/fixtures/feeddata.json
View
@@ -0,0 +1,26 @@
+[
+ {
+ "model": "syndication.entry",
+ "pk": 1,
+ "fields": {
+ "title": "My first entry",
+ "date": "2008-01-01 12:30:00"
+ }
+ },
+ {
+ "model": "syndication.entry",
+ "pk": 2,
+ "fields": {
+ "title": "My second entry",
+ "date": "2008-01-02 12:30:00"
+ }
+ },
+ {
+ "model": "syndication.entry",
+ "pk": 3,
+ "fields": {
+ "title": "My third entry",
+ "date": "2008-01-02 13:30:00"
+ }
+ }
+]
8 tests/regressiontests/syndication/models.py
View
@@ -0,0 +1,8 @@
+from django.db import models
+
+class Entry(models.Model):
+ title = models.CharField(max_length=200)
+ date = models.DateTimeField()
+
+ def __unicode__(self):
+ return self.title
21 tests/regressiontests/syndication/tests.py
View
@@ -1,14 +1,31 @@
# -*- coding: utf-8 -*-
+from xml.dom import minidom
from django.test import TestCase
from django.test.client import Client
+from models import Entry
class SyndicationFeedTest(TestCase):
+ fixtures = ['feeddata.json']
+
+ 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())
+
+ 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())
+
def test_complex_base_url(self):
"""
Tests that that the base url for a complex feed doesn't raise a 500
exception.
"""
- c = Client()
- response = c.get('/syndication/feeds/complex/')
+ response = self.client.get('/syndication/feeds/complex/')
self.assertEquals(response.status_code, 404)
+
+
22 tests/regressiontests/syndication/urls.py
View
@@ -1,18 +1,12 @@
+from feeds import TestRssFeed, TestAtomFeed, ComplexFeed
from django.conf.urls.defaults import patterns
-from django.core.exceptions import ObjectDoesNotExist
-from django.contrib.syndication import feeds
-
-
-class ComplexFeed(feeds.Feed):
- def get_object(self, bits):
- if len(bits) != 1:
- raise ObjectDoesNotExist
- return None
-
+feed_dict = {
+ 'complex': ComplexFeed,
+ 'rss': TestRssFeed,
+ 'atom': TestAtomFeed,
+
+}
urlpatterns = patterns('',
- (r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {
- 'feed_dict': dict(
- complex = ComplexFeed,
- )}),
+ (r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict': feed_dict})
)
Please sign in to comment.
Something went wrong with that request. Please try again.