rufus-verbs 0.10 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,43 +7,41 @@
7
7
  # Wed Jan 16 13:54:36 JST 2008
8
8
  #
9
9
 
10
- require 'test/unit'
11
- require 'testbase'
12
10
 
13
- require 'rufus/verbs'
11
+ require File.dirname(__FILE__) + '/base.rb'
14
12
 
15
13
 
16
14
  class ConditionalTest < Test::Unit::TestCase
17
- include TestBaseMixin
15
+ include TestBaseMixin
18
16
 
19
- include Rufus::Verbs
17
+ include Rufus::Verbs
20
18
 
21
19
 
22
- def test_1
20
+ def test_1
23
21
 
24
- ep = ConditionalEndPoint.new(:host => "localhost", :port => 7777)
25
- expect 200, {}, ep.get(:resource => "items")
22
+ ep = ConditionalEndPoint.new(:host => "localhost", :port => 7777)
23
+ expect 200, {}, ep.get(:resource => "items")
26
24
 
27
- res = ep.put :resource => "items", :id => 0 do
28
- "blockdata"
29
- end
30
- assert_equal 404, res.code.to_i
25
+ res = ep.put :resource => "items", :id => 0 do
26
+ "blockdata"
27
+ end
28
+ assert_equal 404, res.code.to_i
31
29
 
32
- res = ep.post :resource => "items", :id => 0 do
33
- "blockdata"
34
- end
35
- assert_equal 201, res.code.to_i
36
- assert_equal "http://localhost:7777/items/0", res['Location']
30
+ res = ep.post :resource => "items", :id => 0 do
31
+ "blockdata"
32
+ end
33
+ assert_equal 201, res.code.to_i
34
+ assert_equal "http://localhost:7777/items/0", res['Location']
37
35
 
38
- res = expect 200, { 0 => "blockdata" }, ep.get(:res => "items")
39
- assert_kind_of Net::HTTPResponse, res
40
- assert_respond_to res, :lastmod
41
- i = res.object_id
42
- #p res.to_hash
36
+ res = expect 200, { 0 => "blockdata" }, ep.get(:res => "items")
37
+ assert_kind_of Net::HTTPResponse, res
38
+ assert_respond_to res, :lastmod
39
+ i = res.object_id
40
+ #p res.to_hash
43
41
 
44
- res = expect 200, { 0 => "blockdata" }, ep.get(:res => "items")
45
- assert_equal i, res.object_id
42
+ res = expect 200, { 0 => "blockdata" }, ep.get(:res => "items")
43
+ assert_equal i, res.object_id
46
44
 
47
- assert_equal 1, ep.cache_current_size
48
- end
45
+ assert_equal 1, ep.cache_current_size
46
+ end
49
47
  end
@@ -7,139 +7,137 @@
7
7
  # Sat Jan 19 18:22:48 JST 2008
8
8
  #
9
9
 
10
- require 'test/unit'
11
- #require 'testbase'
12
10
 
13
- require 'rufus/verbs'
14
- require 'rufus/verbs/cookies'
11
+ require File.dirname(__FILE__) + '/base.rb'
12
+ #require 'rufus/verbs/cookies'
15
13
 
16
14
 
17
15
  class Cookie0Test < Test::Unit::TestCase
18
- #include TestBaseMixin
16
+ #include TestBaseMixin
19
17
 
20
- include Rufus::Verbs::CookieMixin
21
- include Rufus::Verbs::HostMixin
18
+ include Rufus::Verbs::CookieMixin
19
+ include Rufus::Verbs::HostMixin
22
20
 
23
- #
24
- # testing split_host(s)
25
- #
26
- def test_0
21
+ #
22
+ # testing split_host(s)
23
+ #
24
+ def test_0
27
25
 
28
- assert_equal [ 'localhost', nil ], split_host('localhost')
29
- assert_equal [ 'benz', '.car.co.nz' ], split_host('benz.car.co.nz')
30
- assert_equal [ '127.0.0.1', nil ], split_host('127.0.0.1')
31
- assert_equal [ '::1', nil ], split_host('::1')
32
- end
26
+ assert_equal [ 'localhost', nil ], split_host('localhost')
27
+ assert_equal [ 'benz', '.car.co.nz' ], split_host('benz.car.co.nz')
28
+ assert_equal [ '127.0.0.1', nil ], split_host('127.0.0.1')
29
+ assert_equal [ '::1', nil ], split_host('::1')
30
+ end
33
31
 
