unapi 0.0.4 → 0.0.5
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.
- data/lib/unapi/page.rb +6 -6
- data/lib/unapi/validator.rb +74 -54
- metadata +2 -2
data/lib/unapi/page.rb
CHANGED
@@ -6,11 +6,11 @@ require 'unapi/utils'
|
|
6
6
|
module UnAPI
|
7
7
|
|
8
8
|
class Page
|
9
|
-
attr_reader :status_code, :document
|
9
|
+
attr_reader :status_code, :document, :uri
|
10
10
|
|
11
11
|
# initialize the UnAPI::URI object with a web page url
|
12
12
|
def initialize(url)
|
13
|
-
@
|
13
|
+
@uri = URI.parse(url)
|
14
14
|
@status_code, @document = Utils.get_html_document(url)
|
15
15
|
end
|
16
16
|
|
@@ -23,12 +23,12 @@ module UnAPI
|
|
23
23
|
end
|
24
24
|
return nil if not link_url
|
25
25
|
|
26
|
-
# if the host isn't mentioned then we'll assume relative to
|
26
|
+
# if the host isn't mentioned then we'll assume relative to @uri
|
27
27
|
service_uri = URI.parse(link_url)
|
28
28
|
if service_uri.relative?
|
29
|
-
service_uri.host = @
|
30
|
-
service_uri.port = @
|
31
|
-
service_uri.scheme = @
|
29
|
+
service_uri.host = @uri.host
|
30
|
+
service_uri.port = @uri.port
|
31
|
+
service_uri.scheme = @uri.scheme
|
32
32
|
end
|
33
33
|
|
34
34
|
# if they included a ? let's get rid of that
|
data/lib/unapi/validator.rb
CHANGED
@@ -4,13 +4,17 @@ require 'unapi'
|
|
4
4
|
|
5
5
|
module UnAPI
|
6
6
|
|
7
|
-
class Message
|
8
|
-
attr_accessor :url
|
7
|
+
class Message
|
8
|
+
attr_accessor :msg, :value, :url
|
9
9
|
|
10
|
-
def initialize(
|
11
|
-
|
10
|
+
def initialize(msg, value=nil, url=nil)
|
11
|
+
@msg = msg
|
12
|
+
@value = value
|
12
13
|
@url = url
|
13
|
-
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
return @msg
|
14
18
|
end
|
15
19
|
end
|
16
20
|
|
@@ -32,39 +36,39 @@ module UnAPI
|
|
32
36
|
@warnings = 0
|
33
37
|
end
|
34
38
|
|
35
|
-
def test(ok,
|
39
|
+
def test(ok, test_msg, value=nil, url=nil)
|
36
40
|
if ok
|
37
|
-
pass(
|
41
|
+
pass(test_msg, value, url)
|
38
42
|
else
|
39
|
-
fail(
|
43
|
+
fail(test_msg, value, url)
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
43
|
-
def check(ok,
|
47
|
+
def check(ok, test_msg, value=nil, url=nil)
|
44
48
|
if ok
|
45
|
-
pass(
|
49
|
+
pass(test_msg, value, url)
|
46
50
|
else
|
47
|
-
warn(
|
51
|
+
warn(test_msg, value, url)
|
48
52
|
end
|
49
53
|
end
|
50
54
|
|
51
|
-
def pass(
|
55
|
+
def pass(test_msg, value=nil, url=nil)
|
52
56
|
@passes += 1
|
53
|
-
handle Pass.new(
|
57
|
+
handle Pass.new(test_msg, value, url)
|
54
58
|
end
|
55
59
|
|
56
|
-
def fail(
|
60
|
+
def fail(test_msg, value=nil, url=nil)
|
57
61
|
@failures += 1
|
58
|
-
handle Fail.new(
|
62
|
+
handle Fail.new(test_msg, value, url)
|
59
63
|
end
|
60
64
|
|
61
|
-
def warn(
|
65
|
+
def warn(test_msg, value=nil, url=nil)
|
62
66
|
@warnings += 1
|
63
|
-
handle Warn.new(
|
67
|
+
handle Warn.new(test_msg, value, url)
|
64
68
|
end
|
65
69
|
|
66
70
|
def count
|
67
|
-
return @passes + @failures
|
71
|
+
return @passes + @failures + @warnings
|
68
72
|
end
|
69
73
|
end
|
70
74
|
|
@@ -78,8 +82,8 @@ module UnAPI
|
|
78
82
|
@filehandle.print "#{count}: "
|
79
83
|
case msg
|
80
84
|
when Pass: @filehandle.print("PASS: #{msg}\n")
|
81
|
-
when Fail: @filehandle.print("FAIL: #{msg} #{msg.
|
82
|
-
when Warn: @filehandle.print("WARN: #{msg}\n")
|
85
|
+
when Fail: @filehandle.print("FAIL: #{msg} [found #{msg.value}]\n")
|
86
|
+
when Warn: @filehandle.print("WARN: #{msg} [found #{msg.value}]\n")
|
83
87
|
end
|
84
88
|
end
|
85
89
|
end
|
@@ -112,10 +116,10 @@ module UnAPI
|
|
112
116
|
# make sure there is a service url
|
113
117
|
service_url = page.service_url
|
114
118
|
@handler.test(
|
115
|
-
service_url,
|
116
|
-
"<link> url for unapi service",
|
119
|
+
service_url != nil,
|
120
|
+
"page should have <link> url for unapi service",
|
117
121
|
service_url,
|
118
|
-
|
122
|
+
service_url)
|
119
123
|
|
120
124
|
# get the unapi service from the page
|
121
125
|
service = page.service
|
@@ -129,18 +133,18 @@ module UnAPI
|
|
129
133
|
end
|
130
134
|
|
131
135
|
def check_uris(page)
|
132
|
-
# look for unap-uris on the page
|
133
136
|
service = page.service
|
134
|
-
if not service
|
135
|
-
@handler.fail "couldn't find service"
|
136
|
-
end
|
137
|
+
return if not service
|
137
138
|
|
139
|
+
# look for unap-uris on the page
|
138
140
|
uris = page.uris
|
139
|
-
@handler.test uris.length > 0,
|
141
|
+
@handler.test uris.length > 0,
|
142
|
+
"page should > 0 elements with class unapi-uri",
|
143
|
+
uris.length,
|
144
|
+
page.uri
|
140
145
|
|
141
146
|
# go through each identifier
|
142
147
|
uris.each do |uri|
|
143
|
-
@handler.pass "got unapi-uri #{uri}"
|
144
148
|
|
145
149
|
# verify it has formats available
|
146
150
|
formats = service.formats_for_uri(uri)
|
@@ -149,61 +153,77 @@ module UnAPI
|
|
149
153
|
# request an invalid format
|
150
154
|
content = service.get_uri_in_format(uri, 'thisformatdoesnotexist')
|
151
155
|
@handler.check service.status_code == 415,
|
152
|
-
"request for uri #{uri} with bad format
|
156
|
+
"request for uri #{uri} with bad format should return with " +
|
157
|
+
"status code 415",
|
158
|
+
service.status_code,
|
159
|
+
service.last_url
|
153
160
|
|
154
161
|
# verify that each format is available
|
155
162
|
content = ''
|
156
163
|
formats.each do |format|
|
157
164
|
content = service.get_uri_in_format(uri, format.name)
|
158
165
|
@handler.check service.status_code == 200,
|
159
|
-
"request for #{uri} content
|
166
|
+
"request for #{uri} content should return with 200 status code",
|
167
|
+
service.status_code,
|
160
168
|
service.last_url
|
161
169
|
@handler.test((content != nil and content.length > 0),
|
162
|
-
"request for #{uri}
|
170
|
+
"request for #{uri} should return data",
|
171
|
+
"#{content.length} bytes",
|
163
172
|
service.last_url)
|
164
|
-
@handler.test service.content_type
|
165
|
-
"request for #{uri}
|
173
|
+
@handler.test service.content_type.include?(format.type),
|
174
|
+
"request for #{uri} should return with content-type #{format.type}",
|
175
|
+
service.content_type,
|
166
176
|
service.last_url
|
167
177
|
|
168
178
|
# request an invalid uri with a valid format
|
169
179
|
service.get_uri_in_format('invaliduriinvaliduri', format.name)
|
170
180
|
@handler.check service.status_code == 404,
|
171
181
|
"request for invalid uri with valid format #{format.name} " +
|
172
|
-
"
|
182
|
+
"should return with 404 status code",
|
183
|
+
service.status_code,
|
184
|
+
service.last_url
|
173
185
|
end
|
174
186
|
end
|
175
187
|
end
|
176
188
|
|
177
189
|
def check_formats(formats, service, target)
|
178
|
-
@handler.test service.content_type
|
179
|
-
"formats for #{target}
|
180
|
-
|
190
|
+
@handler.test service.content_type.include?('application/xml'),
|
191
|
+
"formats request for #{target} should return with content-type "+
|
192
|
+
"application/xml",
|
193
|
+
service.content_type,
|
194
|
+
service.last_url
|
181
195
|
|
182
196
|
if target == 'unapi service'
|
183
197
|
@handler.check service.status_code == 200,
|
184
|
-
"formats request for #{target}
|
198
|
+
"formats request for #{target} should return with 200 status code",
|
199
|
+
service.status_code,
|
185
200
|
service.last_url
|
186
201
|
else
|
187
202
|
@handler.check service.status_code == 300,
|
188
|
-
"formats request for #{target} return 300 status code",
|
203
|
+
"formats request for #{target} should return with 300 status code",
|
204
|
+
service.status_code,
|
189
205
|
service.last_url
|
190
206
|
end
|
191
207
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
formats.
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
208
|
+
# make sure there are some formats
|
209
|
+
@handler.test formats.length > 0,
|
210
|
+
"formats request for #{target} should return > 0 formats",
|
211
|
+
formats.length,
|
212
|
+
service.last_url
|
213
|
+
|
214
|
+
# examine each format
|
215
|
+
count = 0
|
216
|
+
formats.each do |format|
|
217
|
+
count += 1
|
218
|
+
@handler.test format.name,
|
219
|
+
"format #{count} for #{target} should have a name",
|
220
|
+
format.name,
|
221
|
+
service.last_url
|
222
|
+
@handler.test format.type,
|
223
|
+
"format #{count} for #{target} should have a type",
|
224
|
+
format.type,
|
225
|
+
service.last_url
|
204
226
|
end
|
205
227
|
end
|
206
|
-
|
207
228
|
end
|
208
229
|
end
|
209
|
-
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: unapi
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2006-
|
6
|
+
version: 0.0.5
|
7
|
+
date: 2006-04-30 00:00:00 -05:00
|
8
8
|
summary: A library for working with the unapi protocol
|
9
9
|
require_paths:
|
10
10
|
- lib
|