forked from realpython/reader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_feed.py
More file actions
89 lines (66 loc) · 2.29 KB
/
test_feed.py
File metadata and controls
89 lines (66 loc) · 2.29 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
86
87
88
89
"""Tests for the reader.feed module"""
# Standard library imports
import os.path
# Third party imports
import pytest
# Reader imports
from reader import feed
# Current directory
HERE = os.path.dirname(__file__)
@pytest.fixture
def monkeypatch_feed(monkeypatch):
"""Use local file instead of downloading feed from web"""
local_path = os.path.join(HERE, "realpython_20180919.xml")
monkeypatch.setattr(feed, "URL", local_path)
return local_path
@pytest.fixture
def monkeypatch_summary_feed(monkeypatch):
"""Use local file instead of downloading feed from web"""
local_path = os.path.join(HERE, "realpython_descriptions_20180919.xml")
monkeypatch.setattr(feed, "URL", local_path)
return local_path
#
# Tests
#
def test_site(monkeypatch_feed):
"""Test that we can read the site title and link"""
expected = "Real Python (https://realpython.com/)"
assert feed.get_site() == expected
def test_article_title(monkeypatch_feed):
"""Test that title is added at top of article"""
article_id = 0
title = feed.get_titles()[article_id]
article = feed.get_article(article_id)
assert article.strip("# ").startswith(title)
def test_article(monkeypatch_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)
for phrase in article_phrases:
assert phrase in article
def test_titles(monkeypatch_feed):
"""Test that titles are found"""
titles = feed.get_titles()
assert len(titles) == 20
assert titles[0] == "Absolute vs Relative Imports in Python"
assert titles[9] == "Primer on Python Decorators"
def test_summary(monkeypatch_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)
for phrase in summary_phrases:
assert phrase in summary
def test_invalid_article_id(monkeypatch_feed):
"""Test that invalid article ids are handled gracefully"""
article_id = "wrong"
with pytest.raises(SystemExit):
feed.get_article(article_id)