34
- #
35
- # testing the CookieJar
36
- #
37
- def test_1
32
+ #
33
+ # testing the CookieJar
34
+ #
35
+ def test_1
38
36
 
39
- cookie0 = TestCookie.new
40
- cookie1 = TestCookie.new
37
+ cookie0 = TestCookie.new
38
+ cookie1 = TestCookie.new
41
39
 
42
- jar = Rufus::Verbs::CookieJar.new 77
43
- assert_equal 0, jar.size
40
+ jar = Rufus::Verbs::CookieJar.new 77
41
+ assert_equal 0, jar.size
44
42
 
45
- jar.add_cookie(".rubyforge.org", "/", cookie0)
46
- assert_equal 1, jar.size
47
- assert_equal [ cookie0 ], jar.fetch_cookies("rufus.rubyforge.org", "/main")
43
+ jar.add_cookie(".rubyforge.org", "/", cookie0)
44
+ assert_equal 1, jar.size
45
+ assert_equal [ cookie0 ], jar.fetch_cookies("rufus.rubyforge.org", "/main")
48
46
 
49
- jar.add_cookie("rufus.rubyforge.org", "/sub", cookie1)
50
- assert_equal 2, jar.size
51
- assert_equal [ cookie1, cookie0 ], jar.fetch_cookies("rufus.rubyforge.org", "/sub/0")
52
- assert_equal [ cookie0 ], jar.fetch_cookies("rufus.rubyforge.org", "/main")
53
- assert_equal [ cookie0 ], jar.fetch_cookies("rufus.rubyforge.org", "/")
47
+ jar.add_cookie("rufus.rubyforge.org", "/sub", cookie1)
48
+ assert_equal 2, jar.size
49
+ assert_equal [ cookie1, cookie0 ], jar.fetch_cookies("rufus.rubyforge.org", "/sub/0")
50
+ assert_equal [ cookie0 ], jar.fetch_cookies("rufus.rubyforge.org", "/main")
51
+ assert_equal [ cookie0 ], jar.fetch_cookies("rufus.rubyforge.org", "/")
54
52
 
55
- jar.remove_cookie("rufus.rubyforge.org", "/sub", cookie1)
56
- assert_equal 1, jar.size
57
- end
53
+ jar.remove_cookie("rufus.rubyforge.org", "/sub", cookie1)
54
+ assert_equal 1, jar.size
55
+ end
58
56
 
59
- #
60
- # testing cookie_acceptable?(opts, cookie)
61
- #
62
- def test_2
57
+ #
58
+ # testing cookie_acceptable?(opts, cookie)
59
+ #
60
+ def test_2
63
61
 
64
- jar = Rufus::Verbs::CookieJar.new 77
62
+ jar = Rufus::Verbs::CookieJar.new 77
65
63
 
66
- opts = { :host => 'rufus.rubyforge.org', :path => '/' }
67
- c = TestCookie.new '.rubyforge.org', '/'
68
- r = TestResponse.new opts
69
- assert cookie_acceptable?(opts, r, c)
64
+ opts = { :host => 'rufus.rubyforge.org', :path => '/' }
65
+ c = TestCookie.new '.rubyforge.org', '/'
66
+ r = TestResponse.new opts
67
+ assert cookie_acceptable?(opts, r, c)
70
68
 
71
- # * The value for the Domain attribute contains no embedded dots
72
- # or does not start with a dot.
69
+ # * The value for the Domain attribute contains no embedded dots
70
+ # or does not start with a dot.
73
71
 
74
- opts = { :host => 'rufus.rubyforge.org', :path => '/' }
75
- c = TestCookie.new 'rufus.rubyforge.org', '/'
76
- r = TestResponse.new opts
77
- assert ! cookie_acceptable?(opts, r, c)
72
+ opts = { :host => 'rufus.rubyforge.org', :path => '/' }
73
+ c = TestCookie.new 'rufus.rubyforge.org', '/'
74
+ r = TestResponse.new opts
75
+ assert ! cookie_acceptable?(opts, r, c)
78
76
 
