Skip to content

Commit 78647d3

Browse files
committed
Adding test
1 parent 00d28c6 commit 78647d3

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

changedetectionio/tests/test_rss_reader_mode.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,61 @@
77
from .util import set_original_response, set_modified_response, live_server_setup, wait_for_all_checks, extract_rss_token_from_UI, \
88
extract_UUID_from_client, delete_all_watches
99

10+
def set_xmlns_purl_content(datastore_path, extra=""):
11+
data=f"""<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
12+
<channel>
13+
<atom:link href="https://www.xxxxxxxtechxxxxx.com/feeds.xml" rel="self" type="application/rss+xml"/>
14+
<title>
15+
<![CDATA[ Latest from xxxxxxxtechxxxxx ]]>
16+
</title>
17+
<link>https://www.xxxxx.com</link>
18+
<description>
19+
<![CDATA[ All the latest content from the xxxxxxxtechxxxxx team ]]>
20+
</description>
21+
<lastBuildDate>Wed, 19 Nov 2025 15:00:00 +0000</lastBuildDate>
22+
<language>en</language>
23+
<item>
24+
<title>
25+
<![CDATA[ Sony Xperia 1 VII review: has Sony’s long-standing Xperia family lost what it takes to compete? ]]>
26+
</title>
27+
<dc:content>
28+
<![CDATA[ {{extra}} a little harder, dc-content. blue often quite tough and purple usually very difficult.</p><p>On the plus side, you don't technically need to solve the final one, as you'll be able to answer that one by a process of elimination. What's more, you can make up to four mistakes, which gives you a little bit of breathing room.</p><p>It's a little more involved than something like Wordle, however, and there are plenty of opportunities for the game to trip you up with tricks. For instance, watch out for homophones and other word games that could disguise the answers.</p><p>It's playable for free via the <a href="https://www.nytimes.com/games/strands" target="_blank">NYT Games site</a> on desktop or mobile.</p></article></section> ]]>
29+
</dc:content>
30+
<link>https://www.xxxxxxx.com/gaming/nyt-connections-today-answers-hints-20-november-2025</link>
31+
<description>
32+
<![CDATA[ Looking for NYT Connections answers and hints? Here's all you need to know to solve today's game, plus my commentary on the puzzles. ]]>
33+
</description>
34+
<guid isPermaLink="false">N2C2T6DztpWdxSdKpSUx89</guid>
35+
<enclosure url="https://cdn.mos.cms.futurecdn.net/RCGfdf3yhQ9W3MHbTRT6yk-1280-80.jpg" type="image/jpeg" length="0"/>
36+
<pubDate>Wed, 19 Nov 2025 15:00:00 +0000</pubDate>
37+
<category>
38+
<![CDATA[ Gaming ]]>
39+
</category>
40+
<dc:creator>
41+
<![CDATA[ Johnny Dee ]]>
42+
</dc:creator>
43+
<media:content type="image/jpeg" url="https://cdn.mos.cms.futurecdn.net/RCGfdf3yhQ9W3MHbTRT6yk-1280-80.jpg">
44+
<media:credit>
45+
<![CDATA[ New York Times ]]>
46+
</media:credit>
47+
<media:text>
48+
<![CDATA[ NYT Connections homescreen on a phone, on a purple background ]]>
49+
</media:text>
50+
<media:title type="plain">
51+
<![CDATA[ NYT Connections homescreen on a phone, on a purple background ]]>
52+
</media:title>
53+
</media:content>
54+
<media:thumbnail url="https://cdn.mos.cms.futurecdn.net/RCGfdf3yhQ9W3MHbTRT6yk-1280-80.jpg"/>
55+
</item>
56+
</channel>
57+
</rss>
58+
"""
59+
60+
with open(os.path.join(datastore_path, "endpoint-content.txt"), "w") as f:
61+
f.write(data)
62+
63+
64+
1065

1166
def set_original_cdata_xml(datastore_path):
1267
test_return_data = """<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
@@ -98,3 +153,26 @@ def test_rss_reader_mode_with_css_filters(client, live_server, measure_memory_us
98153
assert 'The days of Terminator and The Matrix' in snapshot_contents
99154
delete_all_watches(client)
100155

156+
157+
def test_xmlns_purl_content(client, live_server, measure_memory_usage, datastore_path):
158+
set_xmlns_purl_content(datastore_path=datastore_path)
159+
160+
# Rarely do endpoints give the right header, usually just text/xml, so we check also for <rss
161+
# This also triggers the automatic CDATA text parser so the RSS goes back a nice content list
162+
#test_url = url_for('test_endpoint', content_type="text/xml; charset=UTF-8", _external=True)
163+
164+
# Because NO utf-8 was specified here, we should be able to recover it in requests or other somehow.
165+
test_url = url_for('test_endpoint', content_type="text/xml;", _external=True)
166+
live_server.app.config['DATASTORE'].data['settings']['application']['rss_reader_mode'] = True
167+
168+
# Add our URL to the import page
169+
uuid = client.application.config.get('DATASTORE').add_watch(url=test_url, extras={'include_filters': [".last"]})
170+
client.get(url_for("ui.form_watch_checknow"), follow_redirects=True)
171+
172+
wait_for_all_checks(client)
173+
174+
watch = live_server.app.config['DATASTORE'].data['watching'][uuid]
175+
dates = list(watch.history.keys())
176+
snapshot_contents = watch.get_history_snapshot(timestamp=dates[0])
177+
assert "Title: Sony Xperia 1 VII review: has Sony’s long-standing Xperia family lost what it takes to compete?" in snapshot_contents
178+
assert "dc-content" in snapshot_contents

0 commit comments

Comments
 (0)