sndacs 0.0.1 → 0.1.0

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/test/bucket_test.rb DELETED
@@ -1,215 +0,0 @@
1
- require "test_helper"
2
-
3
- class BucketTest < Test::Unit::TestCase
4
- def setup
5
- @bucket_vhost = S3::Bucket.send(:new, nil, "Data-Bucket")
6
- @bucket_path = S3::Bucket.send(:new, nil, "Data_Bucket")
7
- @bucket = @bucket_vhost
8
-
9
- @bucket_location = "EU"
10
- @bucket_location_body = <<-EOLocation
11
- <?xml version="1.0" encoding="UTF-8"?>\n<LocationConstraint xmlns="http://s3.amazonaws.com/doc/2006-03-01/">EU</LocationConstraint>
12
- EOLocation
13
-
14
- @response_location = Net::HTTPOK.new("1.1", "200", "OK")
15
- @response_location.stubs(:body).returns(@bucket_location_body)
16
-
17
- @bucket_owned_by_you_body = <<-EOOwnedByYou
18
- <?xml version="1.0" encoding="UTF-8"?>\n<Error> <Code>BucketAlreadyOwnedByYou</Code> <Message>Your previous request to create the named bucket succeeded and you already own it.</Message> <BucketName>bucket</BucketName> <RequestId>117D08EA0EC6E860</RequestId> <HostId>4VpMSvmJ+G5+DLtVox6O5cZNgdPlYcjCu3l0n4HjDe01vPxxuk5eTAtcAkUynRyV</HostId> </Error>
19
- EOOwnedByYou
20
-
21
- @reponse_owned_by_you = Net::HTTPConflict.new("1.1", "409", "Conflict")
22
- @reponse_owned_by_you.stubs(:body).returns(@bucket_owned_by_you_body)
23
-
24
- @bucket_already_exists_body = <<-EOAlreadyExists
25
- <?xml version="1.0" encoding="UTF-8"?>\n<Error> <Code>BucketAlreadyExists</Code> <Message>The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.</Message> <BucketName>bucket</BucketName> <RequestId>4C154D32807C92BD</RequestId> <HostId>/xyHQgXcUXTZQhoO+NUBzbaxbFrIhKlyuaRHFnmcId0bMePvY9Zwg+dyk2LYE4g5</HostId> </Error>
26
- EOAlreadyExists
27
-
28
- @reponse_already_exists = Net::HTTPConflict.new("1.1", "409", "Conflict")
29
- @response_already_exists.stubs(:body).returns(@bucket_already_exists_body)
30
-
31
- @objects_list_empty = []
32
- @objects_list = [
33
- S3::Object.send(:new, @bucket, :key => "obj1"),
34
- S3::Object.send(:new, @bucket, :key => "obj2")
35
- ]
36
-
37
- @response_objects_list_empty_body = <<-EOEmpty
38
- <?xml version="1.0" encoding="UTF-8"?>\n<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Name>bucket</Name> <Prefix></Prefix> <Marker></Marker> <MaxKeys>1000</MaxKeys> <IsTruncated>false</IsTruncated> </ListBucketResult>
39
- EOEmpty
40
-
41
- @response_objects_list_empty = Net::HTTPOK.new("1.1", "200", "OK")
42
- @response_objects_list_empty.stubs(:body).returns(@response_objects_list_empty_body)
43
-
44
- @response_objects_list_body = <<-EOObjects
45
- <?xml version="1.0" encoding="UTF-8"?>\n<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Name>bucket</Name> <Prefix></Prefix> <Marker></Marker> <MaxKeys>1000</MaxKeys> <IsTruncated>false</IsTruncated> <Contents> <Key>obj1</Key> <LastModified>2009-07-03T10:17:33.000Z</LastModified> <ETag>&quot;99519cdf14c255e580e1b7bca85a458c&quot;</ETag> <Size>1729</Size> <Owner> <ID>df864aeb6f42be43f1d9e60aaabe3f15e245b035a4b79d1cfe36c4deaec67205</ID> <DisplayName>owner</DisplayName> </Owner> <StorageClass>STANDARD</StorageClass> </Contents> <Contents> <Key>obj2</Key> <LastModified>2009-07-03T11:17:33.000Z</LastModified> <ETag>&quot;99519cdf14c255e586e1b12bca85a458c&quot;</ETag> <Size>179</Size> <Owner> <ID>df864aeb6f42be43f1d9e60aaabe3f17e247b037a4b79d1cfe36c4deaec67205</ID> <DisplayName>owner</DisplayName> </Owner> <StorageClass>STANDARD</StorageClass> </Contents> </ListBucketResult>
46
- EOObjects
47
-
48
- @response_objects_list = Net::HTTPOK.new("1.1", "200", "OK")
49
- @response_objects_list.stubs(:body).returns(@response_objects_list_body)
50
- end
51
-
52
- test "name valid" do
53
- assert_raise ArgumentError do S3::Bucket.send(:new, nil, "") end # should not be valid with empty name
54
- assert_raise ArgumentError do S3::Bucket.send(:new, nil, "10.0.0.1") end # should not be valid with IP as name
55
- assert_raise ArgumentError do S3::Bucket.send(:new, nil, "as") end # should not be valid with name shorter than 3 characters
56
- assert_raise ArgumentError do S3::Bucket.send(:new, nil, "a" * 256) end # should not be valid with name longer than 255 characters
57
- assert_raise ArgumentError do S3::Bucket.send(:new, nil, ".asdf") end # should not allow special characters as first character
58
- assert_raise ArgumentError do S3::Bucket.send(:new, nil, "-asdf") end # should not allow special characters as first character
59
- assert_raise ArgumentError do S3::Bucket.send(:new, nil, "_asdf") end # should not allow special characters as first character
60
-
61
- assert_nothing_raised do
62
- S3::Bucket.send(:new, nil, "a-a-")
63
- S3::Bucket.send(:new, nil, "a.a.")
64
- S3::Bucket.send(:new, nil, "a_a_")
65
- end
66
- end
67
-
68
- test "path prefix" do
69
- expected = ""
70
- actual = @bucket_vhost.path_prefix
71
- assert_equal expected, actual
72
-
73
- expected = "Data_Bucket/"
74
- actual = @bucket_path.path_prefix
75
- assert_equal expected, actual
76
- end
77
-
78
- test "host" do
79
- expected = "Data-Bucket.s3.amazonaws.com"
80
- actual = @bucket_vhost.host
81
- assert_equal expected, actual
82
-
83
- expected = "s3.amazonaws.com"
84
- actual = @bucket_path.host
85
- assert_equal expected, actual
86
- end
87
-
88
- test "vhost" do
89
- assert @bucket_vhost.vhost?
90
- assert ! @bucket_path.vhost?
91
- end
92
-
93
- test "exists" do
94
- @bucket.expects(:retrieve).returns(@bucket_vhost)
95
- assert @bucket.exists?
96
-
97
- @bucket.expects(:retrieve).raises(S3::Error::NoSuchBucket.new(nil, nil))
98
- assert ! @bucket.exists?
99
- end
100
-
101
- test "location and parse location" do
102
- @bucket.expects(:bucket_request).with(:get, { :params => { :location => nil } }).returns(@response_location)
103
-
104
- expected = @bucket_location
105
- actual = @bucket.location
106
- assert_equal expected, actual
107
-
108
- @bucket.stubs(:bucket_request).with(:get, { :params => { :location => nil } })
109
- actual = @bucket.location
110
- assert_equal expected, actual
111
- end
112
-
113
- test "save" do
114
- @bucket.expects(:bucket_request).with(:put, { :headers => {} })
115
- assert @bucket.save
116
- # mock ensures that bucket_request was called
117
- end
118
-
119
- test "save failure owned by you" do
120
- @bucket.expects(:bucket_request).with(:put, { :headers => {} }).raises(S3::Error::BucketAlreadyOwnedByYou.new(409, @response_owned_by_you))
121
- assert_raise S3::Error::BucketAlreadyOwnedByYou do
122
- @bucket.save
123
- end
124
-
125
- @bucket.expects(:bucket_request).with(:put, { :headers => {} }).raises(S3::Error::BucketAlreadyExists.new(409, @response_already_exists))
126
- assert_raise S3::Error::BucketAlreadyExists do
127
- @bucket.save
128
- end
129
- end
130
-
131
- test "objects" do
132
- @bucket.expects(:list_bucket).returns(@objects_list_empty)
133
- expected = @objects_list_empty
134
- actual = @bucket.objects
135
- assert_equal expected, actual
136
-
137
- @bucket.stubs(:list_bucket).returns(@objects_list_empty)
138
- actual = @bucket.objects
139
- assert_equal expected, actual
140
-
141
- @bucket.stubs(:list_bucket).returns(@objects_list)
142
-
143
- expected = @objects_list
144
- actual = @bucket.objects
145
- assert_equal expected, actual
146
- end
147
-
148
- test "list bucket and parse objects" do
149
- @bucket.expects(:bucket_request).with(:get, :params => { :test=>true }).returns(@response_objects_list_empty)
150
- expected = @objects_list_empty
151
- actual = @bucket.objects.find_all(:test => true)
152
- assert_equal expected, actual
153
-
154
- @bucket.expects(:bucket_request).with(:get, :params => { :test => true }).returns(@response_objects_list)
155
- expected = @objects_list
156
- actual = @bucket.objects.find_all(:test => true)
157
- assert_equal expected, actual
158
- end
159
-
160
- test "destroy" do
161
- @bucket.expects(:bucket_request).with(:delete)
162
- assert @bucket.destroy
163
- end
164
-
165
- test "objects build" do
166
- @bucket.stubs(:bucket_request)
167
-
168
- expected = "object_name"
169
- actual = @bucket.objects.build("object_name")
170
- assert_kind_of S3::Object, actual
171
- assert_equal expected, actual.key
172
- end
173
-
174
- test "objects find first" do
175
- assert_nothing_raised do
176
- S3::Object.any_instance.stubs(:retrieve).returns(S3::Object.send(:new, nil, :key => "obj2"))
177
- expected = "obj2"
178
- actual = @bucket.objects.find_first("obj2")
179
- assert_equal "obj2", actual.key
180
- end
181
- end
182
-
183
- test "objects find first fail" do
184
- assert_raise S3::Error::NoSuchKey do
185
- S3::Object.any_instance.stubs(:retrieve).raises(S3::Error::NoSuchKey.new(404, nil))
186
- @bucket.objects.find_first("obj3")
187
- end
188
- end
189
-
190
- test "objects find all on empty list" do
191
- @bucket.stubs(:list_bucket).returns(@objects_list_empty)
192
- assert_nothing_raised do
193
- expected = @objects_list_empty
194
- actual = @bucket.objects.find_all
195
- assert_equal expected, actual
196
- end
197
- end
198
-
199
- test "objects find all" do
200
- @bucket.stubs(:list_bucket).returns(@objects_list)
201
- assert_nothing_raised do
202
- expected = @objects_list
203
- actual = @bucket.objects.find_all
204
- assert_equal expected, actual
205
- end
206
- end
207
-
208
- test "objects destroy all" do
209
- @bucket.stubs(:list_bucket).returns(@objects_list)
210
- @bucket.objects.each do |obj|
211
- obj.expects(:destroy)
212
- end
213
- @bucket.objects.destroy_all
214
- end
215
- end
@@ -1,214 +0,0 @@
1
- require "test_helper"
2
-
3
- class ConnectionTest < Test::Unit::TestCase
4
- def setup
5
- @connection = S3::Connection.new(
6
- :access_key_id => "12345678901234567890",
7
- :secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
8
- )
9
- @http_request = Net::HTTP.new("")
10
- @response_ok = Net::HTTPOK.new("1.1", "200", "OK")
11
- @response_not_found = Net::HTTPNotFound.new("1.1", "404", "Not Found")
12
- @response_error = Net::HTTPInternalServerError.new("1.1", "500", "Internal Server Error")
13
- @response_temporary_redirect = Net::HTTPInternalServerError.new("1.1", "307", "Temporary Redirect")
14
- @connection.stubs(:http).returns(@http_request)
15
-
16
- @http_request.stubs(:start).returns(@response_ok)
17
- end
18
-
19
- test "handle response not modify response when ok" do
20
- assert_nothing_raised do
21
- response = @connection.request(
22
- :get,
23
- :host => "s3.amazonaws.com",
24
- :path => "/"
25
- )
26
- assert_equal @response_ok, response
27
- end
28
- end
29
-
30
- test "handle response throws exception when error" do
31
- response_body = <<-EOFakeBody
32
- <?xml version=\"1.0\" encoding=\"UTF-8\"?>
33
- <Error>
34
- <Code>NoSuchBucket</Code>
35
- <Message>The specified bucket does not exist</Message>
36
- </Error>
37
- EOFakeBody
38
-
39
- @http_request.stubs(:start).returns(@response_not_found)
40
- @response_not_found.stubs(:body).returns(response_body)
41
-
42
- assert_raise S3::Error::NoSuchBucket do
43
- response = @connection.request(
44
- :get,
45
- :host => "data.example.com.s3.amazonaws.com",
46
- :path => "/"
47
- )
48
- end
49
- end
50
-
51
- test "handle response throws standard exception when error" do
52
- @http_request.stubs(:start).returns(@response_error)
53
- @response_error.stubs(:body)
54
- assert_raise S3::Error::ResponseError do
55
- response = @connection.request(
56
- :get,
57
- :host => "data.example.com.s3.amazonaws.com",
58
- :path => "/"
59
- )
60
- end
61
-
62
- @response_error.stubs(:body).returns("")
63
- assert_raise S3::Error::ResponseError do
64
- response = @connection.request(
65
- :get,
66
- :host => "data.example.com.s3.amazonaws.com",
67
- :path => "/"
68
- )
69
- end
70
- end
71
-
72
- test "parse params empty" do
73
- expected = ""
74
- actual = S3::Connection.parse_params({})
75
- assert_equal expected, actual
76
- end
77
-
78
- test "parse params only interesting params" do
79
- expected = ""
80
- actual = S3::Connection.parse_params(:param1 => "1", :maxkeys => "2")
81
- assert_equal expected, actual
82
- end
83
-
84
- test "parse params remove underscore" do
85
- expected = "max-keys=100"
86
- actual = S3::Connection.parse_params(:max_keys => 100)
87
- assert_equal expected, actual
88
- end
89
-
90
- test "parse params with and without values" do
91
- params = S3::Connection.parse_params(:max_keys => 100, :prefix => nil)
92
-
93
- splitted_params = params.split("&")
94
- assert_equal 2, splitted_params.length
95
- assert splitted_params.include?("max-keys=100")
96
- assert splitted_params.include?("prefix")
97
- end
98
-
99
- test "headers empty" do
100
- expected = {}
101
- actual = S3::Connection.parse_headers({})
102
- assert_equal expected, actual
103
- end
104
-
105
- test "parse only interesting headers" do
106
- expected = {}
107
- actual = S3::Connection.parse_headers(
108
- :accept => "text/*, text/html, text/html;level=1, */*",
109
- :accept_charset => "iso-8859-2, unicode-1-1;q=0.8"
110
- )
111
- assert_equal expected, actual
112
- end
113
-
114
- test "parse headers remove underscore" do
115
- expected = {
116
- "content-type" => nil,
117
- "x-amz-acl" => nil,
118
- "x-amz-storage-class" => nil,
119
- "if-modified-since" => nil,
120
- "if-unmodified-since" => nil,
121
- "if-match" => nil,
122
- "if-none-match" => nil,
123
- "content-disposition" => nil,
124
- "content-encoding" => nil
125
- }
126
- actual = S3::Connection.parse_headers(
127
- :content_type => nil,
128
- :x_amz_acl => nil,
129
- :x_amz_storage_class => nil,
130
- :if_modified_since => nil,
131
- :if_unmodified_since => nil,
132
- :if_match => nil,
133
- :if_none_match => nil,
134
- :content_disposition => nil,
135
- :content_encoding => nil
136
- )
137
- assert_equal expected, actual
138
- end
139
-
140
- test "parse headers with values" do
141
- expected = {
142
- "content-type" => "text/html",
143
- "x-amz-acl" => "public-read",
144
- "x-amz-storage-class" => "STANDARD",
145
- "if-modified-since" => "today",
146
- "if-unmodified-since" => "tomorrow",
147
- "if-match" => "1234",
148
- "if-none-match" => "1243",
149
- "content-disposition" => "inline",
150
- "content-encoding" => "gzip"
151
- }
152
- actual = S3::Connection.parse_headers(
153
- :content_type => "text/html",
154
- :x_amz_acl => "public-read",
155
- :x_amz_storage_class => "STANDARD",
156
- :if_modified_since => "today",
157
- :if_unmodified_since => "tomorrow",
158
- :if_match => "1234",
159
- :if_none_match => "1243",
160
- :content_disposition => "inline",
161
- :content_encoding => "gzip"
162
- )
163
- assert_equal expected, actual
164
- end
165
-
166
- test "parse headers with range" do
167
- expected = {
168
- "range" => "bytes=0-100"
169
- }
170
- actual = S3::Connection.parse_headers(
171
- :range => 0..100
172
- )
173
- assert_equal expected, actual
174
- end
175
-
176
- test "response.body is nil on TemporaryRedirect" do
177
- @http_request.stubs(:start).returns(@response_temporary_redirect)
178
- @response_temporary_redirect.stubs(:body).returns(nil)
179
-
180
- assert_nothing_raised do
181
- response = @connection.request(
182
- :get,
183
- :host => "data.example.com.s3.amazonaws.com",
184
- :path => "/"
185
- )
186
- assert_equal nil, response
187
- end
188
- end
189
-
190
- test "response body with new host on TemporaryRedirect" do
191
- response_body = <<-EOFakeBody
192
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
193
- <Error>
194
- <Code>TemporaryRedirect</Code>
195
- <Message>Please re-send this request to the specified temporary endpoint. Continue to use the original request endpoint for future requests.</Message>
196
- <RequestId>24A0BB91158D470B</RequestId>
197
- <Bucket>data.example.com</Bucket>
198
- <HostId>DFcq9ktw5HvWZLduutz8fnVzqtXLwIZcAezc7mgyS7lJ2ux+RChY4qAJGa2fQDjV</HostId>
199
- <Endpoint>data.example.com.s3-external-3.amazonaws.com</Endpoint>
200
- </Error>"
201
- EOFakeBody
202
-
203
- @response_temporary_redirect.stubs(:body).returns(response_body)
204
-
205
- assert_nothing_raised do
206
- response = @connection.request(
207
- :get,
208
- :host => "data.example.com.s3.amazonaws.com",
209
- :path => "/"
210
- )
211
- assert_equal @response_ok, response
212
- end
213
- end
214
- end
data/test/object_test.rb DELETED
@@ -1,205 +0,0 @@
1
- # encoding: utf-8
2
- require "test_helper"
3
-
4
- class ObjectTest < Test::Unit::TestCase
5
- def setup
6
- @service = S3::Service.new(
7
- :access_key_id => "1234",
8
- :secret_access_key => "1337"
9
- )
10
- @bucket_images = S3::Bucket.send(:new, @service, "images")
11
- @object_lena = S3::Object.send(:new, @bucket_images, :key => "Lena.png")
12
- @object_lena.content = "test"
13
- @object_carmen = S3::Object.send(:new, @bucket_images, :key => "Carmen.png")
14
- @object_mac = S3::Object.send(:new, @bucket_images, :key => "Mac.png", :cache_control => "max-age=315360000")
15
- @object_mac.content = "test2"
16
-
17
- @response_binary = Net::HTTPOK.new("1.1", "200", "OK")
18
- @response_binary.stubs(:body).returns("test".respond_to?(:force_encoding) ? "test".force_encoding(Encoding::BINARY) : "test")
19
- @response_binary["etag"] = ""
20
- @response_binary["content-type"] = "image/png"
21
- @response_binary["content-disposition"] = "inline"
22
- @response_binary["content-encoding"] = nil
23
- @response_binary["last-modified"] = Time.now.httpdate
24
- @response_binary["content-length"] = 20
25
- @response_binary["x-amz-meta-test"] = "metadata"
26
-
27
- @xml_body = <<-EOXML
28
- <?xml version="1.0" encoding="UTF-8"?>
29
- <CopyObjectResult> <LastModified>#{Time.now.httpdate}</LastModified> <ETag>"etag"</ETag> </CopyObjectResult>
30
- EOXML
31
- @response_xml = Net::HTTPOK.new("1.1", "200", "OK")
32
- @response_xml.stubs(:body).returns(@xml_body)
33
- end
34
-
35
- test "initializing" do
36
- assert_raise ArgumentError do S3::Object.send(:new, nil, :key => "") end # should not allow empty key
37
- assert_raise ArgumentError do S3::Object.send(:new, nil, :key => "//") end # should not allow key with double slash
38
-
39
- assert_nothing_raised do
40
- S3::Object.send(:new, nil, :key => "Lena.png")
41
- S3::Object.send(:new, nil, :key => "Lena playboy.png")
42
- S3::Object.send(:new, nil, :key => "Lena Söderberg.png")
43
- S3::Object.send(:new, nil, :key => "/images/pictures/test images/Lena not full.png")
44
- end
45
- end
46
-
47
- test "==" do
48
- expected = false
49
- actual = @object_lena == nil
50
- assert_equal(expected, actual)
51
- end
52
-
53
- test "full key" do
54
- expected = "images/Lena.png"
55
- actual = @object_lena.full_key
56
- assert_equal expected, actual
57
- end
58
-
59
- test "url" do
60
- bucket1 = S3::Bucket.send(:new, @service, "images")
61
-
62
- object11 = S3::Object.send(:new, bucket1, :key => "Lena.png")
63
- expected = "http://images.s3.amazonaws.com/Lena.png"
64
- actual = object11.url
65
- assert_equal expected, actual
66
-
67
- object12 = S3::Object.send(:new, bucket1, :key => "Lena Söderberg.png")
68
- expected = "http://images.s3.amazonaws.com/Lena%20S%C3%B6derberg.png"
69
- actual = object12.url
70
- assert_equal expected, actual
71
-
72
- bucket2 = S3::Bucket.send(:new, @service, "images_new")
73
-
74
- object21 = S3::Object.send(:new, bucket2, :key => "Lena.png")
75
- expected = "http://s3.amazonaws.com/images_new/Lena.png"
76
- actual = object21.url
77
- assert_equal expected, actual
78
- end
79
-
80
- test "cname url" do
81
- bucket1 = S3::Bucket.send(:new, @service, "images.example.com")
82
-
83
- object11 = S3::Object.send(:new, bucket1, :key => "Lena.png")
84
- expected = "http://images.example.com/Lena.png"
85
- actual = object11.cname_url
86
- assert_equal expected, actual
87
-
88
- object12 = S3::Object.send(:new, bucket1, :key => "Lena Söderberg.png")
89
- expected = "http://images.example.com/Lena%20S%C3%B6derberg.png"
90
- actual = object12.cname_url
91
- assert_equal expected, actual
92
-
93
- bucket2 = S3::Bucket.send(:new, @service, "images_new")
94
-
95
- object21 = S3::Object.send(:new, bucket2, :key => "Lena.png")
96
- expected = nil
97
- actual = object21.cname_url
98
- assert_equal expected, actual
99
- end
100
-
101
- test "destroy" do
102
- @object_lena.expects(:object_request).with(:delete)
103
- assert @object_lena.destroy
104
- end
105
-
106
- test "save" do
107
- @object_lena.expects(:object_request).with(:put, :body=>"test", :headers=>{ :x_amz_acl=>"public-read", :x_amz_storage_class=>"STANDARD", :content_type=>"application/octet-stream" }).returns(@response_binary)
108
- assert @object_lena.save
109
- end
110
-
111
- test "save with cache control headers" do
112
- assert_equal "max-age=315360000", @object_mac.cache_control
113
- @object_mac.expects(:object_request).with(:put, :body=>"test2", :headers=>{ :x_amz_acl=>"public-read", :x_amz_storage_class=>"STANDARD", :content_type=>"application/octet-stream", :cache_control=>"max-age=315360000" }).returns(@response_binary)
114
- assert @object_mac.save
115
- end
116
-
117
- test "content and parse headers" do
118
- @object_lena.expects(:object_request).with(:get, {}).returns(@response_binary)
119
-
120
- expected = /test/n
121
- actual = @object_lena.content(true)
122
- assert_match expected, actual
123
- assert_equal "image/png", @object_lena.content_type
124
-
125
- assert @object_lena.content
126
-
127
- @object_lena.expects(:object_request).with(:get, {}).returns(@response_binary)
128
- assert @object_lena.content(true)
129
- end
130
-
131
- test "retrieve" do
132
- @object_lena.expects(:object_request).with(:head, {}).returns(@response_binary)
133
- assert @object_lena.retrieve
134
- end
135
-
136
- test "retrieve headers" do
137
- @object_lena.expects(:object_request).twice.with(:head, {}).returns(@response_binary)
138
- assert @object_lena.retrieve
139
-
140
- meta = {"x-amz-meta-test" => ["metadata"]}
141
- assert_equal meta, @object_lena.retrieve.metadata
142
- end
143
-
144
- test "exists" do
145
- @object_lena.expects(:retrieve).returns(true)
146
- assert @object_lena.exists?
147
-
148
- @object_carmen.expects(:retrieve).raises(S3::Error::NoSuchKey.new(nil, nil))
149
- assert ! @object_carmen.exists?
150
- end
151
-
152
- test "ACL writer" do
153
- expected = nil
154
- actual = @object_lena.acl
155
- assert_equal expected, actual
156
-
157
- assert @object_lena.acl = :public_read
158
-
159
- expected = "public-read"
160
- actual = @object_lena.acl
161
- assert_equal expected, actual
162
-
163
- assert @object_lena.acl = :private
164
-
165
- expected = "private"
166
- actual = @object_lena.acl
167
- assert_equal expected, actual
168
- end
169
-
170
- test "storage-class writer" do
171
- expected = nil
172
- actual = @object_lena.storage_class
173
- assert_equal expected, actual
174
-
175
- assert @object_lena.storage_class = :standard
176
-
177
- expected = "STANDARD"
178
- actual = @object_lena.storage_class
179
- assert_equal expected, actual
180
-
181
- assert @object_lena.storage_class = :reduced_redundancy
182
-
183
- expected = "REDUCED_REDUNDANCY"
184
- actual = @object_lena.storage_class
185
- assert_equal expected, actual
186
- end
187
-
188
- test "replace" do
189
- @bucket_images.expects(:bucket_request).with(:put, :path => "Lena-copy.png", :headers => { :x_amz_acl => "public-read", :content_type => "application/octet-stream", :x_amz_copy_source => "images/Lena.png", :x_amz_metadata_directive => "REPLACE" }).returns(@response_xml)
190
-
191
- new_object = @object_lena.copy(:key => "Lena-copy.png")
192
-
193
- assert_equal "Lena-copy.png", new_object.key
194
- assert_equal "Lena.png", @object_lena.key
195
- end
196
-
197
- test "copy" do
198
- @bucket_images.expects(:bucket_request).with(:put, :path => "Lena-copy.png", :headers => { :x_amz_acl => "public-read", :content_type => "application/octet-stream", :x_amz_copy_source => "images/Lena.png", :x_amz_metadata_directive => "COPY" }).returns(@response_xml)
199
-
200
- new_object = @object_lena.copy(:key => "Lena-copy.png", :replace => false)
201
-
202
- assert_equal "Lena-copy.png", new_object.key
203
- assert_equal "Lena.png", @object_lena.key
204
- end
205
- end