wiki-api 0.0.2 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
- data/.rubocop.yml +24 -0
- data/.travis.yml +12 -0
- data/Gemfile +2 -0
- data/README.md +93 -64
- data/Rakefile +13 -1
- data/bin/console +8 -0
- data/lib/wiki/api/connect.rb +52 -28
- data/lib/wiki/api/page.rb +48 -82
- data/lib/wiki/api/page_block.rb +19 -18
- data/lib/wiki/api/page_headline.rb +104 -8
- data/lib/wiki/api/page_link.rb +18 -14
- data/lib/wiki/api/page_list_item.rb +12 -13
- data/lib/wiki/api/util.rb +24 -15
- data/lib/wiki/api/version.rb +3 -1
- data/lib/wiki/api.rb +9 -8
- data/test/test_helper.rb +4 -7
- data/test/unit/files/Wiktionary_program.html +4232 -0
- data/test/unit/wiki_connect.rb +18 -25
- data/test/unit/wiki_page_offline.rb +295 -0
- data/wiki-api.gemspec +20 -17
- metadata +57 -38
- data/test/unit/wiki_page_config.rb +0 -45
- data/test/unit/wiki_page_object.rb +0 -229
@@ -1,229 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'test/unit'
|
5
|
-
require File.expand_path(File.dirname(__FILE__) + "/../../lib/wiki/api")
|
6
|
-
|
7
|
-
#
|
8
|
-
# Testing the parsing of URI (with a predownloaded HTML file):
|
9
|
-
# /files/Wiktionary_Welcome,_newcomers.html (2013-03-27)
|
10
|
-
#
|
11
|
-
# Online equivalent:
|
12
|
-
# https://en.wiktionary.org/wiki/Wiktionary:Welcome,_newcomers
|
13
|
-
#
|
14
|
-
|
15
|
-
class WikiPageObject < Test::Unit::TestCase
|
16
|
-
|
17
|
-
# this global is required to resolve URIs (MediaWiki uses relative paths in their links)
|
18
|
-
GLB_CONFIG = { uri: "http://en.wiktionary.org" }
|
19
|
-
|
20
|
-
# use local file for test loading
|
21
|
-
PAGE_CONFIG = { file: File.expand_path(File.dirname(__FILE__) + "/files/Wiktionary_Welcome,_newcomers.html") }
|
22
|
-
|
23
|
-
def setup
|
24
|
-
# NOTE: comment Page.config, to use the online MediaWiki instance
|
25
|
-
Wiki::Api::Page.config = PAGE_CONFIG
|
26
|
-
Wiki::Api::Connect.config = GLB_CONFIG
|
27
|
-
@page_name = "Wiktionary:Welcome,_newcomers"
|
28
|
-
end
|
29
|
-
|
30
|
-
def teardown
|
31
|
-
end
|
32
|
-
|
33
|
-
# test simple page invocation
|
34
|
-
def test_page_invocation
|
35
|
-
page = Wiki::Api::Page.new name: @page_name
|
36
|
-
headlines = page.headlines
|
37
|
-
assert !headlines.empty?, "expected headlines"
|
38
|
-
headlines.each do |headline|
|
39
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# test nokogiri elements per headline
|
44
|
-
def test_page_elements
|
45
|
-
page = Wiki::Api::Page.new name: @page_name
|
46
|
-
headlines = page.headlines
|
47
|
-
assert !headlines.empty?, "expected headlines"
|
48
|
-
assert headlines.size > 1, "expected more than one headline"
|
49
|
-
headlines.each do |headline|
|
50
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
51
|
-
elements = headline.elements.flatten
|
52
|
-
assert !elements.empty?, "expected elements"
|
53
|
-
elements.each do |element|
|
54
|
-
assert element.is_a?(Nokogiri::XML::Element) ||
|
55
|
-
element.is_a?(Nokogiri::XML::Text) ||
|
56
|
-
element.is_a?(Nokogiri::XML::Comment), "expected nokogiri internals"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
# test pageblocks for each headline
|
62
|
-
def test_page_blocks
|
63
|
-
page = Wiki::Api::Page.new name: @page_name
|
64
|
-
headlines = page.headlines
|
65
|
-
assert !headlines.empty?, "expected headlines"
|
66
|
-
assert headlines.size > 1, "expected more than one headline"
|
67
|
-
headlines.each do |headline|
|
68
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
69
|
-
block = headline.block
|
70
|
-
assert block.is_a?(Wiki::Api::PageBlock), "expected block object"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# test string text from page block
|
75
|
-
def test_page_block_string_text
|
76
|
-
page = Wiki::Api::Page.new name: @page_name
|
77
|
-
headlines = page.headlines
|
78
|
-
assert !headlines.empty?, "expected headlines"
|
79
|
-
assert headlines.size > 1, "expected more than one headline"
|
80
|
-
headlines.each do |headline|
|
81
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
82
|
-
block = headline.block
|
83
|
-
assert block.is_a?(Wiki::Api::PageBlock), "expected block object"
|
84
|
-
texts = block.to_texts
|
85
|
-
assert texts.is_a?(Array) && !texts.empty?, "expected array"
|
86
|
-
texts.each do |text|
|
87
|
-
assert text.is_a?(String), "expected string"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
# test list items from page blocks
|
93
|
-
def test_page_block_list_items
|
94
|
-
page = Wiki::Api::Page.new name: @page_name
|
95
|
-
headlines = page.headlines
|
96
|
-
assert !headlines.empty?, "expected headlines"
|
97
|
-
assert headlines.size > 1, "expected more than one headline"
|
98
|
-
headlines.each do |headline|
|
99
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
100
|
-
block = headline.block
|
101
|
-
assert block.is_a?(Wiki::Api::PageBlock), "expected block object"
|
102
|
-
list_items = block.list_items
|
103
|
-
assert list_items.is_a?(Array), "expected array"
|
104
|
-
list_items.each do |list_item|
|
105
|
-
assert list_item.is_a?(Wiki::Api::PageListItem), "expected list item object"
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
# test links within page blocks
|
111
|
-
def test_page_block_links
|
112
|
-
page = Wiki::Api::Page.new name: @page_name
|
113
|
-
headlines = page.headlines
|
114
|
-
assert !headlines.empty?, "expected headlines"
|
115
|
-
assert headlines.size > 1, "expected more than one headline"
|
116
|
-
headlines.each do |headline|
|
117
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
118
|
-
block = headline.block
|
119
|
-
assert block.is_a?(Wiki::Api::PageBlock), "expected block object"
|
120
|
-
links = block.links
|
121
|
-
assert links.is_a?(Array), "expected array"
|
122
|
-
links.each do |link|
|
123
|
-
assert link.is_a?(Wiki::Api::PageLink), "expected link object"
|
124
|
-
assert link.uri.is_a?(URI), "expected uri object"
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
# test links within list items
|
130
|
-
def test_page_block_list_inner_links
|
131
|
-
page = Wiki::Api::Page.new name: @page_name
|
132
|
-
headlines = page.headlines
|
133
|
-
assert !headlines.empty?, "expected headlines"
|
134
|
-
assert headlines.size > 1, "expected more than one headline"
|
135
|
-
headlines.each do |headline|
|
136
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
137
|
-
block = headline.block
|
138
|
-
assert block.is_a?(Wiki::Api::PageBlock), "expected block object"
|
139
|
-
list_items = block.list_items
|
140
|
-
assert list_items.is_a?(Array), "expected array"
|
141
|
-
list_items.each do |list_item|
|
142
|
-
assert list_item.is_a?(Wiki::Api::PageListItem), "expected list item object"
|
143
|
-
links = list_item.links
|
144
|
-
links.each do |link|
|
145
|
-
assert link.is_a?(Wiki::Api::PageLink), "expected link object"
|
146
|
-
assert link.uri.is_a?(URI), "expected uri object"
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
# test single headline invocation
|
153
|
-
def test_page_invocation_single
|
154
|
-
page = Wiki::Api::Page.new name: @page_name
|
155
|
-
headlines = page.headlines
|
156
|
-
assert !headlines.empty?, "expected headlines"
|
157
|
-
assert headlines.size > 1, "expected more than one headline"
|
158
|
-
|
159
|
-
# collect headline names
|
160
|
-
hs = []
|
161
|
-
headlines.each do |headline|
|
162
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
163
|
-
hs << headline.name
|
164
|
-
end
|
165
|
-
|
166
|
-
# query every headline manually
|
167
|
-
hs.each do |h|
|
168
|
-
# test headline query
|
169
|
-
headlines = page.headline h
|
170
|
-
# test for at least one (many indicates multiple headlines with the same name)
|
171
|
-
assert !headlines.empty?, "expected a list of headlines"
|
172
|
-
assert headlines.size == 1, "expected one headline"
|
173
|
-
headlines.each do |headline|
|
174
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
def test_page_headline_search_downcase
|
180
|
-
page = Wiki::Api::Page.new name: @page_name
|
181
|
-
|
182
|
-
headlines = page.headline "Editing_Wiktionary"
|
183
|
-
assert !headlines.empty?, "expected headlines"
|
184
|
-
assert headlines.size == 1, "expected one headline"
|
185
|
-
|
186
|
-
|
187
|
-
# iterate headlines
|
188
|
-
headlines.each do |headline|
|
189
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
190
|
-
end
|
191
|
-
|
192
|
-
# search downcase
|
193
|
-
headlines = page.headline "editing_wiktionary"
|
194
|
-
assert !headlines.empty?, "expected headlines"
|
195
|
-
|
196
|
-
# iterate headlines
|
197
|
-
headlines.each do |headline|
|
198
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
199
|
-
end
|
200
|
-
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_page_headline_search_regular
|
204
|
-
page = Wiki::Api::Page.new name: @page_name
|
205
|
-
|
206
|
-
headlines = page.headline "Editing_Wiktionary"
|
207
|
-
assert !headlines.empty?, "expected headlines"
|
208
|
-
assert headlines.size == 1, "expected one headline"
|
209
|
-
|
210
|
-
# iterate headlines
|
211
|
-
headlines.each do |headline|
|
212
|
-
assert headline.is_a?(Wiki::Api::PageHeadline), "expected headline object"
|
213
|
-
end
|
214
|
-
|
215
|
-
# search downcase
|
216
|
-
headlines = page.headline "editing_wiktionary"
|
217
|
-
assert headlines.size == 1, "expected one headline"
|
218
|
-
|
219
|
-
# search downcase with spaces
|
220
|
-
headlines = page.headline "editing wiktionary"
|
221
|
-
assert headlines.size == 1, "expected one headline"
|
222
|
-
|
223
|
-
# search idiot case with spaces
|
224
|
-
headlines = page.headline "eDiTinG wiKtiOnarY"
|
225
|
-
assert headlines.size == 1, "expected one headline"
|
226
|
-
|
227
|
-
end
|
228
|
-
|
229
|
-
end
|