79
- opts = { :host => 'rufus.rubyforge.org', :path => '/' }
80
- c = TestCookie.new 'org', '/'
81
- r = TestResponse.new opts
82
- assert ! cookie_acceptable?(opts, r, c)
77
+ opts = { :host => 'rufus.rubyforge.org', :path => '/' }
78
+ c = TestCookie.new 'org', '/'
79
+ r = TestResponse.new opts
80
+ assert ! cookie_acceptable?(opts, r, c)
83
81
 
84
- # * The value for the Path attribute is not a prefix of the
85
- # request-URI.
82
+ # * The value for the Path attribute is not a prefix of the
83
+ # request-URI.
86
84
 
87
- opts = { :host => 'rufus.rubyforge.org', :path => '/this' }
88
- c = TestCookie.new '.rubyforge.org', '/that'
89
- r = TestResponse.new opts
90
- assert ! cookie_acceptable?(opts, r, c)
85
+ opts = { :host => 'rufus.rubyforge.org', :path => '/this' }
86
+ c = TestCookie.new '.rubyforge.org', '/that'
87
+ r = TestResponse.new opts
88
+ assert ! cookie_acceptable?(opts, r, c)
91
89
 
92
- # * The value for the request-host does not domain-match the
93
- # Domain attribute.
90
+ # * The value for the request-host does not domain-match the
91
+ # Domain attribute.
94
92
 
95
- opts = { :host => 'rufus.rubyforg.org', :path => '/' }
96
- c = TestCookie.new '.rubyforge.org', '/'
97
- r = TestResponse.new opts
98
- assert ! cookie_acceptable?(opts, r, c)
93
+ opts = { :host => 'rufus.rubyforg.org', :path => '/' }
94
+ c = TestCookie.new '.rubyforge.org', '/'
95
+ r = TestResponse.new opts
96
+ assert ! cookie_acceptable?(opts, r, c)
99
97
 
100
- # * The request-host is a FQDN (not IP address) and has the form
101
- # HD, where D is the value of the Domain attribute, and H is a
102
- # string that contains one or more dots.
103
-
104
- # implicit...
105
- end
98
+ # * The request-host is a FQDN (not IP address) and has the form
99
+ # HD, where D is the value of the Domain attribute, and H is a
100
+ # string that contains one or more dots.
106
101
 
107
- #def test_webrick_cookie
108
- # require 'webrick/cookie'
109
- # cookie = "PREF=ID=18da97219de4985:TM=12007507:LM=12007507:S=Guc1JcA15ySZYl2n; expires=Mon, 18-Jan-2010 09:30:37 GMT; path=/; domain=.google.com"
110
- # p WEBrick::Cookie.parse_set_cookie(cookie)
111
- # p Rufus::Verbs::Cookie.parse_set_cookie(cookie)
112
- #end
102
+ # implicit...
103
+ end
113
104
 
114
- protected
105
+ #def test_webrick_cookie
106
+ # require 'webrick/cookie'
107
+ # cookie = "PREF=ID=18da97219de4985:TM=12007507:LM=12007507:S=Guc1JcA15ySZYl2n; expires=Mon, 18-Jan-2010 09:30:37 GMT; path=/; domain=.google.com"
108
+ # p WEBrick::Cookie.parse_set_cookie(cookie)
109
+ # p Rufus::Verbs::Cookie.parse_set_cookie(cookie)
110
+ #end
115
111
 
116
- class TestCookie
112
+ protected
117
113
 
118
- attr_reader :domain, :path, :name
114
+ class TestCookie
119
115
 
120
- def initialize (domain=nil, path=nil, name='whatever')
116
+ attr_reader :domain, :path, :name
121
117
 
122
- @domain = domain
123
- @path = path
124
- @name = name
125
- end
126
- end
118
+ def initialize (domain=nil, path=nil, name='whatever')
127
119
 
128
- class TestResponse
120
+ @domain = domain
121
+ @path = path
122
+ @name = name
123
+ end
124
+ end
129
125
 
130
- def initialize (opts)
126
+ class TestResponse
131
127
 
