Skip to content

Commit d6fdf49

Browse files
authored
Restore content to default item dict (#48)
1 parent d4d6b5a commit d6fdf49

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

RELEASE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Release type: patch
2+
3+
Restore missing `content` property to default item dictionary.

feedgenerator/django/utils/feedgenerator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def add_item(
178178
categories=(),
179179
item_copyright=None,
180180
ttl=None,
181+
content=None,
181182
updateddate=None,
182183
enclosures=None,
183184
**kwargs,
@@ -197,6 +198,7 @@ def to_str(s):
197198
"title": to_str(title),
198199
"link": iri_to_uri(link),
199200
"description": to_str(description),
201+
"content": to_str(content),
200202
"author_email": to_str(author_email),
201203
"author_name": to_str(author_name),
202204
"author_link": iri_to_uri(author_link),

tests/test_feedgenerator.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
from urllib.parse import quote
23
from zoneinfo import ZoneInfo
34

45
import pytest
@@ -27,6 +28,9 @@
2728
pubdate=NAIVE_DATE,
2829
)
2930

31+
MINIMAL_FEED = {key: FIXT_FEED[key] for key in ("title", "link", "description")}
32+
MINIMAL_ITEM = {key: FIXT_ITEM[key] for key in ("title", "link", "description")}
33+
3034

3135
EXPECTED_RESULT_RSS = """<?xml version="1.0" encoding="utf-8"?>
3236
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Poynter E-Media Tidbits</title><link>http://www.poynter.org/column.asp?id=31</link><description>A group Weblog by the sharpest minds in online media/journalism/publishing.
@@ -162,3 +166,69 @@ def test_timezone_handling(generator, date, expected_date_string):
162166
result = feed.writeString(ENCODING)
163167

164168
assert expected_date_string in result
169+
170+
171+
def test_feed_default_properties():
172+
feed = feedgenerator.SyndicationFeed(**MINIMAL_FEED)
173+
174+
for key in ("title", "link", "description"):
175+
assert feed.feed[key] == MINIMAL_FEED[key]
176+
177+
for key in (
178+
"language",
179+
"author_email",
180+
"author_name",
181+
"author_link",
182+
"subtitle",
183+
"categories",
184+
"feed_url",
185+
"feed_copyright",
186+
"id",
187+
"ttl",
188+
"stylesheets",
189+
):
190+
assert key in feed.feed
191+
192+
# Testing this after testing that the property exists
193+
assert feed.feed["id"] == MINIMAL_FEED["link"]
194+
195+
196+
def test_item_default_properties():
197+
feed = feedgenerator.SyndicationFeed(**MINIMAL_FEED)
198+
feed.add_item(**MINIMAL_ITEM)
199+
200+
for key in ("title", "description"):
201+
expected_value = MINIMAL_ITEM[key]
202+
# The link in the test contains a multibyte character
203+
if key == "link":
204+
expected_value = quote(MINIMAL_ITEM[key], safe="/#%[]=:;$&()+,!?*@'~")
205+
assert feed.items[0][key] == expected_value
206+
207+
for key in (
208+
"content",
209+
"author_email",
210+
"author_name",
211+
"author_link",
212+
"pubdate",
213+
"updateddate",
214+
"comments",
215+
"unique_id",
216+
"unique_id_is_permalink",
217+
"enclosures",
218+
"categories",
219+
"item_copyright",
220+
"ttl",
221+
):
222+
assert key in feed.items[0]
223+
224+
225+
def test_feed_kwargs():
226+
feed = feedgenerator.SyndicationFeed(test="test", **FIXT_FEED)
227+
assert "test" in feed.feed
228+
229+
230+
def test_item_kwargs():
231+
feed = feedgenerator.SyndicationFeed(**FIXT_ITEM)
232+
feed.add_item(test="test", **FIXT_ITEM)
233+
234+
assert "test" in feed.items[0]

0 commit comments

Comments
 (0)