1 from __future__
import absolute_import
3 from django
.contrib
.syndication
import views
4 from django
.core
.exceptions
import ObjectDoesNotExist
5 from django
.utils
import feedgenerator
, tzinfo
7 from .models
import Article
, Entry
10 class ComplexFeed(views
.Feed
):
11 def get_object(self
, request
, foo
=None):
13 raise ObjectDoesNotExist
17 class TestRss2Feed(views
.Feed
):
19 description
= 'A more thorough description of my blog.'
21 feed_guid
= '/foo/bar/1234'
22 author_name
= 'Sally Smith'
23 author_email
= 'test@example.com'
24 author_link
= 'http://www.example.com/'
25 categories
= ('python', 'django')
26 feed_copyright
= 'Copyright (c) 2007, Sally Smith'
30 return Entry
.objects
.all()
32 def item_description(self
, item
):
33 return "Overridden description: %s" % item
35 def item_pubdate(self
, item
):
38 item_author_name
= 'Sally Smith'
39 item_author_email
= 'test@example.com'
40 item_author_link
= 'http://www.example.com/'
41 item_categories
= ('python', 'testing')
42 item_copyright
= 'Copyright (c) 2007, Sally Smith'
45 class TestRss091Feed(TestRss2Feed
):
46 feed_type
= feedgenerator
.RssUserland091Feed
49 class TestAtomFeed(TestRss2Feed
):
50 feed_type
= feedgenerator
.Atom1Feed
51 subtitle
= TestRss2Feed
.description
54 class ArticlesFeed(TestRss2Feed
):
56 A feed to test no link being defined. Articles have no get_absolute_url()
57 method, and item_link() is not defined.
60 return Article
.objects
.all()
63 class TestEnclosureFeed(TestRss2Feed
):
67 class TemplateFeed(TestRss2Feed
):
69 A feed to test defining item titles and descriptions with templates.
71 title_template
= 'syndication/title.html'
72 description_template
= 'syndication/description.html'
74 # Defining a template overrides any item_title definition
76 return "Not in a template"
79 class NaiveDatesFeed(TestAtomFeed
):
81 A feed with naive (non-timezone-aware) dates.
83 def item_pubdate(self
, item
):
87 class TZAwareDatesFeed(TestAtomFeed
):
89 A feed with timezone-aware dates.
91 def item_pubdate(self
, item
):
92 # Provide a weird offset so that the test can know it's getting this
93 # specific offset and not accidentally getting on from
95 return item
.date
.replace(tzinfo
=tzinfo
.FixedOffset(42))
98 class TestFeedUrlFeed(TestAtomFeed
):
99 feed_url
= 'http://example.com/customfeedurl/'
102 class MyCustomAtom1Feed(feedgenerator
.Atom1Feed
):
104 Test of a custom feed generator class.
106 def root_attributes(self
):
107 attrs
= super(MyCustomAtom1Feed
, self
).root_attributes()
108 attrs
[u
'django'] = u
'rocks'
111 def add_root_elements(self
, handler
):
112 super(MyCustomAtom1Feed
, self
).add_root_elements(handler
)
113 handler
.addQuickElement(u
'spam', u
'eggs')
115 def item_attributes(self
, item
):
116 attrs
= super(MyCustomAtom1Feed
, self
).item_attributes(item
)
117 attrs
[u
'bacon'] = u
'yum'
120 def add_item_elements(self
, handler
, item
):
121 super(MyCustomAtom1Feed
, self
).add_item_elements(handler
, item
)
122 handler
.addQuickElement(u
'ministry', u
'silly walks')
125 class TestCustomFeed(TestAtomFeed
):
126 feed_type
= MyCustomAtom1Feed