Skip to content

Commit 6bddfc9

Browse files
committed
Add tests to test User-Agent headers in request
1 parent bcc258a commit 6bddfc9

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

tests/constants.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,14 @@
9393
DEFAULT_EXCLUSIONS: list[str] = []
9494
DEFAULT_INCLUSIONS = ["image", "title", "link", "published"]
9595
DATE_FORMAT = "%a, %d %b %Y %H:%M:%S UTC%z"
96+
97+
URLS_HEADERS_REQUIRED = [
98+
{
99+
"name": "elcomercio_gijon",
100+
"url": "https://www.elcomercio.es/rss/2.0/?section=gijon",
101+
},
102+
{
103+
"name": "nasdaq_options",
104+
"url": "https://www.nasdaq.com/feed/rssoutbound?category=Options",
105+
},
106+
]

tests/test_sensors.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import feedparser
88
import pytest
9-
from constants import DATE_FORMAT
9+
from constants import DATE_FORMAT, URLS_HEADERS_REQUIRED
1010
from feedsource import FeedSource
1111

1212
from custom_components.feedparser.sensor import (
@@ -157,3 +157,24 @@ def test_check_duplicates(feed_sensor: FeedParserSensor) -> None:
157157
feed_sensor.update()
158158
after_second_update = len(feed_sensor.feed_entries)
159159
assert after_first_update == after_second_update
160+
161+
162+
@pytest.mark.parametrize(
163+
"online_feed",
164+
URLS_HEADERS_REQUIRED,
165+
ids=lambda feed_url: feed_url["name"],
166+
)
167+
def test_fetch_data_headers_required(online_feed: dict) -> None:
168+
"""Test fetching feed from remote server that requires request with headers."""
169+
feed_sensor = FeedParserSensor(
170+
feed=online_feed["url"],
171+
name=online_feed["name"],
172+
date_format=DATE_FORMAT,
173+
local_time=False,
174+
show_topn=9999,
175+
inclusions=["image", "title", "link", "published"],
176+
exclusions=[],
177+
scan_interval=DEFAULT_SCAN_INTERVAL,
178+
)
179+
feed_sensor.update()
180+
assert feed_sensor.feed_entries

0 commit comments

Comments
 (0)