steamcannon-deltacloud-core 0.0.7.2-java → 0.0.8.1-java

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/Rakefile CHANGED
@@ -30,15 +30,7 @@ end
30
30
 
31
31
  desc "Run basic unit tests"
32
32
  Rake::TestTask.new("test") { |t|
33
- t.test_files = FileList[
34
- 'tests/api_test.rb',
35
- 'tests/hardware_profiles_test.rb',
36
- 'tests/realms_test.rb',
37
- 'tests/images_test.rb',
38
- 'tests/instances_test.rb',
39
- 'tests/instance_states_test.rb',
40
- 'tests/url_for_test.rb'
41
- ]
33
+ t.test_files = FileList.new('tests/**/*_test.rb')
42
34
  t.verbose = true
43
35
  t.warning = false
44
36
  }
data/config.ru CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'sinatra'
3
3
 
4
+ $:.unshift File.join(File.dirname(__FILE__), '.')
5
+
4
6
  require 'server.rb'
5
7
  run Sinatra::Application
@@ -115,8 +115,11 @@ module ApplicationHelper
115
115
 
116
116
  def cdata(&block)
117
117
  text = capture_haml(&block)
118
- text.gsub!("\n", "\n ")
119
- "<![CDATA[\n #{text}\n]]>"
118
+ "<![CDATA[#{text.strip}]]>"
119
+ end
120
+
121
+ def render_cdata(text)
122
+ "<pem><![CDATA[#{text.strip}]]></pem>"
120
123
  end
121
124
 
122
125
  end
@@ -102,6 +102,8 @@ module Sinatra
102
102
 
103
103
  if rack_accept.media_type.to_s.strip.eql?('Accept:')
104
104
  format :xml
105
+ elsif is_chrome?
106
+ format :html
105
107
  else
106
108
  format lookup_format_from_mime(rack_accept.best_media_type(accept_to_array))
107
109
  end
@@ -109,6 +111,14 @@ module Sinatra
109
111
  end
110
112
 
111
113
  app.class_eval do
114
+
115
+ # Simple helper to detect Chrome based browsers
116
+ # which have screwed up they Accept headers.
117
+ # Set HTML as default output format here
118
+ def is_chrome?
119
+ true if env['HTTP_USER_AGENT'] =~ /Chrome/
120
+ end
121
+
112
122
  # This code was copied from respond_to plugin
113
123
  # http://github.com/cehoffman/sinatra-respond_to
114
124
  # MIT License
data/server.rb CHANGED
@@ -14,6 +14,8 @@ require 'lib/deltacloud/helpers/blob_stream'
14
14
  configure do
15
15
  set :raise_errors => false
16
16
  set :show_exceptions, false
17
+ set :views, File.dirname(__FILE__) + '/views'
18
+ set :public, File.dirname(__FILE__) + '/public'
17
19
  end
18
20
 
19
21
  configure :development do
@@ -421,7 +423,7 @@ collection :keys do
421
423
  @key = driver.create_key(credentials, { :key_name => params[:name] })
422
424
  respond_to do |format|
423
425
  format.html { haml :"keys/show" }
424
- format.xml { haml :"keys/show" }
426
+ format.xml { haml :"keys/show", :ugly => true }
425
427
  end
426
428
  end
427
429
  end
@@ -9,7 +9,7 @@
9
9
  = @image.name
10
10
  %dt Owner
11
11
  %dd
12
- = link_to @image.owner_id, images_url( :owner_id => @image.owner_id )
12
+ = link_to @image.owner_id, image_url( :owner_id => @image.owner_id )
13
13
  %dt Architecture
14
14
  %dd
15
15
  = @image.architecture
@@ -8,9 +8,8 @@
8
8
  %fingerprint<
9
9
  =@key.fingerprint
10
10
  - unless @key.pem_rsa_key.nil?
11
- %pem<
12
- =cdata do
13
- =@key.pem_rsa_key
11
+ %pem
12
+ ~render_cdata(@key.pem_rsa_key)
14
13
  - if @key.is_password?
15
14
  %username<
16
15
  =cdata do
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 7
9
- - 2
10
- version: 0.0.7.2
8
+ - 8
9
+ - 1
10
+ version: 0.0.8.1
11
11
  platform: java
12
12
  authors:
13
13
  - Red Hat, Inc.
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-11 00:00:00 -04:00
18
+ date: 2010-10-21 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -109,9 +109,39 @@ dependencies:
109
109
  type: :runtime
