-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathtest_opml.py
177 lines (148 loc) · 7.13 KB
/
test_opml.py
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env python
import unittest
from planet.opml import opml2config
from ConfigParser import ConfigParser
class OpmlTest(unittest.TestCase):
"""
Test the opml2config function
"""
def setUp(self):
self.config = ConfigParser()
#
# Element
#
def test_outline_element(self):
opml2config('''<outline type="rss"
xmlUrl="http://example.com/feed.xml"
text="sample feed"/>''', self.config)
self.assertEqual('sample feed',
self.config.get("http://example.com/feed.xml", 'name'))
def test_wrong_element(self):
opml2config('''<feed type="rss"
xmlUrl="http://example.com/feed.xml"
text="sample feed"/>''', self.config)
self.assertFalse(self.config.has_section("http://example.com/feed.xml"))
def test_illformed_xml_before(self):
opml2config('''<bad stuff before>
<outline type="rss"
xmlUrl="http://example.com/feed.xml"
text="sample feed"/>''', self.config)
self.assertEqual('sample feed',
self.config.get("http://example.com/feed.xml", 'name'))
def test_illformed_xml_after(self):
opml2config('''<outline type="rss"
xmlUrl="http://example.com/feed.xml"
text="sample feed"/>
<bad stuff after>''', self.config)
self.assertEqual('sample feed',
self.config.get("http://example.com/feed.xml", 'name'))
#
# Type
#
def test_type_missing(self):
opml2config('''<outline
xmlUrl="http://example.com/feed.xml"
text="sample feed"/>''', self.config)
self.assertEqual('sample feed',
self.config.get("http://example.com/feed.xml", 'name'))
def test_type_uppercase(self):
opml2config('''<outline type="RSS"
xmlUrl="http://example.com/feed.xml"
text="sample feed"/>''', self.config)
self.assertEqual('sample feed',
self.config.get("http://example.com/feed.xml", 'name'))
def test_type_atom(self):
opml2config('''<outline type="atom"
xmlUrl="http://example.com/feed.xml"
text="sample feed"/>''', self.config)
self.assertEqual('sample feed',
self.config.get("http://example.com/feed.xml", 'name'))
def test_wrong_type(self):
opml2config('''<outline type="other"
xmlUrl="http://example.com/feed.xml"
text="sample feed"/>''', self.config)
self.assertFalse(self.config.has_section("http://example.com/feed.xml"))
def test_WordPress_link_manager(self):
# http://www.wasab.dk/morten/blog/archives/2006/10/22/wp-venus
opml2config('''<outline type="link"
xmlUrl="http://example.com/feed.xml"
text="sample feed"/>''', self.config)
self.assertEqual('sample feed',
self.config.get("http://example.com/feed.xml", 'name'))
#
# xmlUrl
#
def test_xmlurl_wrong_case(self):
opml2config('''<outline type="rss"
xmlurl="http://example.com/feed.xml"
text="sample feed"/>''', self.config)
self.assertEqual('sample feed',
self.config.get("http://example.com/feed.xml", 'name'))
def test_missing_xmlUrl(self):
opml2config('''<outline type="rss"
text="sample feed"/>''', self.config)
self.assertFalse(self.config.has_section("http://example.com/feed.xml"))
def test_blank_xmlUrl(self):
opml2config('''<outline type="rss"
xmlUrl=""
text="sample feed"/>''', self.config)
self.assertFalse(self.config.has_section(""))
#
# text
#
def test_title_attribute(self):
opml2config('''<outline type="rss"
xmlUrl="http://example.com/feed.xml"
title="sample feed"/>''', self.config)
self.assertEqual('sample feed',
self.config.get("http://example.com/feed.xml", 'name'))
def test_missing_text(self):
opml2config('''<outline type="rss"
xmlUrl="http://example.com/feed.xml"
/>''', self.config)
self.assertFalse(self.config.has_section("http://example.com/feed.xml"))
def test_blank_text_no_title(self):
opml2config('''<outline type="rss"
xmlUrl="http://example.com/feed.xml"
text=""/>''', self.config)
self.assertFalse(self.config.has_section("http://example.com/feed.xml"))
def test_blank_text_with_title(self):
opml2config('''<outline type="rss"
xmlUrl="http://example.com/feed.xml"
text=""
title="sample feed"/>''', self.config)
self.assertEqual('sample feed',
self.config.get("http://example.com/feed.xml", 'name'))
def test_blank_text_blank_title(self):
opml2config('''<outline type="rss"
xmlUrl="http://example.com/feed.xml"
text=""
title=""/>''', self.config)
self.assertFalse(self.config.has_section("http://example.com/feed.xml"))
def test_text_utf8(self):
opml2config('''<outline type="rss"
xmlUrl="http://example.com/feed.xml"
text="Se\xc3\xb1or Frog\xe2\x80\x99s"/>''',
self.config)
self.assertEqual('Se\xc3\xb1or Frog\xe2\x80\x99s',
self.config.get("http://example.com/feed.xml", 'name'))
def test_text_win_1252(self):
opml2config('''<outline type="rss"
xmlUrl="http://example.com/feed.xml"
text="Se\xf1or Frog\x92s"/>''', self.config)
self.assertEqual('Se\xc3\xb1or Frog\xe2\x80\x99s',
self.config.get("http://example.com/feed.xml", 'name'))
def test_text_entity(self):
opml2config('''<outline type="rss"
xmlUrl="http://example.com/feed.xml"
text="Señor Frog’s"/>''', self.config)
self.assertEqual('Se\xc3\xb1or Frog\xe2\x80\x99s',
self.config.get("http://example.com/feed.xml", 'name'))
def test_text_double_escaped(self):
opml2config('''<outline type="rss"
xmlUrl="http://example.com/feed.xml"
text="Se&ntilde;or Frog&rsquo;s"/>''', self.config)
self.assertEqual('Se\xc3\xb1or Frog\xe2\x80\x99s',
self.config.get("http://example.com/feed.xml", 'name'))
if __name__ == '__main__':
unittest.main()