132
- @path = opts[:path]
133
- end
128
+ def initialize (opts)
134
129
 
135
- def request
130
+ @path = opts[:path]
131
+ end
132
+
133
+ def request
136
134
 
137
- r = Object.new
138
- class << r
139
- attr_accessor :path
140
- end
141
- r.path = @path
142
- r
143
- end
144
- end
135
+ r = Object.new
136
+ class << r
137
+ attr_accessor :path
138
+ end
139
+ r.path = @path
140
+ r
141
+ end
142
+ end
145
143
  end
@@ -7,54 +7,52 @@
7
7
  # Sun Jan 13 12:33:03 JST 2008
8
8
  #
9
9
 
10
- require 'test/unit'
11
- require 'testbase'
12
10
 
13
- require 'rufus/verbs'
11
+ require File.dirname(__FILE__) + '/base.rb'
14
12
 
15
13
 
16
14
  class Cookie1Test < Test::Unit::TestCase
17
- include TestBaseMixin
15
+ include TestBaseMixin
18
16
 
19
- include Rufus::Verbs
17
+ include Rufus::Verbs
20
18
 
21
19
 
22
- def test_0
20
+ def test_0
23
21
 
24
- ep = EndPoint.new :cookies => true
25
- class << ep
26
- attr_reader :cookies
27
- end
22
+ ep = EndPoint.new :cookies => true
23
+ class << ep
24
+ attr_reader :cookies
25
+ end
28
26
 
29
- assert_equal 0, ep.cookies.size
27
+ assert_equal 0, ep.cookies.size
30
28
 
31
- ep.get :uri => "http://localhost:7777/cookie"
32
- assert_equal 1, ep.cookies.size
29
+ ep.get :uri => "http://localhost:7777/cookie"
30
+ assert_equal 1, ep.cookies.size
33
31
 
34
- req = ep.get :uri => "http://localhost:7777/cookie", :dry_run => true
35
- assert_match /^tcookie=\d*$/, req['Cookie']
36
- end
32
+ req = ep.get :uri => "http://localhost:7777/cookie", :dry_run => true
33
+ assert_match /^tcookie=\d*$/, req['Cookie']
34
+ end
37
35
 
38
- def test_1
36
+ def test_1
39
37
 
40
- ep0 = EndPoint.new :cookies => true
41
- ep1 = EndPoint.new :cookies => true
38
+ ep0 = EndPoint.new :cookies => true
39
+ ep1 = EndPoint.new :cookies => true
42
40
 
43
- ep0.post("http://localhost:7777/cookie") { "smurf0" }
44
- ep1.post("http://localhost:7777/cookie") { "smurf1" }
41
+ ep0.post("http://localhost:7777/cookie") { "smurf0" }
42
+ ep1.post("http://localhost:7777/cookie") { "smurf1" }
45
43
 
46
- expect 200, [ 'smurf0' ], ep0.get("http://localhost:7777/cookie")
47
- expect 200, [ 'smurf1' ], ep1.get("http://localhost:7777/cookie")
48
- end
44
+ expect 200, [ 'smurf0' ], ep0.get("http://localhost:7777/cookie")
45
+ expect 200, [ 'smurf1' ], ep1.get("http://localhost:7777/cookie")
46
+ end
49
47
 
50
- def test_2
48
+ def test_2
51
49
 
52
- ep = EndPoint.new :cookies => false # explicitely
50
+ ep = EndPoint.new :cookies => false # explicitely
53
51
 
54
- res0 = ep.post("http://localhost:7777/cookie") { "smurf0" }
55
- res1 = expect 200, [], ep.get("http://localhost:7777/cookie")
52
+ res0 = ep.post("http://localhost:7777/cookie") { "smurf0" }
53
+ res1 = expect 200, [], ep.get("http://localhost:7777/cookie")
56
54
 
57
- assert_not_equal res0['Set-Cookie'], res1['Set-Cookie']
58
- end
55
+ assert_not_equal res0['Set-Cookie'], res1['Set-Cookie']
56
+ end
59
57
  end
60
58
 
@@ -7,64 +7,77 @@
7
7
  # Tue Jan 15 09:26:45 JST 2008
8
8
  #
9
9
 
