kronk 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/History.rdoc +22 -0
- data/Manifest.txt +15 -6
- data/README.rdoc +5 -6
- data/Rakefile +5 -5
- data/lib/kronk.rb +164 -194
- data/lib/kronk/cmd.rb +188 -74
- data/lib/kronk/constants.rb +90 -0
- data/lib/kronk/data_renderer.rb +146 -0
- data/lib/kronk/diff.rb +4 -92
- data/lib/kronk/path/transaction.rb +2 -0
- data/lib/kronk/player.rb +233 -0
- data/lib/kronk/player/benchmark.rb +261 -0
- data/lib/kronk/player/input_reader.rb +54 -0
- data/lib/kronk/player/output.rb +49 -0
- data/lib/kronk/player/request_parser.rb +24 -0
- data/lib/kronk/player/stream.rb +50 -0
- data/lib/kronk/player/suite.rb +123 -0
- data/lib/kronk/plist_parser.rb +4 -0
- data/lib/kronk/request.rb +265 -241
- data/lib/kronk/response.rb +330 -149
- data/lib/kronk/test/assertions.rb +2 -2
- data/lib/kronk/xml_parser.rb +7 -1
- data/test/mocks/cookies.yml +32 -0
- data/test/mocks/get_request.txt +6 -0
- data/test/test_assertions.rb +6 -6
- data/test/test_cmd.rb +708 -0
- data/test/test_diff.rb +210 -75
- data/test/test_helper.rb +140 -0
- data/test/test_helper_methods.rb +4 -4
- data/test/test_input_reader.rb +103 -0
- data/test/test_kronk.rb +142 -141
- data/test/test_player.rb +589 -0
- data/test/test_request.rb +147 -212
- data/test/test_request_parser.rb +31 -0
- data/test/test_response.rb +206 -15
- metadata +41 -74
- data/bin/yzma +0 -13
- data/lib/kronk/data_set.rb +0 -144
- data/lib/yzma.rb +0 -174
- data/lib/yzma/randomizer.rb +0 -54
- data/lib/yzma/report.rb +0 -47
- data/test/test_data_set.rb +0 -213
data/test/test_request.rb
CHANGED
@@ -2,173 +2,129 @@ require 'test/test_helper'
|
|
2
2
|
|
3
3
|
class TestRequest < Test::Unit::TestCase
|
4
4
|
|
5
|
-
def
|
6
|
-
|
7
|
-
|
5
|
+
def test_parse
|
6
|
+
raw = "POST /foobar\r\nAccept: json\r\nHost: example.com\r\n\r\nfoo=bar"
|
7
|
+
req = Kronk::Request.parse(raw)
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
assert_equal Kronk::Request, req.class
|
10
|
+
assert_equal URI.parse("http://example.com/foobar"), req.uri
|
11
|
+
assert_equal "json", req.headers['Accept']
|
12
|
+
assert_equal "foo=bar", req.body
|
13
13
|
end
|
14
14
|
|
15
15
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
Kronk::Request.follow_redirect resp, options
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
def test_follow_redirect?
|
29
|
-
resp = mock "resp"
|
30
|
-
resp.expects(:code).returns "300"
|
31
|
-
|
32
|
-
assert Kronk::Request.follow_redirect?(resp, true)
|
33
|
-
|
34
|
-
resp = mock "resp"
|
35
|
-
resp.expects(:code).returns "300"
|
36
|
-
|
37
|
-
assert Kronk::Request.follow_redirect?(resp, 1)
|
16
|
+
def test_parse_invalid
|
17
|
+
assert_raises Kronk::Request::ParseError do
|
18
|
+
Kronk::Request.parse "thing\nfoo\n"
|
19
|
+
end
|
20
|
+
assert_raises Kronk::Request::ParseError do
|
21
|
+
Kronk::Request.parse ""
|
22
|
+
end
|
38
23
|
end
|
39
24
|
|
40
25
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
26
|
+
def test_parse_to_hash
|
27
|
+
expected = {:uri_suffix => "/foobar"}
|
28
|
+
assert_equal expected, Kronk::Request.parse_to_hash("/foobar")
|
44
29
|
|
45
|
-
|
30
|
+
expected = {:http_method => "GET", :uri_suffix => "/foobar"}
|
31
|
+
assert_equal expected, Kronk::Request.parse_to_hash("GET /foobar")
|
46
32
|
|
47
|
-
|
48
|
-
|
33
|
+
expected.merge! :host => "example.com"
|
34
|
+
raw = "GET /foobar\r\nHost: example.com"
|
35
|
+
assert_equal expected, Kronk::Request.parse_to_hash(raw)
|
49
36
|
|
50
|
-
|
37
|
+
expected.merge! :http_method => "POST",
|
38
|
+
:data => "foo=bar",
|
39
|
+
:headers => {'Accept' => 'json'}
|
51
40
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
assert !Kronk::Request.follow_redirect?(resp, true)
|
41
|
+
raw = "POST /foobar\r\nAccept: json\r\nHost: example.com\r\n\r\nfoo=bar"
|
42
|
+
assert_equal expected, Kronk::Request.parse_to_hash(raw)
|
56
43
|
end
|
57
44
|
|
58
45
|
|
59
|
-
def
|
60
|
-
|
61
|
-
|
62
|
-
Kronk::Request.expects(:retrieve_uri).with query, options
|
63
|
-
|
64
|
-
Kronk::Request.retrieve query, options
|
46
|
+
def test_parse_to_hash_invalid
|
47
|
+
assert_nil Kronk::Request.parse_to_hash("thing\nfoo\n")
|
48
|
+
assert_nil Kronk::Request.parse_to_hash("")
|
65
49
|
end
|
66
50
|
|
67
51
|
|
68
|
-
def
|
69
|
-
|
70
|
-
|
71
|
-
File.expects(:file?).with(query).returns true
|
72
|
-
Kronk::Request.expects(:retrieve_file).with query, options
|
73
|
-
|
74
|
-
Kronk::Request.retrieve query, options
|
75
|
-
end
|
52
|
+
def test_retrieve_post
|
53
|
+
expect_request "POST", "http://example.com/request/path?foo=bar",
|
54
|
+
:data => {'test' => 'thing'}, :headers => {'X-THING' => 'thing'}
|
76
55
|
|
56
|
+
resp = Kronk::Request.new("http://example.com/request/path?foo=bar",
|
57
|
+
:data => 'test=thing', :headers => {'X-THING' => 'thing'},
|
58
|
+
:http_method => :post).retrieve
|
77
59
|
|
78
|
-
def test_retrieve_file
|
79
|
-
resp = Kronk::Request.retrieve_file "test/mocks/200_response.txt"
|
80
60
|
assert_equal mock_200_response, resp.raw
|
81
|
-
assert_equal "200", resp.code
|
82
61
|
end
|
83
62
|
|
84
63
|
|
85
|
-
def
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
resp = Kronk::Request.retrieve_file "test/mocks/301_response.txt",
|
90
|
-
:follow_redirects => true
|
91
|
-
|
92
|
-
assert_equal mock_200_response, resp.raw
|
93
|
-
assert_equal "200", resp.code
|
64
|
+
def test_build_uri
|
65
|
+
uri = Kronk::Request.build_uri "https://example.com"
|
66
|
+
assert_equal URI.parse("https://example.com"), uri
|
94
67
|
end
|
95
68
|
|
96
69
|
|
97
|
-
def
|
98
|
-
|
99
|
-
|
70
|
+
def test_build_uri_string
|
71
|
+
uri = Kronk::Request.build_uri "example.com"
|
72
|
+
assert_equal "http://example.com", uri.to_s
|
100
73
|
end
|
101
74
|
|
102
75
|
|
103
|
-
def
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
Kronk::Request.expects(:follow_redirect).
|
108
|
-
with resp, :follow_redirects => true,
|
109
|
-
:headers => {'User-Agent' => Kronk::USER_AGENTS['kronk']},
|
110
|
-
:timeout => nil
|
111
|
-
|
112
|
-
Kronk::Request.retrieve_uri "http://example.com/request/path?foo=bar",
|
113
|
-
:follow_redirects => true
|
76
|
+
def test_build_uri_localhost
|
77
|
+
uri = Kronk::Request.build_uri "/path/to/resource"
|
78
|
+
assert_equal "http://localhost:3000/path/to/resource", uri.to_s
|
114
79
|
end
|
115
80
|
|
116
81
|
|
117
|
-
def
|
118
|
-
|
119
|
-
|
82
|
+
def test_build_uri_query_hash
|
83
|
+
query = {'a' => '1', 'b' => '2'}
|
84
|
+
uri = Kronk::Request.build_uri "example.com/path", :query => query
|
120
85
|
|
121
|
-
Kronk::Request.
|
122
|
-
with resp, :follow_redirects => 3, :data => {:foo => "bar"},
|
123
|
-
:headers => {'User-Agent' => Kronk::USER_AGENTS['kronk']},
|
124
|
-
:timeout => nil
|
125
|
-
|
126
|
-
Kronk::Request.retrieve_uri "http://example.com/request/path?foo=bar",
|
127
|
-
:follow_redirects => 3, :data => {:foo => "bar"}
|
86
|
+
assert_equal query, Kronk::Request.parse_nested_query(uri.query)
|
128
87
|
end
|
129
88
|
|
130
89
|
|
131
|
-
def
|
132
|
-
|
133
|
-
|
90
|
+
def test_build_uri_query_hash_str
|
91
|
+
query = {'a' => '1', 'b' => '2'}
|
92
|
+
uri = Kronk::Request.build_uri "example.com/path?c=3", :query => query
|
134
93
|
|
135
|
-
|
136
|
-
|
137
|
-
Kronk::Request.retrieve_uri "http://example.com/request/path?foo=bar"
|
94
|
+
assert_equal({'a' => '1', 'b' => '2', 'c' => '3'},
|
95
|
+
Kronk::Request.parse_nested_query(uri.query))
|
138
96
|
end
|
139
97
|
|
140
98
|
|
141
|
-
def
|
142
|
-
|
143
|
-
|
99
|
+
def test_build_uri_suffix
|
100
|
+
uri = Kronk::Request.build_uri "http://example.com/path",
|
101
|
+
:uri_suffix => "/to/resource"
|
144
102
|
|
145
|
-
|
146
|
-
:http_method => :post,
|
147
|
-
:data => {:test => "thing"},
|
148
|
-
:headers => {'X-THING' => 'thing'}
|
103
|
+
assert_equal "http://example.com/path/to/resource", uri.to_s
|
149
104
|
end
|
150
105
|
|
151
106
|
|
152
|
-
def
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
resp = Kronk::Request.call :post, "http://example.com/request/path?foo=bar",
|
157
|
-
:data => 'test=thing', :headers => {'X-THING' => 'thing'}
|
107
|
+
def test_build_uri_from_uri
|
108
|
+
query = {'a' => '1', 'b' => '2'}
|
109
|
+
uri = Kronk::Request.build_uri URI.parse("http://example.com/path"),
|
110
|
+
:query => query, :uri_suffix => "/to/resource"
|
158
111
|
|
159
|
-
assert_equal
|
112
|
+
assert_equal "example.com", uri.host
|
113
|
+
assert_equal "/path/to/resource", uri.path
|
114
|
+
assert_equal query, Kronk::Request.parse_nested_query(uri.query)
|
160
115
|
end
|
161
116
|
|
162
117
|
|
163
|
-
def
|
118
|
+
def test_retrieve_get
|
164
119
|
expect_request "GET", "http://example.com/request/path?foo=bar"
|
165
|
-
resp =
|
120
|
+
resp =
|
121
|
+
Kronk::Request.new("http://example.com/request/path?foo=bar").retrieve
|
166
122
|
|
167
123
|
assert_equal mock_200_response, resp.raw
|
168
124
|
end
|
169
125
|
|
170
126
|
|
171
|
-
def
|
127
|
+
def test_retrieve_cookies
|
172
128
|
Kronk.cookie_jar.expects(:get_cookie_header).
|
173
129
|
with("http://example.com/request/path?foo=bar").returns "mock_cookie"
|
174
130
|
|
@@ -178,24 +134,24 @@ class TestRequest < Test::Unit::TestCase
|
|
178
134
|
expect_request "GET", "http://example.com/request/path?foo=bar",
|
179
135
|
:headers => {'Cookie' => "mock_cookie", 'User-Agent' => "kronk"}
|
180
136
|
|
181
|
-
resp = Kronk::Request.
|
182
|
-
:query => "foo=bar", :headers => {'User-Agent' => "kronk"}
|
137
|
+
resp = Kronk::Request.new("http://example.com/request/path",
|
138
|
+
:query => "foo=bar", :headers => {'User-Agent' => "kronk"}).retrieve
|
183
139
|
end
|
184
140
|
|
185
141
|
|
186
|
-
def
|
142
|
+
def test_retrieve_no_cookies_found
|
187
143
|
Kronk.cookie_jar.expects(:get_cookie_header).
|
188
144
|
with("http://example.com/request/path?foo=bar").returns ""
|
189
145
|
|
190
146
|
expect_request "GET", "http://example.com/request/path?foo=bar",
|
191
147
|
:headers => {'User-Agent' => "kronk"}
|
192
148
|
|
193
|
-
resp = Kronk::Request.
|
194
|
-
:query => "foo=bar", :headers => {'User-Agent' => "kronk"}
|
149
|
+
resp = Kronk::Request.new("http://example.com/request/path",
|
150
|
+
:query => "foo=bar", :headers => {'User-Agent' => "kronk"}).retrieve
|
195
151
|
end
|
196
152
|
|
197
153
|
|
198
|
-
def
|
154
|
+
def test_retrieve_no_cookies
|
199
155
|
Kronk.cookie_jar.expects(:get_cookie_header).
|
200
156
|
with("http://example.com/request/path?foo=bar").never
|
201
157
|
|
@@ -204,13 +160,13 @@ class TestRequest < Test::Unit::TestCase
|
|
204
160
|
expect_request "GET", "http://example.com/request/path?foo=bar",
|
205
161
|
:headers => {'User-Agent' => "kronk"}
|
206
162
|
|
207
|
-
resp = Kronk::Request.
|
163
|
+
resp = Kronk::Request.new("http://example.com/request/path",
|
208
164
|
:query => "foo=bar", :headers => {'User-Agent' => "kronk"},
|
209
|
-
:no_cookies => true
|
165
|
+
:no_cookies => true).retrieve
|
210
166
|
end
|
211
167
|
|
212
168
|
|
213
|
-
def
|
169
|
+
def test_retrieve_no_cookies_config
|
214
170
|
old_config = Kronk.config[:use_cookies]
|
215
171
|
Kronk.config[:use_cookies] = false
|
216
172
|
|
@@ -222,14 +178,14 @@ class TestRequest < Test::Unit::TestCase
|
|
222
178
|
expect_request "GET", "http://example.com/request/path?foo=bar",
|
223
179
|
:headers => {'User-Agent' => "kronk"}
|
224
180
|
|
225
|
-
resp = Kronk::Request.
|
226
|
-
:query => "foo=bar", :headers => {'User-Agent' => "kronk"}
|
181
|
+
resp = Kronk::Request.new("http://example.com/request/path",
|
182
|
+
:query => "foo=bar", :headers => {'User-Agent' => "kronk"}).retrieve
|
227
183
|
|
228
184
|
Kronk.config[:use_cookies] = old_config
|
229
185
|
end
|
230
186
|
|
231
187
|
|
232
|
-
def
|
188
|
+
def test_retrieve_no_cookies_config_override
|
233
189
|
old_config = Kronk.config[:use_cookies]
|
234
190
|
Kronk.config[:use_cookies] = false
|
235
191
|
|
@@ -241,61 +197,77 @@ class TestRequest < Test::Unit::TestCase
|
|
241
197
|
expect_request "GET", "http://example.com/request/path?foo=bar",
|
242
198
|
:headers => {'User-Agent' => "kronk"}
|
243
199
|
|
244
|
-
resp = Kronk::Request.
|
200
|
+
resp = Kronk::Request.new("http://example.com/request/path",
|
245
201
|
:query => "foo=bar", :headers => {'User-Agent' => "kronk"},
|
246
|
-
:no_cookies => false
|
202
|
+
:no_cookies => false).retrieve
|
247
203
|
|
248
204
|
Kronk.config[:use_cookies] = old_config
|
249
205
|
end
|
250
206
|
|
251
207
|
|
252
|
-
def
|
208
|
+
def test_retrieve_cookies_already_set
|
253
209
|
Kronk.cookie_jar.expects(:get_cookie_header).
|
254
210
|
with("http://example.com/request/path?foo=bar").never
|
255
211
|
|
256
212
|
expect_request "GET", "http://example.com/request/path?foo=bar",
|
257
|
-
:headers => {'User-Agent' => "kronk"
|
213
|
+
:headers => {'User-Agent' => "kronk"}
|
258
214
|
|
259
|
-
resp = Kronk::Request.
|
215
|
+
resp = Kronk::Request.new("http://example.com/request/path",
|
260
216
|
:query => "foo=bar",
|
261
217
|
:headers => {'User-Agent' => "kronk", 'Cookie' => "mock_cookie"},
|
262
|
-
:no_cookies => true
|
218
|
+
:no_cookies => true).retrieve
|
263
219
|
end
|
264
220
|
|
265
221
|
|
266
|
-
def
|
222
|
+
def test_retrieve_query
|
267
223
|
expect_request "GET", "http://example.com/path?foo=bar"
|
268
|
-
Kronk::Request.
|
269
|
-
:query => {:foo => :bar}
|
224
|
+
Kronk::Request.new("http://example.com/path",
|
225
|
+
:query => {:foo => :bar}).retrieve
|
270
226
|
end
|
271
227
|
|
272
228
|
|
273
|
-
def
|
229
|
+
def test_retrieve_query_appended
|
274
230
|
expect_request "GET", "http://example.com/path?foo=bar&test=thing"
|
275
|
-
Kronk::Request.
|
276
|
-
:query => {:test => :thing}
|
231
|
+
Kronk::Request.new("http://example.com/path?foo=bar",
|
232
|
+
:query => {:test => :thing}).retrieve
|
277
233
|
end
|
278
234
|
|
279
235
|
|
280
|
-
def
|
236
|
+
def test_retrieve_query_appended_string
|
281
237
|
expect_request "GET", "http://example.com/path?foo=bar&test=thing"
|
282
|
-
Kronk::Request.
|
283
|
-
:query => "test=thing"
|
238
|
+
Kronk::Request.new("http://example.com/path?foo=bar",
|
239
|
+
:query => "test=thing").retrieve
|
240
|
+
end
|
241
|
+
|
242
|
+
|
243
|
+
def test_auth_from_headers
|
244
|
+
req = Kronk::Request.parse File.read("test/mocks/get_request.txt")
|
245
|
+
assert_equal "bob", req.auth[:username]
|
246
|
+
assert_equal "foobar", req.auth[:password]
|
284
247
|
end
|
285
248
|
|
286
249
|
|
287
|
-
def
|
250
|
+
def test_auth_from_headers_and_options
|
251
|
+
req = Kronk::Request.new "http://example.com/path",
|
252
|
+
:headers => {"Authorization" => "Basic Ym9iOmZvb2Jhcg=="},
|
253
|
+
:auth => {:password => "password"}
|
254
|
+
assert_equal "bob", req.auth[:username]
|
255
|
+
assert_equal "password", req.auth[:password]
|
256
|
+
end
|
257
|
+
|
258
|
+
|
259
|
+
def test_retrieve_basic_auth
|
288
260
|
auth_opts = {:username => "user", :password => "pass"}
|
289
261
|
|
290
262
|
expect_request "GET", "http://example.com" do |http, req, resp|
|
291
263
|
req.expects(:basic_auth).with auth_opts[:username], auth_opts[:password]
|
292
264
|
end
|
293
265
|
|
294
|
-
resp = Kronk::Request.
|
266
|
+
resp = Kronk::Request.new("http://example.com", :auth => auth_opts).retrieve
|
295
267
|
end
|
296
268
|
|
297
269
|
|
298
|
-
def
|
270
|
+
def test_retrieve_bad_basic_auth
|
299
271
|
auth_opts = {:password => "pass"}
|
300
272
|
|
301
273
|
expect_request "GET", "http://example.com" do |http, req, resp|
|
@@ -303,81 +275,81 @@ class TestRequest < Test::Unit::TestCase
|
|
303
275
|
never
|
304
276
|
end
|
305
277
|
|
306
|
-
resp = Kronk::Request.
|
278
|
+
resp = Kronk::Request.new("http://example.com", :auth => auth_opts).retrieve
|
307
279
|
end
|
308
280
|
|
309
281
|
|
310
|
-
def
|
282
|
+
def test_retrieve_no_basic_auth
|
311
283
|
expect_request "GET", "http://example.com" do |http, req, resp|
|
312
284
|
req.expects(:basic_auth).never
|
313
285
|
end
|
314
286
|
|
315
|
-
resp = Kronk::Request.
|
287
|
+
resp = Kronk::Request.new("http://example.com").retrieve
|
316
288
|
end
|
317
289
|
|
318
290
|
|
319
|
-
def
|
291
|
+
def test_retrieve_ssl
|
320
292
|
expr = expect_request "GET", "https://example.com" do |http, req, resp|
|
321
293
|
req.expects(:use_ssl=).with true
|
322
294
|
end
|
323
295
|
|
324
|
-
resp = Kronk::Request.
|
296
|
+
resp = Kronk::Request.new("https://example.com").retrieve
|
325
297
|
|
326
298
|
assert_equal mock_200_response, resp.raw
|
327
299
|
end
|
328
300
|
|
329
301
|
|
330
|
-
def
|
302
|
+
def test_retrieve_no_ssl
|
331
303
|
expect_request "GET", "http://example.com" do |http, req, resp|
|
332
304
|
req.expects(:use_ssl=).with(true).never
|
333
305
|
end
|
334
306
|
|
335
|
-
resp = Kronk::Request.
|
307
|
+
resp = Kronk::Request.new("http://example.com").retrieve
|
336
308
|
|
337
309
|
assert_equal mock_200_response, resp.raw
|
338
310
|
end
|
339
311
|
|
340
312
|
|
341
|
-
def
|
313
|
+
def test_retrieve_user_agent_default
|
342
314
|
expect_request "GET", "http://example.com",
|
343
315
|
:headers => {
|
344
316
|
'User-Agent' =>
|
345
317
|
"Kronk/#{Kronk::VERSION} (http://github.com/yaksnrainbows/kronk)"
|
346
318
|
}
|
347
319
|
|
348
|
-
resp = Kronk::Request.
|
320
|
+
resp = Kronk::Request.new("http://example.com").retrieve
|
349
321
|
end
|
350
322
|
|
351
323
|
|
352
|
-
def
|
324
|
+
def test_retrieve_user_agent_alias
|
353
325
|
expect_request "GET", "http://example.com",
|
354
326
|
:headers => {'User-Agent' => "Mozilla/5.0 (compatible; Konqueror/3; Linux)"}
|
355
327
|
|
356
|
-
resp = Kronk::Request.
|
357
|
-
:user_agent => 'linux_konqueror'
|
328
|
+
resp = Kronk::Request.new("http://example.com",
|
329
|
+
:user_agent => 'linux_konqueror').retrieve
|
358
330
|
end
|
359
331
|
|
360
332
|
|
361
|
-
def
|
333
|
+
def test_retrieve_user_agent_custom
|
362
334
|
expect_request "GET", "http://example.com",
|
363
335
|
:headers => {'User-Agent' => "custom user agent"}
|
364
336
|
|
365
|
-
resp = Kronk::Request.
|
366
|
-
:user_agent => 'custom user agent'
|
337
|
+
resp = Kronk::Request.new("http://example.com",
|
338
|
+
:user_agent => 'custom user agent').retrieve
|
367
339
|
end
|
368
340
|
|
369
341
|
|
370
|
-
def
|
342
|
+
def test_retrieve_user_agent_header_already_set
|
371
343
|
expect_request "GET", "http://example.com",
|
372
344
|
:headers => {'User-Agent' => "custom user agent"}
|
373
345
|
|
374
|
-
resp = Kronk::Request.
|
346
|
+
resp = Kronk::Request.new("http://example.com",
|
375
347
|
:user_agent => 'mac_safari',
|
376
|
-
:headers => {'User-Agent' => "custom user agent"}
|
348
|
+
:headers => {'User-Agent' => "custom user agent"}).retrieve
|
377
349
|
end
|
378
350
|
|
379
351
|
|
380
|
-
def
|
352
|
+
def test_retrieve_proxy
|
381
353
|
proxy = {
|
382
354
|
:address => "proxy.com",
|
383
355
|
:username => "john",
|
@@ -389,11 +361,11 @@ class TestRequest < Test::Unit::TestCase
|
|
389
361
|
Net::HTTP.expects(:Proxy).with("proxy.com", 8080, "john", "smith").
|
390
362
|
returns Net::HTTP
|
391
363
|
|
392
|
-
Kronk::Request.
|
364
|
+
Kronk::Request.new("http://example.com", :proxy => proxy).retrieve
|
393
365
|
end
|
394
366
|
|
395
367
|
|
396
|
-
def
|
368
|
+
def test_retrieve_proxy_string
|
397
369
|
proxy = "proxy.com:8888"
|
398
370
|
|
399
371
|
expect_request "GET", "http://example.com"
|
@@ -401,17 +373,17 @@ class TestRequest < Test::Unit::TestCase
|
|
401
373
|
Net::HTTP.expects(:Proxy).with("proxy.com", "8888", nil, nil).
|
402
374
|
returns Net::HTTP
|
403
375
|
|
404
|
-
Kronk::Request.
|
376
|
+
Kronk::Request.new("http://example.com", :proxy => proxy).retrieve
|
405
377
|
end
|
406
378
|
|
407
379
|
|
408
380
|
def test_proxy_nil
|
409
|
-
assert_equal Net::HTTP, Kronk::Request.
|
381
|
+
assert_equal Net::HTTP, Kronk::Request.new("host.com").use_proxy(nil)
|
410
382
|
end
|
411
383
|
|
412
384
|
|
413
385
|
def test_proxy_string
|
414
|
-
proxy_class = Kronk::Request.
|
386
|
+
proxy_class = Kronk::Request.new("host.com").use_proxy("myproxy.com:80")
|
415
387
|
|
416
388
|
assert_equal "myproxy.com",
|
417
389
|
proxy_class.instance_variable_get("@proxy_address")
|
@@ -424,7 +396,7 @@ class TestRequest < Test::Unit::TestCase
|
|
424
396
|
|
425
397
|
|
426
398
|
def test_proxy_no_port
|
427
|
-
proxy_class = Kronk::Request.
|
399
|
+
proxy_class = Kronk::Request.new("host.com").use_proxy("myproxy.com")
|
428
400
|
|
429
401
|
assert_equal "myproxy.com",
|
430
402
|
proxy_class.instance_variable_get("@proxy_address")
|
@@ -437,10 +409,13 @@ class TestRequest < Test::Unit::TestCase
|
|
437
409
|
|
438
410
|
|
439
411
|
def test_proxy_hash
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
412
|
+
req = Kronk::Request.new "http://example.com",
|
413
|
+
:proxy => { :address => "myproxy.com",
|
414
|
+
:port => 8080,
|
415
|
+
:username => "john",
|
416
|
+
:password => "smith" }
|
417
|
+
|
418
|
+
proxy_class = req.instance_variable_get "@HTTP"
|
444
419
|
|
445
420
|
assert_equal "myproxy.com",
|
446
421
|
proxy_class.instance_variable_get("@proxy_address")
|
@@ -484,44 +459,4 @@ class TestRequest < Test::Unit::TestCase
|
|
484
459
|
assert_equal "some/path", req.path
|
485
460
|
assert_equal "vanilla kronk", req['User-Agent']
|
486
461
|
end
|
487
|
-
|
488
|
-
|
489
|
-
private
|
490
|
-
|
491
|
-
def expect_request req_method, url, options={}
|
492
|
-
uri = URI.parse url
|
493
|
-
|
494
|
-
resp_io = StringIO.new(mock_200_response)
|
495
|
-
resp = Kronk::Response.read_new resp_io #mock 'resp'
|
496
|
-
resp.stubs(:code).returns(options[:status] || '200')
|
497
|
-
resp.stubs(:to_hash).returns Hash.new
|
498
|
-
|
499
|
-
http = mock 'http'
|
500
|
-
socket = mock 'socket'
|
501
|
-
req = mock 'req'
|
502
|
-
|
503
|
-
data = options[:data]
|
504
|
-
data &&= Hash === data ? Kronk::Request.build_query(data) : data.to_s
|
505
|
-
|
506
|
-
headers = options[:headers] || Hash.new
|
507
|
-
headers['User-Agent'] ||= Kronk.config[:user_agents]['kronk']
|
508
|
-
|
509
|
-
socket.expects(:debug_output=)
|
510
|
-
|
511
|
-
Kronk::Request::VanillaRequest.expects(:new).
|
512
|
-
with(req_method, uri.request_uri, headers).returns req
|
513
|
-
|
514
|
-
http.expects(:request).with(req, data).returns resp
|
515
|
-
|
516
|
-
http.expects(:instance_variable_get).with("@socket").returns socket
|
517
|
-
|
518
|
-
Net::HTTP.expects(:new).with(uri.host, uri.port).returns req
|
519
|
-
req.expects(:start).yields(http).returns resp
|
520
|
-
|
521
|
-
resp.expects(:read_raw_from).returns [nil, mock_200_response, nil]
|
522
|
-
|
523
|
-
yield http, req, resp if block_given?
|
524
|
-
|
525
|
-
resp
|
526
|
-
end
|
527
462
|
end
|