mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
committed by
Mariusz Felisiak
parent
f68fa8b45d
commit
9c19aff7c7
@@ -6,15 +6,15 @@ from .models import Article, Entry
|
||||
|
||||
|
||||
class TestRss2Feed(views.Feed):
|
||||
title = 'My blog'
|
||||
description = 'A more thorough description of my blog.'
|
||||
link = '/blog/'
|
||||
feed_guid = '/foo/bar/1234'
|
||||
author_name = 'Sally Smith'
|
||||
author_email = 'test@example.com'
|
||||
author_link = 'http://www.example.com/'
|
||||
categories = ('python', 'django')
|
||||
feed_copyright = 'Copyright (c) 2007, Sally Smith'
|
||||
title = "My blog"
|
||||
description = "A more thorough description of my blog."
|
||||
link = "/blog/"
|
||||
feed_guid = "/foo/bar/1234"
|
||||
author_name = "Sally Smith"
|
||||
author_email = "test@example.com"
|
||||
author_link = "http://www.example.com/"
|
||||
categories = ("python", "django")
|
||||
feed_copyright = "Copyright (c) 2007, Sally Smith"
|
||||
ttl = 600
|
||||
|
||||
def items(self):
|
||||
@@ -32,11 +32,11 @@ class TestRss2Feed(views.Feed):
|
||||
def item_comments(self, item):
|
||||
return "%scomments" % item.get_absolute_url()
|
||||
|
||||
item_author_name = 'Sally Smith'
|
||||
item_author_email = 'test@example.com'
|
||||
item_author_link = 'http://www.example.com/'
|
||||
item_categories = ('python', 'testing')
|
||||
item_copyright = 'Copyright (c) 2007, Sally Smith'
|
||||
item_author_name = "Sally Smith"
|
||||
item_author_email = "test@example.com"
|
||||
item_author_link = "http://www.example.com/"
|
||||
item_categories = ("python", "testing")
|
||||
item_copyright = "Copyright (c) 2007, Sally Smith"
|
||||
|
||||
|
||||
class TestRss2FeedWithGuidIsPermaLinkTrue(TestRss2Feed):
|
||||
@@ -57,8 +57,8 @@ class TestRss091Feed(TestRss2Feed):
|
||||
|
||||
|
||||
class TestNoPubdateFeed(views.Feed):
|
||||
title = 'Test feed'
|
||||
link = '/feed/'
|
||||
title = "Test feed"
|
||||
link = "/feed/"
|
||||
|
||||
def items(self):
|
||||
return Entry.objects.all()
|
||||
@@ -73,11 +73,12 @@ class TestLatestFeed(TestRss2Feed):
|
||||
"""
|
||||
A feed where the latest entry date is an `updated` element.
|
||||
"""
|
||||
|
||||
feed_type = feedgenerator.Atom1Feed
|
||||
subtitle = TestRss2Feed.description
|
||||
|
||||
def items(self):
|
||||
return Entry.objects.exclude(title='My last entry')
|
||||
return Entry.objects.exclude(title="My last entry")
|
||||
|
||||
|
||||
class ArticlesFeed(TestRss2Feed):
|
||||
@@ -85,6 +86,7 @@ class ArticlesFeed(TestRss2Feed):
|
||||
A feed to test no link being defined. Articles have no get_absolute_url()
|
||||
method, and item_link() is not defined.
|
||||
"""
|
||||
|
||||
def items(self):
|
||||
return Article.objects.all()
|
||||
|
||||
@@ -93,24 +95,26 @@ class TestSingleEnclosureRSSFeed(TestRss2Feed):
|
||||
"""
|
||||
A feed to test that RSS feeds work with a single enclosure.
|
||||
"""
|
||||
|
||||
def item_enclosure_url(self, item):
|
||||
return 'http://example.com'
|
||||
return "http://example.com"
|
||||
|
||||
def item_enclosure_size(self, item):
|
||||
return 0
|
||||
|
||||
def item_mime_type(self, item):
|
||||
return 'image/png'
|
||||
return "image/png"
|
||||
|
||||
|
||||
class TestMultipleEnclosureRSSFeed(TestRss2Feed):
|
||||
"""
|
||||
A feed to test that RSS feeds raise an exception with multiple enclosures.
|
||||
"""
|
||||
|
||||
def item_enclosures(self, item):
|
||||
return [
|
||||
feedgenerator.Enclosure('http://example.com/hello.png', 0, 'image/png'),
|
||||
feedgenerator.Enclosure('http://example.com/goodbye.png', 0, 'image/png'),
|
||||
feedgenerator.Enclosure("http://example.com/hello.png", 0, "image/png"),
|
||||
feedgenerator.Enclosure("http://example.com/goodbye.png", 0, "image/png"),
|
||||
]
|
||||
|
||||
|
||||
@@ -118,8 +122,9 @@ class TemplateFeed(TestRss2Feed):
|
||||
"""
|
||||
A feed to test defining item titles and descriptions with templates.
|
||||
"""
|
||||
title_template = 'syndication/title.html'
|
||||
description_template = 'syndication/description.html'
|
||||
|
||||
title_template = "syndication/title.html"
|
||||
description_template = "syndication/description.html"
|
||||
|
||||
# Defining a template overrides any item_title definition
|
||||
def item_title(self):
|
||||
@@ -130,17 +135,18 @@ 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'
|
||||
|
||||
title_template = "syndication/title_context.html"
|
||||
description_template = "syndication/description_context.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['foo'] = 'bar'
|
||||
context["foo"] = "bar"
|
||||
return context
|
||||
|
||||
|
||||
class TestLanguageFeed(TestRss2Feed):
|
||||
language = 'de'
|
||||
language = "de"
|
||||
|
||||
|
||||
class TestGetObjectFeed(TestRss2Feed):
|
||||
@@ -151,22 +157,23 @@ class TestGetObjectFeed(TestRss2Feed):
|
||||
return Article.objects.filter(entry=obj)
|
||||
|
||||
def item_link(self, item):
|
||||
return '%sarticle/%s/' % (item.entry.get_absolute_url(), item.pk)
|
||||
return "%sarticle/%s/" % (item.entry.get_absolute_url(), item.pk)
|
||||
|
||||
def item_comments(self, item):
|
||||
return '%scomments' % self.item_link(item)
|
||||
return "%scomments" % self.item_link(item)
|
||||
|
||||
def item_description(self, item):
|
||||
return 'Article description: %s' % item.title
|
||||
return "Article description: %s" % item.title
|
||||
|
||||
def item_title(self, item):
|
||||
return 'Title: %s' % item.title
|
||||
return "Title: %s" % item.title
|
||||
|
||||
|
||||
class NaiveDatesFeed(TestAtomFeed):
|
||||
"""
|
||||
A feed with naive (non-timezone-aware) dates.
|
||||
"""
|
||||
|
||||
def item_pubdate(self, item):
|
||||
return item.published
|
||||
|
||||
@@ -175,6 +182,7 @@ class TZAwareDatesFeed(TestAtomFeed):
|
||||
"""
|
||||
A feed with timezone-aware dates.
|
||||
"""
|
||||
|
||||
def item_pubdate(self, item):
|
||||
# Provide a weird offset so that the test can know it's getting this
|
||||
# specific offset and not accidentally getting on from
|
||||
@@ -183,30 +191,31 @@ class TZAwareDatesFeed(TestAtomFeed):
|
||||
|
||||
|
||||
class TestFeedUrlFeed(TestAtomFeed):
|
||||
feed_url = 'http://example.com/customfeedurl/'
|
||||
feed_url = "http://example.com/customfeedurl/"
|
||||
|
||||
|
||||
class MyCustomAtom1Feed(feedgenerator.Atom1Feed):
|
||||
"""
|
||||
Test of a custom feed generator class.
|
||||
"""
|
||||
|
||||
def root_attributes(self):
|
||||
attrs = super().root_attributes()
|
||||
attrs['django'] = 'rocks'
|
||||
attrs["django"] = "rocks"
|
||||
return attrs
|
||||
|
||||
def add_root_elements(self, handler):
|
||||
super().add_root_elements(handler)
|
||||
handler.addQuickElement('spam', 'eggs')
|
||||
handler.addQuickElement("spam", "eggs")
|
||||
|
||||
def item_attributes(self, item):
|
||||
attrs = super().item_attributes(item)
|
||||
attrs['bacon'] = 'yum'
|
||||
attrs["bacon"] = "yum"
|
||||
return attrs
|
||||
|
||||
def add_item_elements(self, handler, item):
|
||||
super().add_item_elements(handler, item)
|
||||
handler.addQuickElement('ministry', 'silly walks')
|
||||
handler.addQuickElement("ministry", "silly walks")
|
||||
|
||||
|
||||
class TestCustomFeed(TestAtomFeed):
|
||||
@@ -217,22 +226,24 @@ class TestSingleEnclosureAtomFeed(TestAtomFeed):
|
||||
"""
|
||||
A feed to test that Atom feeds work with a single enclosure.
|
||||
"""
|
||||
|
||||
def item_enclosure_url(self, item):
|
||||
return 'http://example.com'
|
||||
return "http://example.com"
|
||||
|
||||
def item_enclosure_size(self, item):
|
||||
return 0
|
||||
|
||||
def item_mime_type(self, item):
|
||||
return 'image/png'
|
||||
return "image/png"
|
||||
|
||||
|
||||
class TestMultipleEnclosureAtomFeed(TestAtomFeed):
|
||||
"""
|
||||
A feed to test that Atom feeds work with multiple enclosures.
|
||||
"""
|
||||
|
||||
def item_enclosures(self, item):
|
||||
return [
|
||||
feedgenerator.Enclosure('http://example.com/hello.png', '0', 'image/png'),
|
||||
feedgenerator.Enclosure('http://example.com/goodbye.png', '0', 'image/png'),
|
||||
feedgenerator.Enclosure("http://example.com/hello.png", "0", "image/png"),
|
||||
feedgenerator.Enclosure("http://example.com/goodbye.png", "0", "image/png"),
|
||||
]
|
||||
|
||||
@@ -7,7 +7,7 @@ class Entry(models.Model):
|
||||
published = models.DateTimeField()
|
||||
|
||||
class Meta:
|
||||
ordering = ('updated',)
|
||||
ordering = ("updated",)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
@@ -23,4 +23,4 @@ class Article(models.Model):
|
||||
published = models.DateTimeField()
|
||||
|
||||
class Meta:
|
||||
ordering = ['updated']
|
||||
ordering = ["updated"]
|
||||
|
||||
@@ -8,7 +8,10 @@ from django.test import TestCase, override_settings
|
||||
from django.test.utils import requires_tz_support
|
||||
from django.utils import timezone
|
||||
from django.utils.feedgenerator import (
|
||||
Atom1Feed, Rss201rev2Feed, rfc2822_date, rfc3339_date,
|
||||
Atom1Feed,
|
||||
Rss201rev2Feed,
|
||||
rfc2822_date,
|
||||
rfc3339_date,
|
||||
)
|
||||
|
||||
from .models import Article, Entry
|
||||
@@ -17,31 +20,35 @@ TZ = timezone.get_default_timezone()
|
||||
|
||||
|
||||
class FeedTestCase(TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.e1 = Entry.objects.create(
|
||||
title='My first entry', updated=datetime.datetime(1980, 1, 1, 12, 30),
|
||||
published=datetime.datetime(1986, 9, 25, 20, 15, 00)
|
||||
title="My first entry",
|
||||
updated=datetime.datetime(1980, 1, 1, 12, 30),
|
||||
published=datetime.datetime(1986, 9, 25, 20, 15, 00),
|
||||
)
|
||||
cls.e2 = Entry.objects.create(
|
||||
title='My second entry', updated=datetime.datetime(2008, 1, 2, 12, 30),
|
||||
published=datetime.datetime(2006, 3, 17, 18, 0)
|
||||
title="My second entry",
|
||||
updated=datetime.datetime(2008, 1, 2, 12, 30),
|
||||
published=datetime.datetime(2006, 3, 17, 18, 0),
|
||||
)
|
||||
cls.e3 = Entry.objects.create(
|
||||
title='My third entry', updated=datetime.datetime(2008, 1, 2, 13, 30),
|
||||
published=datetime.datetime(2005, 6, 14, 10, 45)
|
||||
title="My third entry",
|
||||
updated=datetime.datetime(2008, 1, 2, 13, 30),
|
||||
published=datetime.datetime(2005, 6, 14, 10, 45),
|
||||
)
|
||||
cls.e4 = Entry.objects.create(
|
||||
title='A & B < C > D', updated=datetime.datetime(2008, 1, 3, 13, 30),
|
||||
published=datetime.datetime(2005, 11, 25, 12, 11, 23)
|
||||
title="A & B < C > D",
|
||||
updated=datetime.datetime(2008, 1, 3, 13, 30),
|
||||
published=datetime.datetime(2005, 11, 25, 12, 11, 23),
|
||||
)
|
||||
cls.e5 = Entry.objects.create(
|
||||
title='My last entry', updated=datetime.datetime(2013, 1, 20, 0, 0),
|
||||
published=datetime.datetime(2013, 3, 25, 20, 0)
|
||||
title="My last entry",
|
||||
updated=datetime.datetime(2013, 1, 20, 0, 0),
|
||||
published=datetime.datetime(2013, 3, 25, 20, 0),
|
||||
)
|
||||
cls.a1 = Article.objects.create(
|
||||
title='My first article',
|
||||
title="My first article",
|
||||
entry=cls.e1,
|
||||
updated=datetime.datetime(1986, 11, 21, 9, 12, 18),
|
||||
published=datetime.datetime(1986, 10, 21, 9, 12, 18),
|
||||
@@ -54,21 +61,25 @@ class FeedTestCase(TestCase):
|
||||
|
||||
def assertChildNodeContent(self, elem, expected):
|
||||
for k, v in expected.items():
|
||||
self.assertEqual(
|
||||
elem.getElementsByTagName(k)[0].firstChild.wholeText, v)
|
||||
self.assertEqual(elem.getElementsByTagName(k)[0].firstChild.wholeText, v)
|
||||
|
||||
def assertCategories(self, elem, expected):
|
||||
self.assertEqual(
|
||||
{i.firstChild.wholeText for i in elem.childNodes if i.nodeName == 'category'},
|
||||
set(expected)
|
||||
{
|
||||
i.firstChild.wholeText
|
||||
for i in elem.childNodes
|
||||
if i.nodeName == "category"
|
||||
},
|
||||
set(expected),
|
||||
)
|
||||
|
||||
|
||||
@override_settings(ROOT_URLCONF='syndication_tests.urls')
|
||||
@override_settings(ROOT_URLCONF="syndication_tests.urls")
|
||||
class SyndicationFeedTest(FeedTestCase):
|
||||
"""
|
||||
Tests for the high-level syndication feed framework.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
@@ -80,250 +91,306 @@ class SyndicationFeedTest(FeedTestCase):
|
||||
"""
|
||||
Test the structure and content of feeds generated by Rss201rev2Feed.
|
||||
"""
|
||||
response = self.client.get('/syndication/rss2/')
|
||||
response = self.client.get("/syndication/rss2/")
|
||||
doc = minidom.parseString(response.content)
|
||||
|
||||
# Making sure there's only 1 `rss` element and that the correct
|
||||
# RSS version was specified.
|
||||
feed_elem = doc.getElementsByTagName('rss')
|
||||
feed_elem = doc.getElementsByTagName("rss")
|
||||
self.assertEqual(len(feed_elem), 1)
|
||||
feed = feed_elem[0]
|
||||
self.assertEqual(feed.getAttribute('version'), '2.0')
|
||||
self.assertEqual(feed.getElementsByTagName('language')[0].firstChild.nodeValue, 'en')
|
||||
self.assertEqual(feed.getAttribute("version"), "2.0")
|
||||
self.assertEqual(
|
||||
feed.getElementsByTagName("language")[0].firstChild.nodeValue, "en"
|
||||
)
|
||||
|
||||
# Making sure there's only one `channel` element w/in the
|
||||
# `rss` element.
|
||||
chan_elem = feed.getElementsByTagName('channel')
|
||||
chan_elem = feed.getElementsByTagName("channel")
|
||||
self.assertEqual(len(chan_elem), 1)
|
||||
chan = chan_elem[0]
|
||||
|
||||
# Find the last build date
|
||||
d = Entry.objects.latest('published').published
|
||||
d = Entry.objects.latest("published").published
|
||||
last_build_date = rfc2822_date(timezone.make_aware(d, TZ))
|
||||
|
||||
self.assertChildNodes(
|
||||
chan, [
|
||||
'title', 'link', 'description', 'language', 'lastBuildDate',
|
||||
'item', 'atom:link', 'ttl', 'copyright', 'category',
|
||||
]
|
||||
chan,
|
||||
[
|
||||
"title",
|
||||
"link",
|
||||
"description",
|
||||
"language",
|
||||
"lastBuildDate",
|
||||
"item",
|
||||
"atom:link",
|
||||
"ttl",
|
||||
"copyright",
|
||||
"category",
|
||||
],
|
||||
)
|
||||
self.assertChildNodeContent(chan, {
|
||||
'title': 'My blog',
|
||||
'description': 'A more thorough description of my blog.',
|
||||
'link': 'http://example.com/blog/',
|
||||
'language': 'en',
|
||||
'lastBuildDate': last_build_date,
|
||||
'ttl': '600',
|
||||
'copyright': 'Copyright (c) 2007, Sally Smith',
|
||||
})
|
||||
self.assertCategories(chan, ['python', 'django'])
|
||||
self.assertChildNodeContent(
|
||||
chan,
|
||||
{
|
||||
"title": "My blog",
|
||||
"description": "A more thorough description of my blog.",
|
||||
"link": "http://example.com/blog/",
|
||||
"language": "en",
|
||||
"lastBuildDate": last_build_date,
|
||||
"ttl": "600",
|
||||
"copyright": "Copyright (c) 2007, Sally Smith",
|
||||
},
|
||||
)
|
||||
self.assertCategories(chan, ["python", "django"])
|
||||
|
||||
# Ensure the content of the channel is correct
|
||||
self.assertChildNodeContent(chan, {
|
||||
'title': 'My blog',
|
||||
'link': 'http://example.com/blog/',
|
||||
})
|
||||
self.assertChildNodeContent(
|
||||
chan,
|
||||
{
|
||||
"title": "My blog",
|
||||
"link": "http://example.com/blog/",
|
||||
},
|
||||
)
|
||||
|
||||
# Check feed_url is passed
|
||||
self.assertEqual(
|
||||
chan.getElementsByTagName('atom:link')[0].getAttribute('href'),
|
||||
'http://example.com/syndication/rss2/'
|
||||
chan.getElementsByTagName("atom:link")[0].getAttribute("href"),
|
||||
"http://example.com/syndication/rss2/",
|
||||
)
|
||||
|
||||
# Find the pubdate of the first feed item
|
||||
d = Entry.objects.get(pk=self.e1.pk).published
|
||||
pub_date = rfc2822_date(timezone.make_aware(d, TZ))
|
||||
|
||||
items = chan.getElementsByTagName('item')
|
||||
items = chan.getElementsByTagName("item")
|
||||
self.assertEqual(len(items), Entry.objects.count())
|
||||
self.assertChildNodeContent(items[0], {
|
||||
'title': 'My first entry',
|
||||
'description': 'Overridden description: My first entry',
|
||||
'link': 'http://example.com/blog/%s/' % self.e1.pk,
|
||||
'guid': 'http://example.com/blog/%s/' % self.e1.pk,
|
||||
'pubDate': pub_date,
|
||||
'author': 'test@example.com (Sally Smith)',
|
||||
'comments': '/blog/%s/comments' % self.e1.pk,
|
||||
})
|
||||
self.assertCategories(items[0], ['python', 'testing'])
|
||||
self.assertChildNodeContent(
|
||||
items[0],
|
||||
{
|
||||
"title": "My first entry",
|
||||
"description": "Overridden description: My first entry",
|
||||
"link": "http://example.com/blog/%s/" % self.e1.pk,
|
||||
"guid": "http://example.com/blog/%s/" % self.e1.pk,
|
||||
"pubDate": pub_date,
|
||||
"author": "test@example.com (Sally Smith)",
|
||||
"comments": "/blog/%s/comments" % self.e1.pk,
|
||||
},
|
||||
)
|
||||
self.assertCategories(items[0], ["python", "testing"])
|
||||
for item in items:
|
||||
self.assertChildNodes(item, [
|
||||
'title',
|
||||
'link',
|
||||
'description',
|
||||
'guid',
|
||||
'category',
|
||||
'pubDate',
|
||||
'author',
|
||||
'comments',
|
||||
])
|
||||
self.assertChildNodes(
|
||||
item,
|
||||
[
|
||||
"title",
|
||||
"link",
|
||||
"description",
|
||||
"guid",
|
||||
"category",
|
||||
"pubDate",
|
||||
"author",
|
||||
"comments",
|
||||
],
|
||||
)
|
||||
# Assert that <guid> does not have any 'isPermaLink' attribute
|
||||
self.assertIsNone(item.getElementsByTagName(
|
||||
'guid')[0].attributes.get('isPermaLink'))
|
||||
self.assertIsNone(
|
||||
item.getElementsByTagName("guid")[0].attributes.get("isPermaLink")
|
||||
)
|
||||
|
||||
def test_rss2_feed_guid_permalink_false(self):
|
||||
"""
|
||||
Test if the 'isPermaLink' attribute of <guid> element of an item
|
||||
in the RSS feed is 'false'.
|
||||
"""
|
||||
response = self.client.get(
|
||||
'/syndication/rss2/guid_ispermalink_false/')
|
||||
response = self.client.get("/syndication/rss2/guid_ispermalink_false/")
|
||||
doc = minidom.parseString(response.content)
|
||||
chan = doc.getElementsByTagName(
|
||||
'rss')[0].getElementsByTagName('channel')[0]
|
||||
items = chan.getElementsByTagName('item')
|
||||
chan = doc.getElementsByTagName("rss")[0].getElementsByTagName("channel")[0]
|
||||
items = chan.getElementsByTagName("item")
|
||||
for item in items:
|
||||
self.assertEqual(
|
||||
item.getElementsByTagName('guid')[0].attributes.get(
|
||||
'isPermaLink').value, "false")
|
||||
item.getElementsByTagName("guid")[0]
|
||||
.attributes.get("isPermaLink")
|
||||
.value,
|
||||
"false",
|
||||
)
|
||||
|
||||
def test_rss2_feed_guid_permalink_true(self):
|
||||
"""
|
||||
Test if the 'isPermaLink' attribute of <guid> element of an item
|
||||
in the RSS feed is 'true'.
|
||||
"""
|
||||
response = self.client.get(
|
||||
'/syndication/rss2/guid_ispermalink_true/')
|
||||
response = self.client.get("/syndication/rss2/guid_ispermalink_true/")
|
||||
doc = minidom.parseString(response.content)
|
||||
chan = doc.getElementsByTagName(
|
||||
'rss')[0].getElementsByTagName('channel')[0]
|
||||
items = chan.getElementsByTagName('item')
|
||||
chan = doc.getElementsByTagName("rss")[0].getElementsByTagName("channel")[0]
|
||||
items = chan.getElementsByTagName("item")
|
||||
for item in items:
|
||||
self.assertEqual(
|
||||
item.getElementsByTagName('guid')[0].attributes.get(
|
||||
'isPermaLink').value, "true")
|
||||
item.getElementsByTagName("guid")[0]
|
||||
.attributes.get("isPermaLink")
|
||||
.value,
|
||||
"true",
|
||||
)
|
||||
|
||||
def test_rss2_single_enclosure(self):
|
||||
response = self.client.get('/syndication/rss2/single-enclosure/')
|
||||
response = self.client.get("/syndication/rss2/single-enclosure/")
|
||||
doc = minidom.parseString(response.content)
|
||||
chan = doc.getElementsByTagName('rss')[0].getElementsByTagName('channel')[0]
|
||||
items = chan.getElementsByTagName('item')
|
||||
chan = doc.getElementsByTagName("rss")[0].getElementsByTagName("channel")[0]
|
||||
items = chan.getElementsByTagName("item")
|
||||
for item in items:
|
||||
enclosures = item.getElementsByTagName('enclosure')
|
||||
enclosures = item.getElementsByTagName("enclosure")
|
||||
self.assertEqual(len(enclosures), 1)
|
||||
|
||||
def test_rss2_multiple_enclosures(self):
|
||||
with self.assertRaisesMessage(
|
||||
ValueError,
|
||||
"RSS feed items may only have one enclosure, see "
|
||||
"http://www.rssboard.org/rss-profile#element-channel-item-enclosure"
|
||||
"http://www.rssboard.org/rss-profile#element-channel-item-enclosure",
|
||||
):
|
||||
self.client.get('/syndication/rss2/multiple-enclosure/')
|
||||
self.client.get("/syndication/rss2/multiple-enclosure/")
|
||||
|
||||
def test_rss091_feed(self):
|
||||
"""
|
||||
Test the structure and content of feeds generated by RssUserland091Feed.
|
||||
"""
|
||||
response = self.client.get('/syndication/rss091/')
|
||||
response = self.client.get("/syndication/rss091/")
|
||||
doc = minidom.parseString(response.content)
|
||||
|
||||
# Making sure there's only 1 `rss` element and that the correct
|
||||
# RSS version was specified.
|
||||
feed_elem = doc.getElementsByTagName('rss')
|
||||
feed_elem = doc.getElementsByTagName("rss")
|
||||
self.assertEqual(len(feed_elem), 1)
|
||||
feed = feed_elem[0]
|
||||
self.assertEqual(feed.getAttribute('version'), '0.91')
|
||||
self.assertEqual(feed.getAttribute("version"), "0.91")
|
||||
|
||||
# Making sure there's only one `channel` element w/in the
|
||||
# `rss` element.
|
||||
chan_elem = feed.getElementsByTagName('channel')
|
||||
chan_elem = feed.getElementsByTagName("channel")
|
||||
self.assertEqual(len(chan_elem), 1)
|
||||
chan = chan_elem[0]
|
||||
self.assertChildNodes(
|
||||
chan, [
|
||||
'title', 'link', 'description', 'language', 'lastBuildDate',
|
||||
'item', 'atom:link', 'ttl', 'copyright', 'category',
|
||||
]
|
||||
chan,
|
||||
[
|
||||
"title",
|
||||
"link",
|
||||
"description",
|
||||
"language",
|
||||
"lastBuildDate",
|
||||
"item",
|
||||
"atom:link",
|
||||
"ttl",
|
||||
"copyright",
|
||||
"category",
|
||||
],
|
||||
)
|
||||
|
||||
# Ensure the content of the channel is correct
|
||||
self.assertChildNodeContent(chan, {
|
||||
'title': 'My blog',
|
||||
'link': 'http://example.com/blog/',
|
||||
})
|
||||
self.assertCategories(chan, ['python', 'django'])
|
||||
self.assertChildNodeContent(
|
||||
chan,
|
||||
{
|
||||
"title": "My blog",
|
||||
"link": "http://example.com/blog/",
|
||||
},
|
||||
)
|
||||
self.assertCategories(chan, ["python", "django"])
|
||||
|
||||
# Check feed_url is passed
|
||||
self.assertEqual(
|
||||
chan.getElementsByTagName('atom:link')[0].getAttribute('href'),
|
||||
'http://example.com/syndication/rss091/'
|
||||
chan.getElementsByTagName("atom:link")[0].getAttribute("href"),
|
||||
"http://example.com/syndication/rss091/",
|
||||
)
|
||||
|
||||
items = chan.getElementsByTagName('item')
|
||||
items = chan.getElementsByTagName("item")
|
||||
self.assertEqual(len(items), Entry.objects.count())
|
||||
self.assertChildNodeContent(items[0], {
|
||||
'title': 'My first entry',
|
||||
'description': 'Overridden description: My first entry',
|
||||
'link': 'http://example.com/blog/%s/' % self.e1.pk,
|
||||
})
|
||||
self.assertChildNodeContent(
|
||||
items[0],
|
||||
{
|
||||
"title": "My first entry",
|
||||
"description": "Overridden description: My first entry",
|
||||
"link": "http://example.com/blog/%s/" % self.e1.pk,
|
||||
},
|
||||
)
|
||||
for item in items:
|
||||
self.assertChildNodes(item, ['title', 'link', 'description'])
|
||||
self.assertChildNodes(item, ["title", "link", "description"])
|
||||
self.assertCategories(item, [])
|
||||
|
||||
def test_atom_feed(self):
|
||||
"""
|
||||
Test the structure and content of feeds generated by Atom1Feed.
|
||||
"""
|
||||
response = self.client.get('/syndication/atom/')
|
||||
response = self.client.get("/syndication/atom/")
|
||||
feed = minidom.parseString(response.content).firstChild
|
||||
|
||||
self.assertEqual(feed.nodeName, 'feed')
|
||||
self.assertEqual(feed.getAttribute('xmlns'), 'http://www.w3.org/2005/Atom')
|
||||
self.assertEqual(feed.nodeName, "feed")
|
||||
self.assertEqual(feed.getAttribute("xmlns"), "http://www.w3.org/2005/Atom")
|
||||
self.assertChildNodes(
|
||||
feed,
|
||||
['title', 'subtitle', 'link', 'id', 'updated', 'entry', 'rights', 'category', 'author']
|
||||
[
|
||||
"title",
|
||||
"subtitle",
|
||||
"link",
|
||||
"id",
|
||||
"updated",
|
||||
"entry",
|
||||
"rights",
|
||||
"category",
|
||||
"author",
|
||||
],
|
||||
)
|
||||
for link in feed.getElementsByTagName('link'):
|
||||
if link.getAttribute('rel') == 'self':
|
||||
self.assertEqual(link.getAttribute('href'), 'http://example.com/syndication/atom/')
|
||||
for link in feed.getElementsByTagName("link"):
|
||||
if link.getAttribute("rel") == "self":
|
||||
self.assertEqual(
|
||||
link.getAttribute("href"), "http://example.com/syndication/atom/"
|
||||
)
|
||||
|
||||
entries = feed.getElementsByTagName('entry')
|
||||
entries = feed.getElementsByTagName("entry")
|
||||
self.assertEqual(len(entries), Entry.objects.count())
|
||||
for entry in entries:
|
||||
self.assertChildNodes(entry, [
|
||||
'title',
|
||||
'link',
|
||||
'id',
|
||||
'summary',
|
||||
'category',
|
||||
'updated',
|
||||
'published',
|
||||
'rights',
|
||||
'author',
|
||||
])
|
||||
summary = entry.getElementsByTagName('summary')[0]
|
||||
self.assertEqual(summary.getAttribute('type'), 'html')
|
||||
self.assertChildNodes(
|
||||
entry,
|
||||
[
|
||||
"title",
|
||||
"link",
|
||||
"id",
|
||||
"summary",
|
||||
"category",
|
||||
"updated",
|
||||
"published",
|
||||
"rights",
|
||||
"author",
|
||||
],
|
||||
)
|
||||
summary = entry.getElementsByTagName("summary")[0]
|
||||
self.assertEqual(summary.getAttribute("type"), "html")
|
||||
|
||||
def test_atom_feed_published_and_updated_elements(self):
|
||||
"""
|
||||
The published and updated elements are not
|
||||
the same and now adhere to RFC 4287.
|
||||
"""
|
||||
response = self.client.get('/syndication/atom/')
|
||||
response = self.client.get("/syndication/atom/")
|
||||
feed = minidom.parseString(response.content).firstChild
|
||||
entries = feed.getElementsByTagName('entry')
|
||||
entries = feed.getElementsByTagName("entry")
|
||||
|
||||
published = entries[0].getElementsByTagName('published')[0].firstChild.wholeText
|
||||
updated = entries[0].getElementsByTagName('updated')[0].firstChild.wholeText
|
||||
published = entries[0].getElementsByTagName("published")[0].firstChild.wholeText
|
||||
updated = entries[0].getElementsByTagName("updated")[0].firstChild.wholeText
|
||||
|
||||
self.assertNotEqual(published, updated)
|
||||
|
||||
def test_atom_single_enclosure(self):
|
||||
response = self.client.get('/syndication/atom/single-enclosure/')
|
||||
response = self.client.get("/syndication/atom/single-enclosure/")
|
||||
feed = minidom.parseString(response.content).firstChild
|
||||
items = feed.getElementsByTagName('entry')
|
||||
items = feed.getElementsByTagName("entry")
|
||||
for item in items:
|
||||
links = item.getElementsByTagName('link')
|
||||
links = [link for link in links if link.getAttribute('rel') == 'enclosure']
|
||||
links = item.getElementsByTagName("link")
|
||||
links = [link for link in links if link.getAttribute("rel") == "enclosure"]
|
||||
self.assertEqual(len(links), 1)
|
||||
|
||||
def test_atom_multiple_enclosures(self):
|
||||
response = self.client.get('/syndication/atom/multiple-enclosure/')
|
||||
response = self.client.get("/syndication/atom/multiple-enclosure/")
|
||||
feed = minidom.parseString(response.content).firstChild
|
||||
items = feed.getElementsByTagName('entry')
|
||||
items = feed.getElementsByTagName("entry")
|
||||
for item in items:
|
||||
links = item.getElementsByTagName('link')
|
||||
links = [link for link in links if link.getAttribute('rel') == 'enclosure']
|
||||
links = item.getElementsByTagName("link")
|
||||
links = [link for link in links if link.getAttribute("rel") == "enclosure"]
|
||||
self.assertEqual(len(links), 2)
|
||||
|
||||
def test_latest_post_date(self):
|
||||
@@ -332,71 +399,88 @@ class SyndicationFeedTest(FeedTestCase):
|
||||
considered when determining the latest post date.
|
||||
"""
|
||||
# this feed has a `published` element with the latest date
|
||||
response = self.client.get('/syndication/atom/')
|
||||
response = self.client.get("/syndication/atom/")
|
||||
feed = minidom.parseString(response.content).firstChild
|
||||
updated = feed.getElementsByTagName('updated')[0].firstChild.wholeText
|
||||
updated = feed.getElementsByTagName("updated")[0].firstChild.wholeText
|
||||
|
||||
d = Entry.objects.latest('published').published
|
||||
d = Entry.objects.latest("published").published
|
||||
latest_published = rfc3339_date(timezone.make_aware(d, TZ))
|
||||
|
||||
self.assertEqual(updated, latest_published)
|
||||
|
||||
# this feed has an `updated` element with the latest date
|
||||
response = self.client.get('/syndication/latest/')
|
||||
response = self.client.get("/syndication/latest/")
|
||||
feed = minidom.parseString(response.content).firstChild
|
||||
updated = feed.getElementsByTagName('updated')[0].firstChild.wholeText
|
||||
updated = feed.getElementsByTagName("updated")[0].firstChild.wholeText
|
||||
|
||||
d = Entry.objects.exclude(title='My last entry').latest('updated').updated
|
||||
d = Entry.objects.exclude(title="My last entry").latest("updated").updated
|
||||
latest_updated = rfc3339_date(timezone.make_aware(d, TZ))
|
||||
|
||||
self.assertEqual(updated, latest_updated)
|
||||
|
||||
def test_custom_feed_generator(self):
|
||||
response = self.client.get('/syndication/custom/')
|
||||
response = self.client.get("/syndication/custom/")
|
||||
feed = minidom.parseString(response.content).firstChild
|
||||
|
||||
self.assertEqual(feed.nodeName, 'feed')
|
||||
self.assertEqual(feed.getAttribute('django'), 'rocks')
|
||||
self.assertEqual(feed.nodeName, "feed")
|
||||
self.assertEqual(feed.getAttribute("django"), "rocks")
|
||||
self.assertChildNodes(
|
||||
feed,
|
||||
['title', 'subtitle', 'link', 'id', 'updated', 'entry', 'spam', 'rights', 'category', 'author']
|
||||
[
|
||||
"title",
|
||||
"subtitle",
|
||||
"link",
|
||||
"id",
|
||||
"updated",
|
||||
"entry",
|
||||
"spam",
|
||||
"rights",
|
||||
"category",
|
||||
"author",
|
||||
],
|
||||
)
|
||||
|
||||
entries = feed.getElementsByTagName('entry')
|
||||
entries = feed.getElementsByTagName("entry")
|
||||
self.assertEqual(len(entries), Entry.objects.count())
|
||||
for entry in entries:
|
||||
self.assertEqual(entry.getAttribute('bacon'), 'yum')
|
||||
self.assertChildNodes(entry, [
|
||||
'title',
|
||||
'link',
|
||||
'id',
|
||||
'summary',
|
||||
'ministry',
|
||||
'rights',
|
||||
'author',
|
||||
'updated',
|
||||
'published',
|
||||
'category',
|
||||
])
|
||||
summary = entry.getElementsByTagName('summary')[0]
|
||||
self.assertEqual(summary.getAttribute('type'), 'html')
|
||||
self.assertEqual(entry.getAttribute("bacon"), "yum")
|
||||
self.assertChildNodes(
|
||||
entry,
|
||||
[
|
||||
"title",
|
||||
"link",
|
||||
"id",
|
||||
"summary",
|
||||
"ministry",
|
||||
"rights",
|
||||
"author",
|
||||
"updated",
|
||||
"published",
|
||||
"category",
|
||||
],
|
||||
)
|
||||
summary = entry.getElementsByTagName("summary")[0]
|
||||
self.assertEqual(summary.getAttribute("type"), "html")
|
||||
|
||||
def test_feed_generator_language_attribute(self):
|
||||
response = self.client.get('/syndication/language/')
|
||||
response = self.client.get("/syndication/language/")
|
||||
feed = minidom.parseString(response.content).firstChild
|
||||
self.assertEqual(feed.firstChild.getElementsByTagName('language')[0].firstChild.nodeValue, 'de')
|
||||
self.assertEqual(
|
||||
feed.firstChild.getElementsByTagName("language")[0].firstChild.nodeValue,
|
||||
"de",
|
||||
)
|
||||
|
||||
def test_title_escaping(self):
|
||||
"""
|
||||
Titles are escaped correctly in RSS feeds.
|
||||
"""
|
||||
response = self.client.get('/syndication/rss2/')
|
||||
response = self.client.get("/syndication/rss2/")
|
||||
doc = minidom.parseString(response.content)
|
||||
for item in doc.getElementsByTagName('item'):
|
||||
link = item.getElementsByTagName('link')[0]
|
||||
if link.firstChild.wholeText == 'http://example.com/blog/4/':
|
||||
title = item.getElementsByTagName('title')[0]
|
||||
self.assertEqual(title.firstChild.wholeText, 'A & B < C > D')
|
||||
for item in doc.getElementsByTagName("item"):
|
||||
link = item.getElementsByTagName("link")[0]
|
||||
if link.firstChild.wholeText == "http://example.com/blog/4/":
|
||||
title = item.getElementsByTagName("title")[0]
|
||||
self.assertEqual(title.firstChild.wholeText, "A & B < C > D")
|
||||
|
||||
def test_naive_datetime_conversion(self):
|
||||
"""
|
||||
@@ -404,11 +488,11 @@ class SyndicationFeedTest(FeedTestCase):
|
||||
"""
|
||||
# Naive date times passed in get converted to the local time zone, so
|
||||
# check the received zone offset against the local offset.
|
||||
response = self.client.get('/syndication/naive-dates/')
|
||||
response = self.client.get("/syndication/naive-dates/")
|
||||
doc = minidom.parseString(response.content)
|
||||
updated = doc.getElementsByTagName('updated')[0].firstChild.wholeText
|
||||
updated = doc.getElementsByTagName("updated")[0].firstChild.wholeText
|
||||
|
||||
d = Entry.objects.latest('published').published
|
||||
d = Entry.objects.latest("published").published
|
||||
latest = rfc3339_date(timezone.make_aware(d, TZ))
|
||||
|
||||
self.assertEqual(updated, latest)
|
||||
@@ -417,25 +501,25 @@ class SyndicationFeedTest(FeedTestCase):
|
||||
"""
|
||||
Datetimes with timezones don't get trodden on.
|
||||
"""
|
||||
response = self.client.get('/syndication/aware-dates/')
|
||||
response = self.client.get("/syndication/aware-dates/")
|
||||
doc = minidom.parseString(response.content)
|
||||
published = doc.getElementsByTagName('published')[0].firstChild.wholeText
|
||||
self.assertEqual(published[-6:], '+00:42')
|
||||
published = doc.getElementsByTagName("published")[0].firstChild.wholeText
|
||||
self.assertEqual(published[-6:], "+00:42")
|
||||
|
||||
def test_feed_no_content_self_closing_tag(self):
|
||||
tests = [
|
||||
(Atom1Feed, 'link'),
|
||||
(Rss201rev2Feed, 'atom:link'),
|
||||
(Atom1Feed, "link"),
|
||||
(Rss201rev2Feed, "atom:link"),
|
||||
]
|
||||
for feedgenerator, tag in tests:
|
||||
with self.subTest(feedgenerator=feedgenerator.__name__):
|
||||
feed = feedgenerator(
|
||||
title='title',
|
||||
link='https://example.com',
|
||||
description='self closing tags test',
|
||||
feed_url='https://feed.url.com',
|
||||
title="title",
|
||||
link="https://example.com",
|
||||
description="self closing tags test",
|
||||
feed_url="https://feed.url.com",
|
||||
)
|
||||
doc = feed.writeString('utf-8')
|
||||
doc = feed.writeString("utf-8")
|
||||
self.assertIn(f'<{tag} href="https://feed.url.com" rel="self"/>', doc)
|
||||
|
||||
@requires_tz_support
|
||||
@@ -443,48 +527,56 @@ class SyndicationFeedTest(FeedTestCase):
|
||||
"""
|
||||
Tests the Last-Modified header with naive publication dates.
|
||||
"""
|
||||
response = self.client.get('/syndication/naive-dates/')
|
||||
self.assertEqual(response.headers['Last-Modified'], 'Tue, 26 Mar 2013 01:00:00 GMT')
|
||||
response = self.client.get("/syndication/naive-dates/")
|
||||
self.assertEqual(
|
||||
response.headers["Last-Modified"], "Tue, 26 Mar 2013 01:00:00 GMT"
|
||||
)
|
||||
|
||||
def test_feed_last_modified_time(self):
|
||||
"""
|
||||
Tests the Last-Modified header with aware publication dates.
|
||||
"""
|
||||
response = self.client.get('/syndication/aware-dates/')
|
||||
self.assertEqual(response.headers['Last-Modified'], 'Mon, 25 Mar 2013 19:18:00 GMT')
|
||||
response = self.client.get("/syndication/aware-dates/")
|
||||
self.assertEqual(
|
||||
response.headers["Last-Modified"], "Mon, 25 Mar 2013 19:18:00 GMT"
|
||||
)
|
||||
|
||||
# No last-modified when feed has no item_pubdate
|
||||
response = self.client.get('/syndication/no_pubdate/')
|
||||
self.assertFalse(response.has_header('Last-Modified'))
|
||||
response = self.client.get("/syndication/no_pubdate/")
|
||||
self.assertFalse(response.has_header("Last-Modified"))
|
||||
|
||||
def test_feed_url(self):
|
||||
"""
|
||||
The feed_url can be overridden.
|
||||
"""
|
||||
response = self.client.get('/syndication/feedurl/')
|
||||
response = self.client.get("/syndication/feedurl/")
|
||||
doc = minidom.parseString(response.content)
|
||||
for link in doc.getElementsByTagName('link'):
|
||||
if link.getAttribute('rel') == 'self':
|
||||
self.assertEqual(link.getAttribute('href'), 'http://example.com/customfeedurl/')
|
||||
for link in doc.getElementsByTagName("link"):
|
||||
if link.getAttribute("rel") == "self":
|
||||
self.assertEqual(
|
||||
link.getAttribute("href"), "http://example.com/customfeedurl/"
|
||||
)
|
||||
|
||||
def test_secure_urls(self):
|
||||
"""
|
||||
Test URLs are prefixed with https:// when feed is requested over HTTPS.
|
||||
"""
|
||||
response = self.client.get('/syndication/rss2/', **{
|
||||
'wsgi.url_scheme': 'https',
|
||||
})
|
||||
doc = minidom.parseString(response.content)
|
||||
chan = doc.getElementsByTagName('channel')[0]
|
||||
self.assertEqual(
|
||||
chan.getElementsByTagName('link')[0].firstChild.wholeText[0:5],
|
||||
'https'
|
||||
response = self.client.get(
|
||||
"/syndication/rss2/",
|
||||
**{
|
||||
"wsgi.url_scheme": "https",
|
||||
},
|
||||
)
|
||||
atom_link = chan.getElementsByTagName('atom:link')[0]
|
||||
self.assertEqual(atom_link.getAttribute('href')[0:5], 'https')
|
||||
for link in doc.getElementsByTagName('link'):
|
||||
if link.getAttribute('rel') == 'self':
|
||||
self.assertEqual(link.getAttribute('href')[0:5], 'https')
|
||||
doc = minidom.parseString(response.content)
|
||||
chan = doc.getElementsByTagName("channel")[0]
|
||||
self.assertEqual(
|
||||
chan.getElementsByTagName("link")[0].firstChild.wholeText[0:5], "https"
|
||||
)
|
||||
atom_link = chan.getElementsByTagName("atom:link")[0]
|
||||
self.assertEqual(atom_link.getAttribute("href")[0:5], "https")
|
||||
for link in doc.getElementsByTagName("link"):
|
||||
if link.getAttribute("rel") == "self":
|
||||
self.assertEqual(link.getAttribute("href")[0:5], "https")
|
||||
|
||||
def test_item_link_error(self):
|
||||
"""
|
||||
@@ -492,75 +584,100 @@ class SyndicationFeedTest(FeedTestCase):
|
||||
item(s).
|
||||
"""
|
||||
msg = (
|
||||
'Give your Article class a get_absolute_url() method, or define '
|
||||
'an item_link() method in your Feed class.'
|
||||
"Give your Article class a get_absolute_url() method, or define "
|
||||
"an item_link() method in your Feed class."
|
||||
)
|
||||
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
||||
self.client.get('/syndication/articles/')
|
||||
self.client.get("/syndication/articles/")
|
||||
|
||||
def test_template_feed(self):
|
||||
"""
|
||||
The item title and description can be overridden with templates.
|
||||
"""
|
||||
response = self.client.get('/syndication/template/')
|
||||
response = self.client.get("/syndication/template/")
|
||||
doc = minidom.parseString(response.content)
|
||||
feed = doc.getElementsByTagName('rss')[0]
|
||||
chan = feed.getElementsByTagName('channel')[0]
|
||||
items = chan.getElementsByTagName('item')
|
||||
feed = doc.getElementsByTagName("rss")[0]
|
||||
chan = feed.getElementsByTagName("channel")[0]
|
||||
items = chan.getElementsByTagName("item")
|
||||
|
||||
self.assertChildNodeContent(items[0], {
|
||||
'title': 'Title in your templates: My first entry\n',
|
||||
'description': 'Description in your templates: My first entry\n',
|
||||
'link': 'http://example.com/blog/%s/' % self.e1.pk,
|
||||
})
|
||||
self.assertChildNodeContent(
|
||||
items[0],
|
||||
{
|
||||
"title": "Title in your templates: My first entry\n",
|
||||
"description": "Description in your templates: My first entry\n",
|
||||
"link": "http://example.com/blog/%s/" % self.e1.pk,
|
||||
},
|
||||
)
|
||||
|
||||
def test_template_context_feed(self):
|
||||
"""
|
||||
Custom context data can be passed to templates for title
|
||||
and description.
|
||||
"""
|
||||
response = self.client.get('/syndication/template_context/')
|
||||
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')
|
||||
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)\n',
|
||||
'description': 'My first entry (foo is bar)\n',
|
||||
})
|
||||
self.assertChildNodeContent(
|
||||
items[0],
|
||||
{
|
||||
"title": "My first entry (foo is bar)\n",
|
||||
"description": "My first entry (foo is bar)\n",
|
||||
},
|
||||
)
|
||||
|
||||
def test_add_domain(self):
|
||||
"""
|
||||
add_domain() prefixes domains onto the correct URLs.
|
||||
"""
|
||||
prefix_domain_mapping = (
|
||||
(('example.com', '/foo/?arg=value'), 'http://example.com/foo/?arg=value'),
|
||||
(('example.com', '/foo/?arg=value', True), 'https://example.com/foo/?arg=value'),
|
||||
(('example.com', 'http://djangoproject.com/doc/'), 'http://djangoproject.com/doc/'),
|
||||
(('example.com', 'https://djangoproject.com/doc/'), 'https://djangoproject.com/doc/'),
|
||||
(('example.com', 'mailto:uhoh@djangoproject.com'), 'mailto:uhoh@djangoproject.com'),
|
||||
(('example.com', '//example.com/foo/?arg=value'), 'http://example.com/foo/?arg=value'),
|
||||
(("example.com", "/foo/?arg=value"), "http://example.com/foo/?arg=value"),
|
||||
(
|
||||
("example.com", "/foo/?arg=value", True),
|
||||
"https://example.com/foo/?arg=value",
|
||||
),
|
||||
(
|
||||
("example.com", "http://djangoproject.com/doc/"),
|
||||
"http://djangoproject.com/doc/",
|
||||
),
|
||||
(
|
||||
("example.com", "https://djangoproject.com/doc/"),
|
||||
"https://djangoproject.com/doc/",
|
||||
),
|
||||
(
|
||||
("example.com", "mailto:uhoh@djangoproject.com"),
|
||||
"mailto:uhoh@djangoproject.com",
|
||||
),
|
||||
(
|
||||
("example.com", "//example.com/foo/?arg=value"),
|
||||
"http://example.com/foo/?arg=value",
|
||||
),
|
||||
)
|
||||
for prefix in prefix_domain_mapping:
|
||||
with self.subTest(prefix=prefix):
|
||||
self.assertEqual(views.add_domain(*prefix[0]), prefix[1])
|
||||
|
||||
def test_get_object(self):
|
||||
response = self.client.get('/syndication/rss2/articles/%s/' % self.e1.pk)
|
||||
response = self.client.get("/syndication/rss2/articles/%s/" % self.e1.pk)
|
||||
doc = minidom.parseString(response.content)
|
||||
feed = doc.getElementsByTagName('rss')[0]
|
||||
chan = feed.getElementsByTagName('channel')[0]
|
||||
items = chan.getElementsByTagName('item')
|
||||
feed = doc.getElementsByTagName("rss")[0]
|
||||
chan = feed.getElementsByTagName("channel")[0]
|
||||
items = chan.getElementsByTagName("item")
|
||||
|
||||
self.assertChildNodeContent(items[0], {
|
||||
'comments': '/blog/%s/article/%s/comments' % (self.e1.pk, self.a1.pk),
|
||||
'description': 'Article description: My first article',
|
||||
'link': 'http://example.com/blog/%s/article/%s/' % (self.e1.pk, self.a1.pk),
|
||||
'title': 'Title: My first article',
|
||||
'pubDate': rfc2822_date(timezone.make_aware(self.a1.published, TZ)),
|
||||
})
|
||||
self.assertChildNodeContent(
|
||||
items[0],
|
||||
{
|
||||
"comments": "/blog/%s/article/%s/comments" % (self.e1.pk, self.a1.pk),
|
||||
"description": "Article description: My first article",
|
||||
"link": "http://example.com/blog/%s/article/%s/"
|
||||
% (self.e1.pk, self.a1.pk),
|
||||
"title": "Title: My first article",
|
||||
"pubDate": rfc2822_date(timezone.make_aware(self.a1.published, TZ)),
|
||||
},
|
||||
)
|
||||
|
||||
def test_get_non_existent_object(self):
|
||||
response = self.client.get('/syndication/rss2/articles/0/')
|
||||
response = self.client.get("/syndication/rss2/articles/0/")
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
@@ -3,28 +3,30 @@ from django.urls import path
|
||||
from . import feeds
|
||||
|
||||
urlpatterns = [
|
||||
path('syndication/rss2/', feeds.TestRss2Feed()),
|
||||
path('syndication/rss2/articles/<int:entry_id>/', feeds.TestGetObjectFeed()),
|
||||
path("syndication/rss2/", feeds.TestRss2Feed()),
|
||||
path("syndication/rss2/articles/<int:entry_id>/", feeds.TestGetObjectFeed()),
|
||||
path(
|
||||
'syndication/rss2/guid_ispermalink_true/',
|
||||
feeds.TestRss2FeedWithGuidIsPermaLinkTrue()),
|
||||
"syndication/rss2/guid_ispermalink_true/",
|
||||
feeds.TestRss2FeedWithGuidIsPermaLinkTrue(),
|
||||
),
|
||||
path(
|
||||
'syndication/rss2/guid_ispermalink_false/',
|
||||
feeds.TestRss2FeedWithGuidIsPermaLinkFalse()),
|
||||
path('syndication/rss091/', feeds.TestRss091Feed()),
|
||||
path('syndication/no_pubdate/', feeds.TestNoPubdateFeed()),
|
||||
path('syndication/atom/', feeds.TestAtomFeed()),
|
||||
path('syndication/latest/', feeds.TestLatestFeed()),
|
||||
path('syndication/custom/', feeds.TestCustomFeed()),
|
||||
path('syndication/language/', feeds.TestLanguageFeed()),
|
||||
path('syndication/naive-dates/', feeds.NaiveDatesFeed()),
|
||||
path('syndication/aware-dates/', feeds.TZAwareDatesFeed()),
|
||||
path('syndication/feedurl/', feeds.TestFeedUrlFeed()),
|
||||
path('syndication/articles/', feeds.ArticlesFeed()),
|
||||
path('syndication/template/', feeds.TemplateFeed()),
|
||||
path('syndication/template_context/', feeds.TemplateContextFeed()),
|
||||
path('syndication/rss2/single-enclosure/', feeds.TestSingleEnclosureRSSFeed()),
|
||||
path('syndication/rss2/multiple-enclosure/', feeds.TestMultipleEnclosureRSSFeed()),
|
||||
path('syndication/atom/single-enclosure/', feeds.TestSingleEnclosureAtomFeed()),
|
||||
path('syndication/atom/multiple-enclosure/', feeds.TestMultipleEnclosureAtomFeed()),
|
||||
"syndication/rss2/guid_ispermalink_false/",
|
||||
feeds.TestRss2FeedWithGuidIsPermaLinkFalse(),
|
||||
),
|
||||
path("syndication/rss091/", feeds.TestRss091Feed()),
|
||||
path("syndication/no_pubdate/", feeds.TestNoPubdateFeed()),
|
||||
path("syndication/atom/", feeds.TestAtomFeed()),
|
||||
path("syndication/latest/", feeds.TestLatestFeed()),
|
||||
path("syndication/custom/", feeds.TestCustomFeed()),
|
||||
path("syndication/language/", feeds.TestLanguageFeed()),
|
||||
path("syndication/naive-dates/", feeds.NaiveDatesFeed()),
|
||||
path("syndication/aware-dates/", feeds.TZAwareDatesFeed()),
|
||||
path("syndication/feedurl/", feeds.TestFeedUrlFeed()),
|
||||
path("syndication/articles/", feeds.ArticlesFeed()),
|
||||
path("syndication/template/", feeds.TemplateFeed()),
|
||||
path("syndication/template_context/", feeds.TemplateContextFeed()),
|
||||
path("syndication/rss2/single-enclosure/", feeds.TestSingleEnclosureRSSFeed()),
|
||||
path("syndication/rss2/multiple-enclosure/", feeds.TestMultipleEnclosureRSSFeed()),
|
||||
path("syndication/atom/single-enclosure/", feeds.TestSingleEnclosureAtomFeed()),
|
||||
path("syndication/atom/multiple-enclosure/", feeds.TestMultipleEnclosureAtomFeed()),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user