App Engine Python SDK version 1.7.4 (2)
[gae.git] / python / lib / django_1_4 / tests / regressiontests / syndication / feeds.py
blob41feb895500eebfe32b085a40288b02b34f3a8f9
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):
12 if foo is not None:
13 raise ObjectDoesNotExist
14 return None
17 class TestRss2Feed(views.Feed):
18 title = 'My blog'
19 description = 'A more thorough description of my blog.'
20 link = '/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'
27 ttl = 600
29 def items(self):
30 return Entry.objects.all()
32 def item_description(self, item):
33 return "Overridden description: %s" % item
35 def item_pubdate(self, item):
36 return item.date
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):
55 """
56 A feed to test no link being defined. Articles have no get_absolute_url()
57 method, and item_link() is not defined.
58 """
59 def items(self):
60 return Article.objects.all()
63 class TestEnclosureFeed(TestRss2Feed):
64 pass
67 class TemplateFeed(TestRss2Feed):
68 """
69 A feed to test defining item titles and descriptions with templates.
70 """
71 title_template = 'syndication/title.html'
72 description_template = 'syndication/description.html'
74 # Defining a template overrides any item_title definition
75 def item_title(self):
76 return "Not in a template"
79 class NaiveDatesFeed(TestAtomFeed):
80 """
81 A feed with naive (non-timezone-aware) dates.
82 """
83 def item_pubdate(self, item):
84 return item.date
87 class TZAwareDatesFeed(TestAtomFeed):
88 """
89 A feed with timezone-aware dates.
90 """
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
94 # settings.TIME_ZONE.
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'
109 return attrs
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'
118 return attrs
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