From 76c6d65662b3ace72c44b7b7fd6f6d58889189e3 Mon Sep 17 00:00:00 2001 From: mtredinnick Date: Thu, 20 Mar 2008 06:35:53 +0000 Subject: [PATCH] Merged the tests and documentation from #4720 to support the changes in [7295]. Thanks, Andy Gayton. Fixed #4720. Refs #5855. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7328 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/syndication_feeds.txt | 7 +++++++ tests/regressiontests/syndication/__init__.py | 0 tests/regressiontests/syndication/tests.py | 14 ++++++++++++++ tests/regressiontests/syndication/urls.py | 18 ++++++++++++++++++ tests/urls.py | 3 +++ 5 files changed, 42 insertions(+) create mode 100644 tests/regressiontests/syndication/__init__.py create mode 100644 tests/regressiontests/syndication/tests.py create mode 100644 tests/regressiontests/syndication/urls.py diff --git a/docs/syndication_feeds.txt b/docs/syndication_feeds.txt index ebd6af26..f86acfe5 100644 --- a/docs/syndication_feeds.txt +++ b/docs/syndication_feeds.txt @@ -245,6 +245,13 @@ request to the URL ``/rss/beats/0613/``: subclass of ``ObjectDoesNotExist``. Raising ``ObjectDoesNotExist`` in ``get_object()`` tells Django to produce a 404 error for that request. + **New in Django development version:** The ``get_object()`` method also + has a chance to handle the ``/rss/beats/`` url. In this case, ``bits`` + will be an empty list. In our example, ``len(bits) != 1`` and an + ``ObjectDoesNotExist`` exception will be raised, so ``/rss/beats/`` will + generate a 404 page. But you can handle this case however you like. For + example you could generate a combined feed for all beats. + * To generate the feed's ````, ``<link>`` and ``<description>``, Django uses the ``title()``, ``link()`` and ``description()`` methods. In the previous example, they were simple string class attributes, but this diff --git a/tests/regressiontests/syndication/__init__.py b/tests/regressiontests/syndication/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/regressiontests/syndication/tests.py b/tests/regressiontests/syndication/tests.py new file mode 100644 index 00000000..6a9dd643 --- /dev/null +++ b/tests/regressiontests/syndication/tests.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- + +from django.test import TestCase +from django.test.client import Client + +class SyndicationFeedTest(TestCase): + 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/') + self.assertEquals(response.status_code, 404) diff --git a/tests/regressiontests/syndication/urls.py b/tests/regressiontests/syndication/urls.py new file mode 100644 index 00000000..24644ffd --- /dev/null +++ b/tests/regressiontests/syndication/urls.py @@ -0,0 +1,18 @@ +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 + + +urlpatterns = patterns('', + (r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', { + 'feed_dict': dict( + complex = ComplexFeed, + )}), +) diff --git a/tests/urls.py b/tests/urls.py index 41b4aaf6..dbdf9a80 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -19,4 +19,7 @@ urlpatterns = patterns('', (r'^middleware/', include('regressiontests.middleware.urls')), (r'^utils/', include('regressiontests.utils.urls')), + + # test urlconf for syndication tests + (r'^syndication/', include('regressiontests.syndication.urls')), ) -- 2.11.4.GIT