kerryb-amazon-ec2 0.3.6

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.
@@ -0,0 +1,238 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
+ # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
9
+ #++
10
+
11
+ require File.dirname(__FILE__) + '/test_helper.rb'
12
+
13
+ context "EC2 image_attributes " do
14
+
15
+ setup do
16
+ @ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
17
+
18
+ @modify_image_attribute_response_body = <<-RESPONSE
19
+ <ModifyImageAttributeResponse xm-lns="http://ec2.amazonaws.com/doc/2007-03-01">
20
+ <return>true</return>
21
+ </ModifyImageAttributeResponse>
22
+ RESPONSE
23
+
24
+ @reset_image_attribute_response_body = <<-RESPONSE
25
+ <ResetImageAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
26
+ <return>true</return>
27
+ </ResetImageAttributeResponse>
28
+ RESPONSE
29
+
30
+ @describe_image_attribute_response_body_launch_permissions = <<-RESPONSE
31
+ <DescribeImageAttributeResponse xm-lns="http://ec2.amazonaws.com/doc/2007-03-01">
32
+ <imageId>ami-61a54008</imageId>
33
+ <launchPermission>
34
+ <item>
35
+ <group>all</group>
36
+ </item>
37
+ <item>
38
+ <userId>495219933132</userId>
39
+ </item>
40
+ </launchPermission>
41
+ </DescribeImageAttributeResponse>
42
+ RESPONSE
43
+
44
+ @describe_image_attribute_response_body_product_codes = <<-RESPONSE
45
+ <DescribeImageAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-03">
46
+ <imageId>ami-61a54008</imageId>
47
+ <productCodes>
48
+ <item>
49
+ <productCode>774F4FF8</productCode>
50
+ </item>
51
+ </productCodes>
52
+ </DescribeImageAttributeResponse>
53
+ RESPONSE
54
+
55
+ end
56
+
57
+
58
+ specify "should be able to be changed with modify_image_attribute (with :attribute and single value :user_id and :group)" do
59
+ @ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
60
+ "Attribute"=>"launchPermission",
61
+ "OperationType"=>"add",
62
+ "UserId.1"=>"123",
63
+ "Group.1"=>"all"}).
64
+ returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
65
+ @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :user_id=>["123"], :group=>["all"]).should.be.an.instance_of Hash
66
+ end
67
+
68
+
69
+ specify "should be able to be changed with modify_image_attribute ( with :attribute but specifying :group only)" do
70
+ @ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
71
+ "Attribute"=>"launchPermission",
72
+ "OperationType"=>"add",
73
+ "Group.1"=>"all"}).
74
+ returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
75
+ @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :group=>["all"]).should.be.an.instance_of Hash
76
+ end
77
+
78
+
79
+ specify "should be able to be changed with modify_image_attribute ( with :operation_type 'remove')" do
80
+ @ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
81
+ "Attribute"=>"launchPermission",
82
+ "OperationType"=>"remove",
83
+ "Group.1"=>"all"}).
84
+ returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
85
+ @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"remove", :group=>["all"]).should.be.an.instance_of Hash
86
+ end
87
+
88
+
89
+ specify "should be able to be changed with modify_image_attribute ( with :attribute but specifying :user_id only)" do
90
+ @ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
91
+ "Attribute"=>"launchPermission",
92
+ "OperationType"=>"add",
93
+ "UserId.1"=>"123"}).returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
94
+
95
+ @ec2.modify_image_attribute(:image_id=>"ami-61a54008",
96
+ :attribute=>"launchPermission",
97
+ :operation_type=>"add",
98
+ :user_id=>["123"]).should.be.an.instance_of Hash
99
+ end
100
+
101
+
102
+ specify "should be able to be changed with modify_image_attribute ( with :attribute=>'productCodes')" do
103
+ @ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
104
+ "Attribute"=>"productCodes",
105
+ "OperationType"=>"",
106
+ "ProductCode.1"=>"774F4FF8"}).returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
107
+
108
+ @ec2.modify_image_attribute(:image_id=>"ami-61a54008",
109
+ :attribute=>"productCodes",
110
+ :product_code=>["774F4FF8"]).should.be.an.instance_of Hash
111
+ end
112
+
113
+
114
+ specify "should be able to be changed with modify_image_attribute ( with :attribute and multiple :user_id and :group elements)" do
115
+ @ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
116
+ "Attribute"=>"launchPermission",
117
+ "OperationType"=>"add",
118
+ "UserId.1"=>"123",
119
+ "UserId.2"=>"345",
120
+ "Group.1"=>"123",
121
+ "Group.2"=>"all"}).returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
122
+
123
+ @ec2.modify_image_attribute(:image_id=>"ami-61a54008",
124
+ :attribute=>"launchPermission",
125
+ :operation_type=>"add",
126
+ :user_id=>["123", "345"],
127
+ :group=>["123", "all"]).should.be.an.instance_of Hash
128
+ end
129
+
130
+
131
+ specify "should raise an exception when modify_image_attribute is called with incorrect arguments" do
132
+ # method args can't be nil or empty
133
+ lambda { @ec2.modify_image_attribute() }.should.raise(EC2::ArgumentError)
134
+ lambda { @ec2.modify_image_attribute(:image_id=>"") }.should.raise(EC2::ArgumentError)
135
+
136
+ # :image_id option must be not be empty or nil
137
+ lambda { @ec2.modify_image_attribute(:image_id=>nil, :attribute=>"launchPermission", :operation_type=>"add", :group=>["all"]) }.should.raise(EC2::ArgumentError)
138
+ lambda { @ec2.modify_image_attribute(:image_id=>"", :attribute=>"launchPermission", :operation_type=>"add", :group=>["all"]) }.should.raise(EC2::ArgumentError)
139
+
140
+ # :attribute currently has two options which are 'launchPermission' and 'productCodes, it should fail with any other value, nil, or empty
141
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>nil, :operation_type=>"add", :group=>["all"]) }.should.raise(EC2::ArgumentError)
142
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"", :operation_type=>"add", :group=>["all"]) }.should.raise(EC2::ArgumentError)
143
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"foo", :operation_type=>"add", :group=>["all"]) }.should.raise(EC2::ArgumentError)
144
+
145
+ # :attribute => 'launchPermission' option should fail if neither :group nor :user_id are also provided
146
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add") }.should.raise(EC2::ArgumentError)
147
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :group => nil) }.should.raise(EC2::ArgumentError)
148
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :group => "") }.should.raise(EC2::ArgumentError)
149
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :user_id => nil) }.should.raise(EC2::ArgumentError)
150
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :user_id => "") }.should.raise(EC2::ArgumentError)
151
+
152
+ # :attribute => 'productCodes' option should fail if :product_code isn't also provided
153
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"productCodes", :product_code=>nil) }.should.raise(EC2::ArgumentError)
154
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"productCodes", :product_code=>"") }.should.raise(EC2::ArgumentError)
155
+
156
+ # :operation_type currently has two options which are 'add' and 'remove', and it should fail with any other, nil or empty
157
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>nil, :group=>["all"]) }.should.raise(EC2::ArgumentError)
158
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"", :group=>["all"]) }.should.raise(EC2::ArgumentError)
159
+ lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"foo", :group=>["all"]) }.should.raise(EC2::ArgumentError)
160
+ end
161
+
162
+
163
+ specify "method describe_image_attribute should return the proper attributes when called with launchPermission" do
164
+ @ec2.stubs(:make_request).with('DescribeImageAttribute', {"ImageId"=>"ami-61a54008",
165
+ "Attribute"=>"launchPermission" }).
166
+ returns stub(:body => @describe_image_attribute_response_body_launch_permissions, :is_a? => true)
167
+
168
+ @ec2.describe_image_attribute(:image_id => "ami-61a54008", :attribute => "launchPermission").
169
+ should.be.an.instance_of Hash
170
+
171
+ response = @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission")
172
+ response.imageId.should.equal "ami-61a54008"
173
+ response.launchPermission.item[0].group.should.equal "all"
174
+ response.launchPermission.item[1].userId.should.equal "495219933132"
175
+ end
176
+
177
+
178
+ specify "method describe_image_attribute should return the proper attributes when called with productCodes" do
179
+ @ec2.stubs(:make_request).with('DescribeImageAttribute', {"ImageId"=>"ami-61a54008",
180
+ "Attribute"=>"productCodes" }).
181
+ returns stub(:body => @describe_image_attribute_response_body_product_codes, :is_a? => true)
182
+
183
+ @ec2.describe_image_attribute(:image_id => "ami-61a54008", :attribute => "productCodes").
184
+ should.be.an.instance_of Hash
185
+
186
+ response = @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>"productCodes")
187
+ response.imageId.should.equal "ami-61a54008"
188
+ response.productCodes.item[0].productCode.should.equal "774F4FF8"
189
+ end
190
+
191
+
192
+ specify "should raise an exception when describe_image_attribute is called with incorrect arguments" do
193
+ # method args can't be nil or empty
194
+ lambda { @ec2.describe_image_attribute() }.should.raise(EC2::ArgumentError)
195
+ lambda { @ec2.describe_image_attribute(:image_id=>"") }.should.raise(EC2::ArgumentError)
196
+
197
+ # :image_id option must be not be empty or nil w/ launchPermission
198
+ lambda { @ec2.describe_image_attribute(:image_id=>nil, :attribute=>"launchPermission") }.should.raise(EC2::ArgumentError)
199
+ lambda { @ec2.describe_image_attribute(:image_id=>"", :attribute=>"launchPermission") }.should.raise(EC2::ArgumentError)
200
+
201
+ # :image_id option must be not be empty or nil w/ productCodes
202
+ lambda { @ec2.describe_image_attribute(:image_id=>nil, :attribute=>"productCodes") }.should.raise(EC2::ArgumentError)
203
+ lambda { @ec2.describe_image_attribute(:image_id=>"", :attribute=>"productCodes") }.should.raise(EC2::ArgumentError)
204
+
205
+ # :attribute currently has two options which are 'launchPermission' and 'productCodes', it should fail with any other values,
206
+ # nil, or empty
207
+ lambda { @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>nil) }.should.raise(EC2::ArgumentError)
208
+ lambda { @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>"") }.should.raise(EC2::ArgumentError)
209
+ lambda { @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>"foo") }.should.raise(EC2::ArgumentError)
210
+ end
211
+
212
+
213
+ specify "should be able to reset attributes with reset_image_attribute " do
214
+ @ec2.stubs(:make_request).with('ResetImageAttribute', {"ImageId"=>"ami-61a54008",
215
+ "Attribute"=>"launchPermission"}).
216
+ returns stub(:body => @reset_image_attribute_response_body, :is_a? => true)
217
+ @ec2.reset_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission").should.be.an.instance_of Hash
218
+ @ec2.reset_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission").return.should.equal "true"
219
+ end
220
+
221
+
222
+ specify "should raise an exception when reset_image_attribute is called with incorrect arguments" do
223
+ # method args can't be nil or empty
224
+ lambda { @ec2.reset_image_attribute() }.should.raise(EC2::ArgumentError)
225
+ lambda { @ec2.reset_image_attribute(:image_id=>"") }.should.raise(EC2::ArgumentError)
226
+
227
+ # :image_id option must be not be empty or nil
228
+ lambda { @ec2.reset_image_attribute(:image_id=>nil, :attribute=>"launchPermission") }.should.raise(EC2::ArgumentError)
229
+ lambda { @ec2.reset_image_attribute(:image_id=>"", :attribute=>"launchPermission") }.should.raise(EC2::ArgumentError)
230
+
231
+ # :attribute currently has one option which is 'launchPermission', it should fail with any other value, nil, or empty
232
+ lambda { @ec2.reset_image_attribute(:image_id=>"ami-61a54008", :attribute=>nil) }.should.raise(EC2::ArgumentError)
233
+ lambda { @ec2.reset_image_attribute(:image_id=>"ami-61a54008", :attribute=>"") }.should.raise(EC2::ArgumentError)
234
+ lambda { @ec2.reset_image_attribute(:image_id=>"ami-61a54008", :attribute=>"foo") }.should.raise(EC2::ArgumentError)
235
+ end
236
+
237
+
238
+ end
@@ -0,0 +1,197 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
+ # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
9
+ #++
10
+
11
+ require File.dirname(__FILE__) + '/test_helper.rb'
12
+
13
+ context "An EC2 image " do
14
+
15
+ setup do
16
+ @ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
17
+
18
+ @register_image_response_body = <<-RESPONSE
19
+ <RegisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
20
+ <imageId>ami-61a54008</imageId>
21
+ </RegisterImageResponse>
22
+ RESPONSE
23
+
24
+ @describe_image_response_body = <<-RESPONSE
25
+ <DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
26
+ <imagesSet>
27
+ <item>
28
+ <imageId>ami-61a54008</imageId>
29
+ <imageLocation>foobar1/image.manifest.xml</imageLocation>
30
+ <imageState>available</imageState>
31
+ <imageOwnerId>AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA</imageOwnerId>
32
+ <isPublic>true</isPublic>
33
+ <productCodes>
34
+ <item>
35
+ <productCode>774F4FF8</productCode>
36
+ </item>
37
+ </productCodes>
38
+ </item>
39
+ <item>
40
+ <imageId>ami-61a54009</imageId>
41
+ <imageLocation>foobar2/image.manifest.xml</imageLocation>
42
+ <imageState>deregistered</imageState>
43
+ <imageOwnerId>ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ</imageOwnerId>
44
+ <isPublic>false</isPublic>
45
+ </item>
46
+ </imagesSet>
47
+ </DescribeImagesResponse>
48
+ RESPONSE
49
+
50
+ @deregister_image_response_body = <<-RESPONSE
51
+ <DeregisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
52
+ <return>true</return>
53
+ </DeregisterImageResponse>
54
+ RESPONSE
55
+
56
+ end
57
+
58
+
59
+ specify "should be able to be registered" do
60
+ @ec2.stubs(:make_request).with('RegisterImage', {"ImageLocation"=>"mybucket-myimage.manifest.xml"}).
61
+ returns stub(:body => @register_image_response_body, :is_a? => true)
62
+ @ec2.register_image(:image_location => "mybucket-myimage.manifest.xml").imageId.should.equal "ami-61a54008"
63
+ @ec2.register_image(:image_location => "mybucket-myimage.manifest.xml").should.be.an.instance_of Hash
64
+ end
65
+
66
+
67
+ specify "method register_image should raise an exception when called without nil/empty string arguments" do
68
+ lambda { @ec2.register_image() }.should.raise(EC2::ArgumentError)
69
+ lambda { @ec2.register_image(:image_location => "") }.should.raise(EC2::ArgumentError)
70
+ end
71
+
72
+
73
+ specify "should be able to be described and return the correct Ruby response class for parent and members" do
74
+ @ec2.stubs(:make_request).with('DescribeImages', {}).
75
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
76
+ @ec2.describe_images.should.be.an.instance_of Hash
77
+ response = @ec2.describe_images
78
+ response.should.be.an.instance_of Hash
79
+ end
80
+
81
+
82
+ specify "should be able to be described with no params and return an imagesSet" do
83
+ @ec2.stubs(:make_request).with('DescribeImages', {}).
84
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
85
+ @ec2.describe_images.imagesSet.item.length.should.equal 2
86
+ end
87
+
88
+ specify "should be able to be described by an Array of ImageId.N ID's and return an array of Items" do
89
+ @ec2.stubs(:make_request).with('DescribeImages', {"ImageId.1"=>"ami-61a54008", "ImageId.2"=>"ami-61a54009"}).
90
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
91
+ @ec2.describe_images( :image_id => ["ami-61a54008", "ami-61a54009"] ).imagesSet.item.length.should.equal 2
92
+
93
+ response = @ec2.describe_images( :image_id => ["ami-61a54008", "ami-61a54009"] )
94
+
95
+ # test first 'Item' object returned
96
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
97
+ response.imagesSet.item[0].imageLocation.should.equal "foobar1/image.manifest.xml"
98
+ response.imagesSet.item[0].imageState.should.equal "available"
99
+ response.imagesSet.item[0].imageOwnerId.should.equal "AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA"
100
+ response.imagesSet.item[0].isPublic.should.equal "true"
101
+ response.imagesSet.item[0].productCodes.item[0].productCode.should.equal "774F4FF8"
102
+
103
+ # test second 'Item' object returned
104
+ response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
105
+ response.imagesSet.item[1].imageLocation.should.equal "foobar2/image.manifest.xml"
106
+ response.imagesSet.item[1].imageState.should.equal "deregistered"
107
+ response.imagesSet.item[1].imageOwnerId.should.equal "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"
108
+ response.imagesSet.item[1].isPublic.should.equal "false"
109
+ end
110
+
111
+
112
+ specify "should be able to be described by an owners with Owner.N ID's and return an array of Items" do
113
+ @ec2.stubs(:make_request).with('DescribeImages', "Owner.1" => "AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "Owner.2" => "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ").
114
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
115
+ @ec2.describe_images( :owner_id => ["AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"] ).imagesSet.item.length.should.equal 2
116
+
117
+ # owner ID's
118
+ response = @ec2.describe_images( :owner_id => ["AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"] )
119
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
120
+ response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
121
+ end
122
+
123
+
124
+ specify "should be able to be described by an owner of 'self' and return an array of Items that I own" do
125
+ @ec2.stubs(:make_request).with('DescribeImages', "Owner.1" => "self").
126
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
127
+ @ec2.describe_images( :owner_id => "self" ).imagesSet.item.length.should.equal 2
128
+
129
+ # 'self' - Those that I own
130
+ response = @ec2.describe_images( :owner_id => "self" )
131
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
132
+ end
133
+
134
+
135
+ specify "should be able to be described by an owner of 'amazon' and return an array of Items that are Amazon Public AMI's" do
136
+ @ec2.stubs(:make_request).with('DescribeImages', "Owner.1" => "amazon").
137
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
138
+ @ec2.describe_images( :owner_id => "amazon" ).imagesSet.item.length.should.equal 2
139
+
140
+ # 'amazon' - Those that are owned and created by AWS
141
+ response = @ec2.describe_images( :owner_id => "amazon" )
142
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
143
+ end
144
+
145
+
146
+ specify "should be able to be described by an owners with Owner.N ID's who can execute AMI's and return an array of Items" do
147
+ @ec2.stubs(:make_request).with('DescribeImages', "ExecutableBy.1" => "AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ExecutableBy.2" => "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ").
148
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
149
+ @ec2.describe_images( :executable_by => ["AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"] ).imagesSet.item.length.should.equal 2
150
+
151
+ # executable by owner ID's
152
+ response = @ec2.describe_images( :executable_by => ["AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"] )
153
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
154
+ response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
155
+ end
156
+
157
+
158
+ specify "should be able to be described by an owners with Owner.N of 'self' who can execute AMI's and return an array of Items" do
159
+ @ec2.stubs(:make_request).with('DescribeImages', "ExecutableBy.1" => "self").
160
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
161
+ @ec2.describe_images( :executable_by => "self" ).imagesSet.item.length.should.equal 2
162
+
163
+ # executable by owner ID's
164
+ response = @ec2.describe_images( :executable_by => "self" )
165
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
166
+ response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
167
+ end
168
+
169
+
170
+ specify "should be able to be described by an owners with Owner.N of 'all' who can execute AMI's and return an array of Items" do
171
+ @ec2.stubs(:make_request).with('DescribeImages', "ExecutableBy.1" => "all").
172
+ returns stub(:body => @describe_image_response_body, :is_a? => true)
173
+ @ec2.describe_images( :executable_by => "all" ).imagesSet.item.length.should.equal 2
174
+
175
+ # executable by owner ID's
176
+ response = @ec2.describe_images( :executable_by => "all" )
177
+ response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
178
+ response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
179
+ end
180
+
181
+
182
+ specify "should be able to be de-registered" do
183
+ @ec2.stubs(:make_request).with('DeregisterImage', {"ImageId"=>"ami-61a54008"}).
184
+ returns stub(:body => @deregister_image_response_body, :is_a? => true)
185
+ @ec2.deregister_image(:image_id => "ami-61a54008" ).should.be.an.instance_of Hash
186
+ @ec2.deregister_image(:image_id => "ami-61a54008" ).return.should.equal "true"
187
+ end
188
+
189
+
190
+ specify "method deregister_image should raise an exception when called without nil/empty string arguments" do
191
+ lambda { @ec2.deregister_image() }.should.raise(EC2::ArgumentError)
192
+ lambda { @ec2.deregister_image( :image_id => nil ) }.should.raise(EC2::ArgumentError)
193
+ lambda { @ec2.deregister_image( :image_id => "" ) }.should.raise(EC2::ArgumentError)
194
+ end
195
+
196
+
197
+ end