10
- require 'test/unit'
11
10
 
12
- require 'rufus/verbs'
11
+ require File.dirname(__FILE__) + '/base.rb'
13
12
 
14
13
 
15
14
  class DryRunTest < Test::Unit::TestCase
16
15
 
17
- include Rufus::Verbs
16
+ include Rufus::Verbs
18
17
 
19
18
 
20
- def test_0
19
+ def test_0
21
20
 
22
- req = put(
23
- :dry_run => true,
24
- :uri => "http://localhost:7777/items/1",
25
- :params => { "a" => "A", :b => :B })
21
+ req = put(
22
+ :dry_run => true,
23
+ :uri => "http://localhost:7777/items/1",
24
+ :params => { "a" => "A", :b => :B })
26
25
 
27
- assert_equal "/items/1?a=A&b=B", req.path
26
+ assert_equal "/items/1?a=A&b=B", req.path
28
27
 
29
- req = post(
30
- :dry_run => true,
31
- :uri => "http://localhost:7777/items/1",
32
- :params => { "a" => "A", :b => :B })
28
+ req = post(
29
+ :dry_run => true,
30
+ :uri => "http://localhost:7777/items/1",
31
+ :params => { "a" => "A", :b => :B })
33
32
 
34
- assert_equal "/items/1?a=A&b=B", req.path
33
+ assert_equal "/items/1?a=A&b=B", req.path
35
34
 
36
- req = put(
37
- :dry_run => true,
38
- :uri => "http://localhost:7777/items/1",
39
- :query => { "a" => "A", :b => :B })
35
+ req = put(
36
+ :dry_run => true,
37
+ :uri => "http://localhost:7777/items/1",
38
+ :query => { "a" => "A", :b => :B })
40
39
 
41
- assert_equal "/items/1?a=A&b=B", req.path
40
+ assert_equal "/items/1?a=A&b=B", req.path
42
41
 
43
- req = put(
44
- "http://localhost:7777/items/1?a=A", :d => "toto", :dry_run => true)
42
+ req = put(
43
+ "http://localhost:7777/items/1?a=A", :d => "toto", :dry_run => true)
45
44
 
46
- assert_equal "/items/1?a=A", req.path
47
- assert_equal "toto", req.body
48
- end
45
+ assert_equal "/items/1?a=A", req.path
46
+ assert_equal "toto", req.body
47
+ end
49
48
 
50
- def test_1
49
+ def test_1
51
50
 
52
- ep = Rufus::Verbs::EndPoint.new(
53
- :host => 'localhost',
54
- :resource => 'whatever')
51
+ ep = Rufus::Verbs::EndPoint.new(
52
+ :host => 'localhost',
53
+ :resource => 'whatever')
55
54
 
56
- req = ep.get(
57
- :dry_run => true,
58
- :resource => 'other',
59
- :params => { 'a' => 'A', 'b' => 'B' })
55
+ req = ep.get(
56
+ :dry_run => true,
57
+ :resource => 'other',
58
+ :params => { 'a' => 'A', 'b' => 'B' })
60
59
 
61
- assert_equal "/other?a=A&b=B", req.path
60
+ assert_equal "/other?a=A&b=B", req.path
62
61
 
63
- req = ep.post(
64
- :dry_run => true,
65
- :resource => 'other',
66
- :query => { 'a' => 'A', 'b' => 'B' })
67
-
68
- assert_equal "/other?a=A&b=B", req.path
69
- end
62
+ req = ep.post(
63
+ :dry_run => true,
64
+ :resource => 'other',
65
+ :query => { 'a' => 'A', 'b' => 'B' })
66
+
67
+ assert_equal "/other?a=A&b=B", req.path
68
+ end
69
+
70
+ def test_cgi_escape
71
+
72
+ ep = Rufus::Verbs::EndPoint.new(
73
+ :host => 'localhost',
74
+ :resource => 'whatever')
75
+
76
+ req = ep.post(
77
+ :dry_run => true,
78
+ :resource => 'other',
79
+ :query => { 'a' => 'A&A', 'b' => 'B?B' })
80
+
81
+ assert_equal "/other?a=A%26A&b=B%3FB", req.path
82
+ end
70
83
  end