|
1 | 1 | import datetime |
| 2 | +from urllib.parse import quote |
2 | 3 | from zoneinfo import ZoneInfo |
3 | 4 |
|
4 | 5 | import pytest |
|
27 | 28 | pubdate=NAIVE_DATE, |
28 | 29 | ) |
29 | 30 |
|
| 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 | + |
30 | 34 |
|
31 | 35 | EXPECTED_RESULT_RSS = """<?xml version="1.0" encoding="utf-8"?> |
32 | 36 | <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): |
162 | 166 | result = feed.writeString(ENCODING) |
163 | 167 |
|
164 | 168 | 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