110
110
  version_requirements: *id006
111
111
  - !ruby/object:Gem::Dependency
112
- name: compass
112
+ name: aws
113
113
  prerelease: false
114
114
  requirement: &id007 !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ segments:
120
+ - 2
121
+ - 3
122
+ - 21
123
+ version: 2.3.21
124
+ type: :runtime
125
+ version_requirements: *id007
126
+ - !ruby/object:Gem::Dependency
127
+ name: amazon-ec2
128
+ prerelease: false
129
+ requirement: &id008 !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ segments:
135
+ - 0
136
+ - 9
137
+ - 15
138
+ version: 0.9.15
139
+ type: :runtime
140
+ version_requirements: *id008
141
+ - !ruby/object:Gem::Dependency
142
+ name: compass
143
+ prerelease: false
144
+ requirement: &id009 !ruby/object:Gem::Requirement
115
145
  none: false
116
146
  requirements:
117
147
  - - ">="
@@ -122,11 +152,11 @@ dependencies:
122
152
  - 17
123
153
  version: 0.8.17
124
154
  type: :development
125
- version_requirements: *id007
155
+ version_requirements: *id009
126
156
  - !ruby/object:Gem::Dependency
127
157
  name: nokogiri
128
158
  prerelease: false
129
- requirement: &id008 !ruby/object:Gem::Requirement
159
+ requirement: &id010 !ruby/object:Gem::Requirement
130
160
  none: false
131
161
  requirements:
132
162
  - - ">="
@@ -137,11 +167,11 @@ dependencies:
137
167
  - 1
138
168
  version: 1.4.1
139
169
  type: :development
140
- version_requirements: *id008
170
+ version_requirements: *id010
141
171
  - !ruby/object:Gem::Dependency
142
172
  name: rack-test
143
173
  prerelease: false
144
- requirement: &id009 !ruby/object:Gem::Requirement
174
+ requirement: &id011 !ruby/object:Gem::Requirement
145
175
  none: false
146
176
  requirements:
147
177
  - - ">="
@@ -152,11 +182,11 @@ dependencies:
152
182
  - 3
153
183
  version: 0.5.3
154
184
  type: :development
155
- version_requirements: *id009
185
+ version_requirements: *id011
156
186
  - !ruby/object:Gem::Dependency
157
187
  name: cucumber
158
188
  prerelease: false
159
- requirement: &id010 !ruby/object:Gem::Requirement
189
+ requirement: &id012 !ruby/object:Gem::Requirement
160
190
  none: false
161
191
  requirements:
162
192
  - - ">="
@@ -167,11 +197,11 @@ dependencies:
167
197
  - 3
168
198
  version: 0.6.3
169
199
  type: :development
170
- version_requirements: *id010
200
+ version_requirements: *id012
171
201
  - !ruby/object:Gem::Dependency
172
202
  name: rcov
173
203
  prerelease: false
174
- requirement: &id011 !ruby/object:Gem::Requirement
204
+ requirement: &id013 !ruby/object:Gem::Requirement
175
205
  none: false
176
206
  requirements:
177
207
  - - ">="
@@ -182,7 +212,7 @@ dependencies:
182
212
  - 8
183
213
  version: 0.9.8
184
214
  type: :development
185
- version_requirements: *id011
215
+ version_requirements: *id013
186
216
  description: " The Deltacloud API is built as a service-based REST API.\n You do not directly link a Deltacloud library into your program to use it.\n Instead, a client speaks the Deltacloud API over HTTP to a server\n which implements the REST interface.\n"
187
217
  email: deltacloud-users@lists.fedorahosted.org
188
218
  executables:
@@ -335,13 +365,6 @@ files:
335
365
  - public/stylesheets/compiled/application.css
336
366
  - public/stylesheets/compiled/screen.css
337
367
  - bin/deltacloudd
338
- - tests/images_test.rb
339
- - tests/instances_test.rb
340
- - tests/url_for_test.rb
341
- - tests/hardware_profiles_test.rb
342
- - tests/instance_states_test.rb
343
- - tests/realms_test.rb
344
- - tests/api_test.rb
345
368
  - COPYING
346
369
  has_rdoc: true
347
370
  homepage: http://www.deltacloud.org
@@ -377,11 +400,5 @@ rubygems_version: 1.3.7
377
400
  signing_key:
378
401
  specification_version: 3
379
402
  summary: Deltacloud REST API
