summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorZbigniew Siciarz <antyqjon@gmail.com>2013-02-24 15:00:34 +0100
committerJacob Kaplan-Moss <jacob@jacobian.org>2013-02-24 08:33:20 -0600
commit0a8402eb052a5c35085baa5408aaf4ee36ebc0a6 (patch)
treeda243369985c25bd5b0a34e17560c81036317e16 /tests
parent4506ae0497d388f8bc118b9f6f916a5da48d599a (diff)
Test case and docs for custom context data in feeds
Thanks Paul Winkler for the initial patch. (Ref #18112).
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/syndication/feeds.py13
-rw-r--r--tests/regressiontests/syndication/templates/syndication/description_context.html1
-rw-r--r--tests/regressiontests/syndication/templates/syndication/title_context.html1
-rw-r--r--tests/regressiontests/syndication/tests.py16
-rw-r--r--tests/regressiontests/syndication/urls.py1
5 files changed, 32 insertions, 0 deletions
diff --git a/tests/regressiontests/syndication/feeds.py b/tests/regressiontests/syndication/feeds.py
index 25757057b9..0956820bf0 100644
--- a/tests/regressiontests/syndication/feeds.py
+++ b/tests/regressiontests/syndication/feeds.py
@@ -97,6 +97,19 @@ class TemplateFeed(TestRss2Feed):
return "Not in a template"
+class TemplateContextFeed(TestRss2Feed):
+ """
+ A feed to test custom context data in templates for title or description.
+ """
+ title_template = 'syndication/title_context.html'
+ description_template = 'syndication/description_context.html'
+
+ def get_context_data(self, **kwargs):
+ context = super(TemplateContextFeed, self).get_context_data(**kwargs)
+ context['foo'] = 'bar'
+ return context
+
+
class NaiveDatesFeed(TestAtomFeed):
"""
A feed with naive (non-timezone-aware) dates.
diff --git a/tests/regressiontests/syndication/templates/syndication/description_context.html b/tests/regressiontests/syndication/templates/syndication/description_context.html
new file mode 100644
index 0000000000..319d84b1b0
--- /dev/null
+++ b/tests/regressiontests/syndication/templates/syndication/description_context.html
@@ -0,0 +1 @@
+{{ obj }} (foo is {{ foo }}) \ No newline at end of file
diff --git a/tests/regressiontests/syndication/templates/syndication/title_context.html b/tests/regressiontests/syndication/templates/syndication/title_context.html
new file mode 100644
index 0000000000..319d84b1b0
--- /dev/null
+++ b/tests/regressiontests/syndication/templates/syndication/title_context.html
@@ -0,0 +1 @@
+{{ obj }} (foo is {{ foo }}) \ No newline at end of file
diff --git a/tests/regressiontests/syndication/tests.py b/tests/regressiontests/syndication/tests.py
index 8885dc28c0..e8fc6be420 100644
--- a/tests/regressiontests/syndication/tests.py
+++ b/tests/regressiontests/syndication/tests.py
@@ -323,6 +323,22 @@ class SyndicationFeedTest(FeedTestCase):
'link': 'http://example.com/blog/1/',
})
+ def test_template_context_feed(self):
+ """
+ Test that custom context data can be passed to templates for title
+ and description.
+ """
+ response = self.client.get('/syndication/template_context/')
+ doc = minidom.parseString(response.content)
+ feed = doc.getElementsByTagName('rss')[0]
+ chan = feed.getElementsByTagName('channel')[0]
+ items = chan.getElementsByTagName('item')
+
+ self.assertChildNodeContent(items[0], {
+ 'title': 'My first entry (foo is bar)',
+ 'description': 'My first entry (foo is bar)',
+ })
+
def test_add_domain(self):
"""
Test add_domain() prefixes domains onto the correct URLs.
diff --git a/tests/regressiontests/syndication/urls.py b/tests/regressiontests/syndication/urls.py
index ec3c8cc596..1dd7e92332 100644
--- a/tests/regressiontests/syndication/urls.py
+++ b/tests/regressiontests/syndication/urls.py
@@ -21,4 +21,5 @@ urlpatterns = patterns('django.contrib.syndication.views',
(r'^syndication/feedurl/$', feeds.TestFeedUrlFeed()),
(r'^syndication/articles/$', feeds.ArticlesFeed()),
(r'^syndication/template/$', feeds.TemplateFeed()),
+ (r'^syndication/template_context/$', feeds.TemplateContextFeed()),
)