-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathtest_feed.py
More file actions
85 lines (62 loc) · 2.18 KB
/
test_feed.py
File metadata and controls
85 lines (62 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""Tests for the reader.feed module."""
# Standard library imports
import pathlib
# Third party imports
import pytest
# Reader imports
from reader import feed
# Current directory
HERE = pathlib.Path(__file__).resolve().parent
@pytest.fixture
def local_feed():
"""Use local file instead of downloading feed from web."""
return HERE / "realpython_20180919.xml"
@pytest.fixture
def local_summary_feed():
"""Use local file instead of downloading feed from web."""
return HERE / "realpython_descriptions_20180919.xml"
#
# Tests
#
def test_site(local_feed):
"""Test that we can read the site title and link."""
expected = "Real Python (https://realpython.com/)"
assert feed.get_site(url=local_feed) == expected
def test_article_title(local_feed):
"""Test that title is added at top of article."""
article_id = 0
title = feed.get_titles(url=local_feed)[article_id]
article = feed.get_article(article_id, url=local_feed)
assert article.strip("# ").startswith(title)
def test_article(local_feed):
"""Test that article is returned."""
article_id = 2
article_phrases = [
"logging.info('This is an info message')",
"By using the `level` parameter",
" * `level`: The root logger",
]
article = feed.get_article(article_id, url=local_feed)
for phrase in article_phrases:
assert phrase in article
def test_titles(local_feed):
"""Test that titles are found."""
titles = feed.get_titles(url=local_feed)
assert len(titles) == 20
assert titles[0] == "Absolute vs Relative Imports in Python"
assert titles[9] == "Primer on Python Decorators"
def test_summary(local_summary_feed):
"""Test that summary feeds can be read."""
article_id = 1
summary_phrases = [
"Get the inside scoop",
"this list of\ninformative videos",
]
summary = feed.get_article(article_id, url=local_summary_feed)
for phrase in summary_phrases:
assert phrase in summary
def test_invalid_article_id(local_feed):
"""Test that invalid article ids are handled gracefully."""
article_id = "wrong"
with pytest.raises(SystemExit):
feed.get_article(article_id, url=local_feed)