380
- test_files:
381
- - tests/images_test.rb
382
- - tests/instances_test.rb
383
- - tests/url_for_test.rb
384
- - tests/hardware_profiles_test.rb
385
- - tests/instance_states_test.rb
386
- - tests/realms_test.rb
387
- - tests/api_test.rb
403
+ test_files: []
404
+
data/tests/api_test.rb DELETED
@@ -1,37 +0,0 @@
1
- require 'tests/common'
2
-
3
- module DeltacloudUnitTest
4
- class ApiTest < Test::Unit::TestCase
5
- include Rack::Test::Methods
6
-
7
- def app
8
- Sinatra::Application
9
- end
10
-
11
- def test_it_returns_entry_points
12
- do_xml_request '/api'
13
- (last_xml_response/'/api/link').map.size.should > 0
14
- end
15
-
16
- def test_it_has_correct_attributes_set
17
- do_xml_request '/api'
18
- (last_xml_response/'/api/link').each do |link|
19
- link.attributes.keys.sort.should == [ 'href', 'rel' ]
20
- end
21
- end
22
-
23
- def test_it_responses_to_html
24
- do_request '/api', {}, false, { :format => :html }
25
- last_response.status.should == 200
26
- Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
27
- end
28
-
29
- def test_it_responses_to_json
30
- do_request '/api', {}, false, { :format => :json }
31
- last_response.status.should == 200
32
- JSON::parse(last_response.body).class.should == Hash
33
- JSON::parse(last_response.body)['api'].class.should == Hash
34
- end
35
-
36
- end
37
- end
@@ -1,120 +0,0 @@
1
- require 'tests/common'
2
-
3
- module DeltacloudUnitTest
4
- class HardwareProfilesTest < Test::Unit::TestCase
5
- include Rack::Test::Methods
6
-
7
- def app
8
- Sinatra::Application
9
- end
10
-
11
- def test_it_returns_hardware_profiles
12
- do_xml_request '/api/hardware_profiles'
13
- (last_xml_response/'hardware_profiles/hardware_profile').map.size.should > 0
14
- end
15
-
16
- def test_it_has_correct_attributes_set
17
- do_xml_request '/api/hardware_profiles'
18
- (last_xml_response/'hardware_profiles/hardware_profile').each do |profile|
19
- profile.attributes.keys.sort.should == [ 'href', 'id' ]
20
- end
21
- end
22
-
23
- def test_hardware_profiles_have_name
24
- do_xml_request '/api/hardware_profiles'
25
- (last_xml_response/'hardware_profiles/hardware_profile').each do |profile|
26
- (profile/'name').text.should_not == nil
27
- end
28
- end
29
-
30
- def test_hardware_profiles_have_unique_name
31
- do_xml_request '/api/hardware_profiles'
32
- names = []
33
- (last_xml_response/'hardware_profiles/hardware_profile').each do |profile|
34
- names << (profile/'name').text
35
- end
36
- names.should == names.uniq
37
- end
38
-
39
- def test_hardware_profiles_have_unique_id
40
- do_xml_request '/api/hardware_profiles'
41
- ids = []
42
- (last_xml_response/'hardware_profiles/hardware_profile').each do |profile|
43
- ids << profile['id']
44
- end
45
- ids.should == ids.uniq
46
- end
47
-
48
- def test_m1_xlarge_profile_has_correct_attributes
49
- do_xml_request '/api/hardware_profiles'
50
- profile = (last_xml_response/'hardware_profiles/hardware_profile[@id="m1-xlarge"]')
51
- test_profile_properties(profile)
52
- end
53
-
54
- def test_it_returns_valid_hardware_profile
55
- do_xml_request '/api/hardware_profiles/m1-xlarge'
56
- profile = (last_xml_response/'hardware_profile')
57
- test_profile_properties(profile)
58
- end
59
-
60
- def test_it_responses_to_json
61
- do_request '/api/hardware_profiles', {}, false, { :format => :json }
62
- JSON::parse(last_response.body).class.should == Hash
63
- JSON::parse(last_response.body)['hardware_profiles'].class.should == Array
64
-
65
- do_request '/api/hardware_profiles/m1-xlarge', {}, false, { :format => :json }
66
- last_response.status.should == 200
67
- JSON::parse(last_response.body).class.should == Hash
68
- JSON::parse(last_response.body)['hardware_profile'].class.should == Hash
69
- end
70
-
71
- def test_it_responses_to_html
72
- do_request '/api/hardware_profiles', {}, false, { :format => :html }
73
- last_response.status.should == 200
74
- Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
75
-
76
- do_request '/api/hardware_profiles/m1-xlarge', {}, false, { :format => :html }
77
- last_response.status.should == 200
78
- Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
79
- end
80
-
81
- def test_it_returns_error_on_wrong_name
82
- do_request '/api/hardware_profiles/m1-unknown-wrongname', {}, false, { :format => :html }
83
- last_response.status.should == 404
84
- do_xml_request '/api/hardware_profiles/m1-unknown-wrongname'
85
- last_response.status.should == 404
86
- do_request '/api/hardware_profiles/m1-unknown-wrongname', {}, false, { :format => :json }
87
- last_response.status.should == 404
88
- end
89
-
90
- private
91
-
92
- def test_profile_properties(profile)
93
-
94
- (profile/'property').each do |properties|
95
- properties.attributes.keys.sort.should == [ 'kind', 'name', 'unit', 'value' ]
96
- end
97
-
98
- (profile/'property[@name="architecture"]').first['kind'].should == 'fixed'
99
- (profile/'property[@name="architecture"]').first['unit'].should == 'label'
100
-
101
- (profile/'property[@name="memory"]').first['kind'].should == 'range'
102
- (profile/'property[@name="memory"]').first['unit'].should == 'MB'
103
- (profile/'property[@name="memory"]/range').size.should == 1
104
- (profile/'property[@name="memory"]/range').first.attributes.keys.sort.should == [ 'first', 'last' ]
105
-
106
- (profile/'property[@name="cpu"]').first['kind'].should == 'fixed'
107
- (profile/'property[@name="cpu"]').first['unit'].should == 'count'
108
-
109
- (profile/'property[@name="storage"]').first['kind'].should == 'enum'
110
- (profile/'property[@name="storage"]').first['unit'].should == 'GB'
111
- (profile/'property[@name="storage"]/enum').size.should == 1
112
- (profile/'property[@name="storage"]/enum/entry').map.size.should == 3
113
- (profile/'property[@name="storage"]/enum/entry').each do |entry|
114
- entry.attributes.keys.should == [ 'value' ]
115
- entry['value'].should_not == nil
116
- end
117
- end
118
-
119
- end
120
- end
data/tests/images_test.rb DELETED
@@ -1,111 +0,0 @@
1
- require 'tests/common'
2
-
3
- module DeltacloudUnitTest
4
- class HardwareProfilesTest < Test::Unit::TestCase
5
- include Rack::Test::Methods
6
-
7
- def app
8
- Sinatra::Application
9
- end
10
-
11
- def test_it_require_authentication
12
- require_authentication?('/api/images').should == true
13
- end
14
-
15
- def test_it_returns_images
16
- do_xml_request '/api/images', {}, true
17
- (last_xml_response/'images/image').map.size.should > 0
18
- end
19
-
20
- def test_it_has_correct_attributes_set
21
- do_xml_request '/api/images', {}, true
22
- (last_xml_response/'images/image').each do |image|
23
- image.attributes.keys.sort.should == [ 'href', 'id' ]
24
- end
25
- end
26
-
27
- def test_img1_has_correct_attributes
28
- do_xml_request '/api/images', {}, true
29
- image = (last_xml_response/'images/image[@id="img1"]')
30
- test_image_attributes(image)
31
- end
32
-
33
- def test_it_returns_valid_image
34
- do_xml_request '/api/images/img1', {}, true
35
- image = (last_xml_response/'image')
36
- test_image_attributes(image)
37
- end
38
-
39
- def test_it_has_unique_ids
40
- do_xml_request '/api/images', {}, true
41
- ids = []
42
- (last_xml_response/'images/image').each do |image|
43
- ids << image['id'].to_s
44
- end
45
- ids.sort.should == ids.sort.uniq
46
- end
47
-
48
- def test_it_has_valid_urls
49
- do_xml_request '/api/images', {}, true
50
- ids = []
51
- images = (last_xml_response/'images/image')
52
- images.each do |image|
53
- do_xml_request image['href'].to_s, {}, true
54
- (last_xml_response/'image').first['href'].should == image['href'].to_s
55
- end
56
- end
57
-
58
- def test_it_can_filter_using_owner_id
59
- do_xml_request '/api/images', { :owner_id => 'mockuser' }, true
60
- (last_xml_response/'images/image').size.should == 1
61
- (last_xml_response/'images/image/owner_id').first.text.should == 'mockuser'
62
- end
63
-
64
- def test_it_can_filter_using_unknown_owner_id
65
- do_xml_request '/api/images', { :architecture => 'unknown_user' }, true
66
- (last_xml_response/'images/image').size.should == 0
67
- end
68
-
69
- def test_it_can_filter_using_architecture
70
- do_xml_request '/api/images', { :architecture => 'x86_64' }, true
71
- (last_xml_response/'images/image').size.should == 1
72
- (last_xml_response/'images/image/architecture').first.text.should == 'x86_64'
73
- end
74
-
75
- def test_it_can_filter_using_unknown_architecture
76
- do_xml_request '/api/images', { :architecture => 'unknown_arch' }, true
77
- (last_xml_response/'images/image').size.should == 0
78
- end
79
-
80
- def test_it_responses_to_json
81
- do_request '/api/images', {}, true, { :format => :json }
82
- JSON::parse(last_response.body).class.should == Hash
83
- JSON::parse(last_response.body)['images'].class.should == Array
84
-
85
- do_request '/api/images/img1', {}, true, { :format => :json }
86
- last_response.status.should == 200
87
- JSON::parse(last_response.body).class.should == Hash
88
- JSON::parse(last_response.body)['image'].class.should == Hash
89
- end
90
-
91
- def test_it_responses_to_html
92
- do_request '/api/images', {}, true, { :format => :html }
93
- last_response.status.should == 200
94
- Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
95
-
96
- do_request '/api/images/img1', {}, true, { :format => :html }
97
- last_response.status.should == 200
98
- Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
99
- end
100
-
101
- private
102
-
103
- def test_image_attributes(image)
104
- (image/'name').text.should_not nil
105
- (image/'owner_id').text.should_not nil
106
- (image/'description').text.should_not nil
107
- (image/'architecture').text.should_not nil
108
- end
109
-
110
- end
111
- end
@@ -1,51 +0,0 @@
1
- require 'tests/common'
2
-
3
- module DeltacloudUnitTest
4
- class RealmsTest < Test::Unit::TestCase
5
- include Rack::Test::Methods
6
-
7
- def app
8
- Sinatra::Application
9
- end
10
-
11
- def test_it_not_require_authentication
12
- require_authentication?('/api/realms').should_not == true
13
- end
14
-
15
- def test_it_returns_instance_states
16
- do_xml_request '/api/instance_states', {}, true
17
- (last_xml_response/'states/state').map.size.should > 0
18
- end
19
-
20
- def test_each_state_has_transition
21
- do_xml_request '/api/instance_states', {}, true
22
- (last_xml_response/'states/state').each do |state|
23
- next if state['name'].eql?('finish') # Finnish state doesn't have transitions
24
- (state/'transition').map.size.should > 0
25
- (state/'transition').each do |transition|
26
- transition['to'].should_not == nil
27
- end
28
- end
29
- end
30
-
31
- def test_it_responses_to_json
32
- do_request '/api/instance_states', {}, false, { :format => :json }
33
- JSON::parse(last_response.body).class.should == Array
34
- JSON::parse(last_response.body).first['transitions'].class.should == Array
35
- JSON::parse(last_response.body).first['name'].should == 'start'
36
- end
37
-
38
- def test_it_responses_to_html
39
- do_request '/api/instance_states', {}, false, { :format => :html }
40
- last_response.status.should == 200
41
- Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
42
- end
43
-
44
- def test_it_responses_to_png
45
- do_request '/api/instance_states', { :format => 'png' }, false
46
- last_response.status.should == 200
47
- last_response.headers['Content-Type'].should == 'image/png'
48
- end
49
-
50
- end
51
- end
@@ -1,222 +0,0 @@
1
- require 'tests/common'
2
-
3
- module DeltacloudUnitTest
4
- class InstancesTest < Test::Unit::TestCase
5
- include Rack::Test::Methods
6
-
7
- def app
8
- Sinatra::Application
9
- end
10
-
11
- def test_it_require_authentication
12
- require_authentication?('/api/instances').should == true
13
- end
14
-
15
- def test_it_returns_instances
16
- do_xml_request '/api/instances', {}, true
17
- (last_xml_response/'instances/instance').map.size.should > 0
18
- end
19
-
20
- def test_it_has_correct_attributes_set
21
- do_xml_request '/api/images', {}, true
22
- (last_xml_response/'images/image').each do |image|
23
- image.attributes.keys.sort.should == [ 'href', 'id' ]
24
- end
25
- end
26
-
27
- def test_it_has_unique_ids
28
- do_xml_request '/api/instances', {}, true
29
- ids = []
30
- (last_xml_response/'instances/instance').each do |image|
31
- ids << image['id'].to_s
32
- end
33
- ids.sort.should == ids.sort.uniq
34
- end
35
-
36
- def test_inst1_has_correct_attributes
37
- do_xml_request '/api/instances', {}, true
38
- instance = (last_xml_response/'instances/instance[@id="inst1"]')
39
- test_instance_attributes(instance)
40
- end
41
-
42
- def test_it_returns_valid_realm
43
- do_xml_request '/api/instances/inst1', {}, true
44
- instance = (last_xml_response/'instance')
45
- test_instance_attributes(instance)
46
- end
47
-
48
- def test_it_responses_to_json
49
- do_request '/api/instances', {}, true, { :format => :json }
50
- JSON::parse(last_response.body).class.should == Hash
51
- JSON::parse(last_response.body)['instances'].class.should == Array
52
-
53
- do_request '/api/instances/inst1', {}, true, { :format => :json }
54
- last_response.status.should == 200
55
- JSON::parse(last_response.body).class.should == Hash
56
- JSON::parse(last_response.body)['instance'].class.should == Hash
57
- end
58
-
59
- def test_it_responses_to_html
60
- do_request '/api/instances', {}, true, { :format => :html }
61
- last_response.status.should == 200
62
- Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
63
-
64
- do_request '/api/instances/inst1', {}, true, { :format => :html }
65
- last_response.status.should == 200
66
- Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
67
- end
68
-
69
- def test_it_create_a_new_instance_using_image_id
70
- params = {
71
- :image_id => 'img1'
72
- }
73
- header 'Accept', accept_header(:xml)
74
- post '/api/instances', params, authenticate
75
- last_response.status.should == 201
76
- last_response.headers['Location'].should_not == nil
77
- do_xml_request last_response.headers['Location'], {}, true
78
- (last_xml_response/'instance/name').should_not == nil
79
- add_created_instance (last_xml_response/'instance').first['id']
80
- test_instance_attributes(last_xml_response/'instance')
81
- end
82
-
83
- def test_it_create_a_new_instance_using_image_id_and_name
84
- params = {
85
- :image_id => 'img1',
86
- :name => "unit_test_instance1"
87
- }
88
- header 'Accept', accept_header(:xml)
89
- post '/api/instances', params, authenticate(:format => :xml)
90
- last_response.status.should == 201
91
- last_response.headers['Location'].should_not == nil
92
- do_xml_request last_response.headers['Location'], {}, true
93
- (last_xml_response/'instance/name').text.should == 'unit_test_instance1'
94
- add_created_instance (last_xml_response/'instance').first['id']
95
- test_instance_attributes(last_xml_response/'instance')
96
- end
97
-
98
- def test_it_create_a_new_instance_using_image_id_and_name_and_hwp
99
- params = {
100
- :image_id => 'img1',
101
- :name => "unit_test_instance1",
102
- :hwp_id => "m1-xlarge"
103
- }
104
- header 'Accept', accept_header(:xml)
105
- post '/api/instances', params, authenticate(:format => :xml)
106
- last_response.status.should == 201
107
- last_response.headers['Location'].should_not == nil
108
- do_xml_request last_response.headers['Location'], {}, true
109
- (last_xml_response/'instance/name').text.should == 'unit_test_instance1'
110
- (last_xml_response/'instance/hardware_profile').first['id'].should == 'm1-xlarge'
111
- add_created_instance (last_xml_response/'instance').first['id']
112
- test_instance_attributes(last_xml_response/'instance')
113
- end
114
-
115
- def test_it_z0_stop_and_start_instance
116
- $created_instances.each do |instance_id|
117
- do_xml_request "/api/instances/#{instance_id}", {}, true
118
- stop_url = (last_xml_response/'actions/link[@rel="stop"]').first['href']
119
- stop_url.should_not == nil
120
- post create_url(stop_url), { :format => 'xml' }, authenticate
121
- last_response.status.should == 200
122
- instance = Nokogiri::XML(last_response.body)
123
- test_instance_attributes(instance)
124
- (instance/'state').text.should == 'STOPPED'
125
- do_xml_request "/api/instances/#{instance_id}", {}, true
126
- start_url = (last_xml_response/'actions/link[@rel="start"]').first['href']
127
- start_url.should_not == nil
128
- post create_url(start_url), { :format => 'xml'}, authenticate
129
- last_response.status.should == 200
130
- instance = Nokogiri::XML(last_response.body)
131
- test_instance_attributes(instance)
132
- (instance/'state').text.should == 'RUNNING'
133
- end
134
- end
135
-
136
- def test_z0_reboot_instance
137
- $created_instances.each do |instance_id|
138
- do_xml_request "/api/instances/#{instance_id}", {}, true
139
- reboot_url = (last_xml_response/'actions/link[@rel="reboot"]').first['href']
140
- reboot_url.should_not == nil
141
- post create_url(reboot_url), { :format => "xml"}, authenticate
142
- last_response.status.should == 200
143
- instance = Nokogiri::XML(last_response.body)
144
- test_instance_attributes(instance)
145
- (instance/'state').text.should == 'RUNNING'
146
- end
147
- end
148
-
149
- def test_z1_stop_created_instances
150
- $created_instances.each do |instance_id|
151
- do_xml_request "/api/instances/#{instance_id}", {}, true
152
- stop_url = (last_xml_response/'actions/link[@rel="stop"]').first['href']
153
- stop_url.should_not == nil
154
- post create_url(stop_url), {}, authenticate
155
- last_response.status.should == 200
156
- instance = Nokogiri::XML(last_response.body)
157
- test_instance_attributes(instance)
158
- (instance/'state').text.should == 'STOPPED'
159
- end
160
- end
161
-
162
- def test_z2_destroy_created_instances
163
- $created_instances.each do |instance_id|
164
- do_xml_request "/api/instances/#{instance_id}", {}, true
165
- destroy_url = (last_xml_response/'actions/link[@rel="destroy"]').first['href']
166
- destroy_url.should_not == nil
167
- delete create_url(destroy_url), {}, authenticate
168
- last_response.status.should == 302
169
- do_xml_request last_response.headers['Location'], {}, true
170
- (last_xml_response/'instances').should_not == nil
171
- do_xml_request "/api/instances/#{instance_id}", {}, true
172
- last_response.status.should == 404
173
- end
174
- end
175
-
176
- private
177
-
178
- def test_instance_attributes(instance)
179
- (instance/'name').should_not == nil
180
- (instance/'owner_id').should_not == nil
181
- ['RUNNING', 'STOPPED'].include?((instance/'state').text).should == true
182
-
183
- (instance/'public_addreses').should_not == nil
184
- (instance/'public_addresses/address').map.size.should > 0
185
- (instance/'public_addresses/address').first.text.should_not == ""
186
-
187
- (instance/'private_addresses').should_not == nil
188
- (instance/'private_addresses/address').map.size.should > 0
189
- (instance/'private_addresses/address').first.text.should_not == ""
190
-
191
- (instance/'actions/link').map.size.should > 0
192
- (instance/'actions/link').each do |link|
193
- link['href'].should_not == ""
194
- link['rel'].should_not == ""
195
- link['method'].should_not == ""
196
- ['get', 'post', 'delete', 'put'].include?(link['method']).should == true
197
- end
198
-
199
- (instance/'image').size.should > 0
200
- (instance/'image').first['href'].should_not == ""
201
- (instance/'image').first['id'].should_not == ""
202
- do_xml_request (instance/'image').first['href'], {}, true
203
- (last_xml_response/'image').should_not == nil
204
- (last_xml_response/'image').first['href'] == (instance/'image').first['href']
205
-
206
- (instance/'realm').size.should > 0
207
- (instance/'realm').first['href'].should_not == ""
208
- (instance/'realm').first['id'].should_not == ""
209
- do_xml_request (instance/'realm').first['href']
210
- (last_xml_response/'realm').should_not == nil
211
- (last_xml_response/'realm').first['href'] == (instance/'realm').first['href']
212
-
213
- (instance/'hardware_profile').size.should > 0
214
- (instance/'hardware_profile').first['href'].should_not == ""
215
- (instance/'hardware_profile').first['id'].should_not == ""
216
- do_xml_request (instance/'hardware_profile').first['href']
217
- (last_xml_response/'hardware_profile').should_not == nil
218
- (last_xml_response/'hardware_profile').first['href'] == (instance/'hardware_profile').first['href']
219
- end
220
-
221
- end
222
- end
data/tests/realms_test.rb DELETED
@@ -1,78 +0,0 @@
1
- require 'tests/common'
2
-
3
- module DeltacloudUnitTest
4
- class RealmsTest < Test::Unit::TestCase
5
- include Rack::Test::Methods
6
-
7
- def app
8
- Sinatra::Application
9
- end
10
-
11
- def test_it_not_require_authentication
12
- require_authentication?('/api/realms').should_not == true
13
- end
14
-
15
- def test_it_returns_realms
16
- do_xml_request '/api/realms', {}, true
17
- (last_xml_response/'realms/realm').map.size.should > 0
18
- end
19
-
20
- def test_it_has_correct_attributes_set
21
- do_xml_request '/api/realms', {}, true
22
- (last_xml_response/'realms/realm').each do |realm|
23
- realm.attributes.keys.sort.should == [ 'href', 'id' ]
24
- end
25
- end
26
-
27
- def test_us_has_correct_attributes
28
- do_xml_request '/api/realms', {}, true
29
- realm = (last_xml_response/'realms/realm[@id="us"]')
30
- test_realm_attributes(realm)
31
- end
32
-
33
- def test_it_returns_valid_realm
34
- do_xml_request '/api/realms/us', {}, true
35
- realm = (last_xml_response/'realm')
36
- test_realm_attributes(realm)
37
- end
38
-
39
- def test_it_has_unique_ids
40
- do_xml_request '/api/realms', {}, true
41
- ids = []
42
- (last_xml_response/'realms/realm').each do |realm|
43
- ids << realm['id'].to_s
44
- end
45
- ids.sort.should == ids.sort.uniq
46
- end
47
-
48
- def test_it_responses_to_json
49
- do_request '/api/realms', {}, false, { :format => :json }
50
- JSON::parse(last_response.body).class.should == Hash
51
- JSON::parse(last_response.body)['realms'].class.should == Array
52
-
53
- do_request '/api/realms/us', {}, false, { :format => :json }
54
- last_response.status.should == 200
55
- JSON::parse(last_response.body).class.should == Hash
56
- JSON::parse(last_response.body)['realm'].class.should == Hash
57
- end
58
-
59
- def test_it_responses_to_html
60
- do_request '/api/realms', {}, false, { :format => :html }
61
- last_response.status.should == 200
62
- Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
63
-
64
- do_request '/api/realms/us', {}, false, { :format => :html }
65
- last_response.status.should == 200
66
- Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
67
- end
68
-
69
- private
70
-
71
- def test_realm_attributes(realm)
72
- (realm/'name').should_not == nil
73
- (realm/'limit').should_not == nil
74
- ['AVAILABLE'].include?((realm/'state').text).should == true
75
- end
76
-
77
- end
78
- end
@@ -1,50 +0,0 @@
1
- require 'tests/common'
2
-
3
- module DeltacloudUnitTest
4
- class UrlForTest < Test::Unit::TestCase
5
- include Rack::Test::Methods
6
-
7
- def app
8
- Sinatra::Application
9
- end
10
-
11
- def test_it_works_for_root
12
- verify_url_for("/", "/")
13
- end
14
-
15
- def test_it_works_for_root_absolute
16
- verify_url_for("/", "http://localhost/", :full)
17
- end
18
-
19
- def test_it_works_with_spaces
20
- verify_url_for("/url with spaces", "/url%20with%20spaces")
21
- end
22
-
23
- def test_it_works_when_given_absolute
24
- verify_url_for("http://test.com", "http://test.com")
25
- end
26
-
27
- def test_it_works_when_not_at_root_context
28
- verify_url_for("/", "context/", :path_only, {}, {"SCRIPT_NAME" => "context"})
29
- end
30
-
31
- def verify_url_for(url, expected_url, mode=:path_only, params={}, rack_env={})
32
- # generate a unique url for each test
33
- test_url = "/url_for_test/#{expected_url.hash}/#{Time.now.to_i}"
34
- # Create our sinatra test endpoint
35
- self.class.create_test_url_content(test_url, url, mode)
36
-
37
- # verify the generated url matches what we expect
38
- get test_url, params, rack_env
39
- last_response.body.should == expected_url
40
- end
41
-
42
- def self.create_test_url_content(test_url, url_content, mode)
43
- get test_url do
44
- content_type "text/plain"
45
- url_for(url_content, mode)
46
- end
47
- end
48
-
49
- end
50
- end