deltacloud-core 0.0.2 → 0.0.3
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/COPYING +176 -502
- data/Rakefile +21 -14
- data/deltacloud.rb +3 -0
- data/lib/deltacloud/base_driver.rb +12 -11
- data/lib/deltacloud/base_driver/base_driver.rb +22 -11
- data/lib/deltacloud/drivers/ec2/ec2_driver.rb +15 -12
- data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +16 -11
- data/lib/deltacloud/drivers/mock/data/images/img1.yml +3 -0
- data/lib/deltacloud/drivers/mock/data/images/img2.yml +3 -0
- data/lib/deltacloud/drivers/mock/data/images/img3.yml +3 -0
- data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +16 -0
- data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +9 -0
- data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +9 -0
- data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap1.yml +4 -0
- data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap2.yml +4 -0
- data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap3.yml +4 -0
- data/lib/deltacloud/drivers/mock/data/storage_volumes/vol1.yml +6 -0
- data/lib/deltacloud/drivers/mock/data/storage_volumes/vol2.yml +6 -0
- data/lib/deltacloud/drivers/mock/data/storage_volumes/vol3.yml +6 -0
- data/lib/deltacloud/drivers/mock/mock_driver.rb +13 -11
- data/lib/deltacloud/drivers/rackspace/rackspace_client.rb +12 -11
- data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +12 -11
- data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +12 -11
- data/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb +12 -11
- data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +14 -12
- data/lib/deltacloud/drivers/terremark/terremark_driver.rb +12 -11
- data/lib/deltacloud/helpers/application_helper.rb +64 -11
- data/lib/deltacloud/helpers/conversion_helper.rb +12 -11
- data/lib/deltacloud/method_serializer.rb +12 -11
- data/lib/deltacloud/models/base_model.rb +12 -11
- data/lib/deltacloud/models/image.rb +12 -11
- data/lib/deltacloud/models/instance.rb +13 -12
- data/lib/deltacloud/models/instance_profile.rb +12 -11
- data/lib/deltacloud/models/realm.rb +12 -11
- data/lib/deltacloud/models/storage_snapshot.rb +12 -11
- data/lib/deltacloud/models/storage_volume.rb +12 -11
- data/lib/drivers.rb +12 -0
- data/lib/sinatra/rabbit.rb +1 -0
- data/lib/sinatra/respond_to.rb +3 -0
- data/server.rb +40 -80
- data/tests/api_test.rb +37 -0
- data/tests/hardware_profiles_test.rb +120 -0
- data/tests/images_test.rb +95 -78
- data/tests/instance_states_test.rb +52 -0
- data/tests/instances_test.rb +193 -110
- data/tests/realms_test.rb +66 -44
- data/views/errors/not_found.html.haml +6 -0
- data/views/errors/not_found.xml.haml +2 -0
- data/views/hardware_profiles/index.xml.haml +1 -1
- data/views/hardware_profiles/show.xml.haml +3 -2
- data/views/images/index.xml.haml +4 -3
- data/views/images/show.xml.haml +2 -2
- data/views/instances/index.xml.haml +6 -8
- data/views/instances/show.xml.haml +9 -10
- data/views/realms/index.xml.haml +1 -3
- data/views/realms/show.xml.haml +4 -5
- data/views/storage_snapshots/index.xml.haml +3 -5
- data/views/storage_snapshots/show.xml.haml +2 -4
- data/views/storage_volumes/index.xml.haml +7 -7
- data/views/storage_volumes/show.xml.haml +2 -4
- metadata +156 -81
- data/tests/deltacloud_test.rb +0 -60
- data/tests/storage_snapshots_test.rb +0 -48
- data/tests/storage_volumes_test.rb +0 -48
@@ -0,0 +1,52 @@
|
|
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', {}, false, { :format => :png }
|
46
|
+
last_response.status.should == 200
|
47
|
+
last_response.headers['Content-Type'].should == 'image/png'
|
48
|
+
#last_response.headers['Content-Length'].should == '4371'
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
data/tests/instances_test.rb
CHANGED
@@ -1,136 +1,219 @@
|
|
1
|
-
require 'tests/
|
1
|
+
require 'tests/common'
|
2
2
|
|
3
|
-
|
3
|
+
module DeltacloudUnitTest
|
4
|
+
class InstancesTest < Test::Unit::TestCase
|
5
|
+
include Rack::Test::Methods
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@options = [:id, :architecture, :memory, :storage]
|
9
|
-
@params = {}
|
10
|
-
self.temp_inst_id = 'inst2'
|
11
|
-
super(*args)
|
12
|
-
end
|
13
|
-
|
14
|
-
attr_accessor :temp_inst_id
|
15
|
-
|
16
|
-
def test_if_instances_are_not_empty
|
17
|
-
get '/api/instances.xml', @params, rack_headers
|
18
|
-
doc = Nokogiri::XML.parse(last_response.body)
|
19
|
-
assert_not_equal 0, doc.xpath('/instances/instance').size
|
20
|
-
end
|
7
|
+
def app
|
8
|
+
Sinatra::Application
|
9
|
+
end
|
21
10
|
|
22
|
-
|
23
|
-
|
24
|
-
send :define_method, method_name do
|
25
|
-
get '/api/instances.xml', @params, rack_headers
|
26
|
-
doc = Nokogiri::XML.parse(last_response.body)
|
27
|
-
instance = doc.xpath('/instances/instance[1]').first
|
28
|
-
assert_not_nil instance.xpath(option.to_s).first
|
11
|
+
def test_it_require_authentication
|
12
|
+
require_authentication?('/api/instances').should == true
|
29
13
|
end
|
30
|
-
end
|
31
14
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
get '/api/instances/inst1.xml', @params, rack_headers
|
36
|
-
doc = Nokogiri::XML.parse(last_response.body)
|
37
|
-
instance = doc.xpath('/instance').first
|
38
|
-
assert_not_nil instance.xpath(option.to_s).first
|
15
|
+
def test_it_returns_instances
|
16
|
+
do_xml_request '/api/instances', {}, true
|
17
|
+
(last_xml_response/'instances/instance').map.size.should > 0
|
39
18
|
end
|
40
|
-
end
|
41
19
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
48
26
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
54
34
|
end
|
55
|
-
end
|
56
35
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
62
41
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
68
47
|
|
69
|
-
|
70
|
-
|
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
|
71
52
|
|
72
|
-
|
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
|
73
58
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
end
|
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'
|
79
63
|
|
80
|
-
|
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
|
81
68
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
69
|
+
def test_it_create_a_new_instance_using_image_id
|
70
|
+
params = {
|
71
|
+
:image_id => 'img1'
|
72
|
+
}
|
73
|
+
post '/api/instances', params, authenticate(:format => :xml)
|
74
|
+
last_response.status.should == 302
|
75
|
+
last_response.headers['Location'].should_not == nil
|
76
|
+
do_xml_request last_response.headers['Location'], {}, true
|
77
|
+
(last_xml_response/'instance/name').should_not == nil
|
78
|
+
add_created_instance (last_xml_response/'instance').first['id']
|
79
|
+
test_instance_attributes(last_xml_response/'instance')
|
80
|
+
end
|
87
81
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
82
|
+
def test_it_create_a_new_instance_using_image_id_and_name
|
83
|
+
params = {
|
84
|
+
:image_id => 'img1',
|
85
|
+
:name => "unit_test_instance1"
|
86
|
+
}
|
87
|
+
post '/api/instances', params, authenticate(:format => :xml)
|
88
|
+
last_response.status.should == 302
|
89
|
+
last_response.headers['Location'].should_not == nil
|
90
|
+
do_xml_request last_response.headers['Location'], {}, true
|
91
|
+
(last_xml_response/'instance/name').text.should == 'unit_test_instance1'
|
92
|
+
add_created_instance (last_xml_response/'instance').first['id']
|
93
|
+
test_instance_attributes(last_xml_response/'instance')
|
94
|
+
end
|
94
95
|
|
95
|
-
|
96
|
+
def test_it_create_a_new_instance_using_image_id_and_name_and_hwp
|
97
|
+
params = {
|
98
|
+
:image_id => 'img1',
|
99
|
+
:name => "unit_test_instance1",
|
100
|
+
:hwp_id => "m1-xlarge"
|
101
|
+
}
|
102
|
+
post '/api/instances', params, authenticate(:format => :xml)
|
103
|
+
last_response.status.should == 302
|
104
|
+
last_response.headers['Location'].should_not == nil
|
105
|
+
do_xml_request last_response.headers['Location'], {}, true
|
106
|
+
(last_xml_response/'instance/name').text.should == 'unit_test_instance1'
|
107
|
+
(last_xml_response/'instance/hardware_profile').first['id'].should == 'm1-xlarge'
|
108
|
+
add_created_instance (last_xml_response/'instance').first['id']
|
109
|
+
test_instance_attributes(last_xml_response/'instance')
|
110
|
+
end
|
96
111
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
112
|
+
def test_it_z0_stop_and_start_instance
|
113
|
+
$created_instances.each do |instance_id|
|
114
|
+
do_xml_request "/api/instances/#{instance_id}", {}, true
|
115
|
+
stop_url = (last_xml_response/'actions/link[@rel="stop"]').first['href']
|
116
|
+
stop_url.should_not == nil
|
117
|
+
post create_url(stop_url), {}, authenticate(:format => :xml)
|
118
|
+
last_response.status.should == 200
|
119
|
+
instance = Nokogiri::XML(last_response.body)
|
120
|
+
test_instance_attributes(instance)
|
121
|
+
(instance/'state').text.should == 'STOPPED'
|
122
|
+
do_xml_request "/api/instances/#{instance_id}", {}, true
|
123
|
+
start_url = (last_xml_response/'actions/link[@rel="start"]').first['href']
|
124
|
+
start_url.should_not == nil
|
125
|
+
post create_url(start_url), {}, authenticate(:format => :xml)
|
126
|
+
last_response.status.should == 200
|
127
|
+
instance = Nokogiri::XML(last_response.body)
|
128
|
+
test_instance_attributes(instance)
|
129
|
+
(instance/'state').text.should == 'RUNNING'
|
130
|
+
end
|
131
|
+
end
|
102
132
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
133
|
+
def test_z0_reboot_instance
|
134
|
+
$created_instances.each do |instance_id|
|
135
|
+
do_xml_request "/api/instances/#{instance_id}", {}, true
|
136
|
+
reboot_url = (last_xml_response/'actions/link[@rel="reboot"]').first['href']
|
137
|
+
reboot_url.should_not == nil
|
138
|
+
post create_url(reboot_url), {}, authenticate(:format => :xml)
|
139
|
+
last_response.status.should == 200
|
140
|
+
instance = Nokogiri::XML(last_response.body)
|
141
|
+
test_instance_attributes(instance)
|
142
|
+
(instance/'state').text.should == 'RUNNING'
|
143
|
+
end
|
144
|
+
end
|
109
145
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
146
|
+
def test_z1_stop_created_instances
|
147
|
+
$created_instances.each do |instance_id|
|
148
|
+
do_xml_request "/api/instances/#{instance_id}", {}, true
|
149
|
+
stop_url = (last_xml_response/'actions/link[@rel="stop"]').first['href']
|
150
|
+
stop_url.should_not == nil
|
151
|
+
post create_url(stop_url), {}, authenticate(:format => :xml)
|
152
|
+
last_response.status.should == 200
|
153
|
+
instance = Nokogiri::XML(last_response.body)
|
154
|
+
test_instance_attributes(instance)
|
155
|
+
(instance/'state').text.should == 'STOPPED'
|
156
|
+
end
|
157
|
+
end
|
115
158
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
159
|
+
def test_z2_destroy_created_instances
|
160
|
+
$created_instances.each do |instance_id|
|
161
|
+
do_xml_request "/api/instances/#{instance_id}", {}, true
|
162
|
+
destroy_url = (last_xml_response/'actions/link[@rel="destroy"]').first['href']
|
163
|
+
destroy_url.should_not == nil
|
164
|
+
delete create_url(destroy_url), {}, authenticate(:format => :xml)
|
165
|
+
last_response.status.should == 302
|
166
|
+
do_xml_request last_response.headers['Location'], {}, true
|
167
|
+
(last_xml_response/'instances').should_not == nil
|
168
|
+
do_xml_request "/api/instances/#{instance_id}", {}, true
|
169
|
+
last_response.status.should == 404
|
170
|
+
end
|
171
|
+
end
|
121
172
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
173
|
+
private
|
174
|
+
|
175
|
+
def test_instance_attributes(instance)
|
176
|
+
(instance/'name').should_not == nil
|
177
|
+
(instance/'owner_id').should_not == nil
|
178
|
+
['RUNNING', 'STOPPED'].include?((instance/'state').text).should == true
|
179
|
+
|
180
|
+
(instance/'public_addreses').should_not == nil
|
181
|
+
(instance/'public_addresses/address').map.size.should > 0
|
182
|
+
(instance/'public_addresses/address').first.text.should_not == ""
|
183
|
+
|
184
|
+
(instance/'private_addresses').should_not == nil
|
185
|
+
(instance/'private_addresses/address').map.size.should > 0
|
186
|
+
(instance/'private_addresses/address').first.text.should_not == ""
|
187
|
+
|
188
|
+
(instance/'actions/link').map.size.should > 0
|
189
|
+
(instance/'actions/link').each do |link|
|
190
|
+
link['href'].should_not == ""
|
191
|
+
link['rel'].should_not == ""
|
192
|
+
link['method'].should_not == ""
|
193
|
+
['get', 'post', 'delete', 'put'].include?(link['method']).should == true
|
194
|
+
end
|
195
|
+
|
196
|
+
(instance/'image').size.should > 0
|
197
|
+
(instance/'image').first['href'].should_not == ""
|
198
|
+
(instance/'image').first['id'].should_not == ""
|
199
|
+
do_xml_request (instance/'image').first['href'], {}, true
|
200
|
+
(last_xml_response/'image').should_not == nil
|
201
|
+
(last_xml_response/'image').first['href'] == (instance/'image').first['href']
|
202
|
+
|
203
|
+
(instance/'realm').size.should > 0
|
204
|
+
(instance/'realm').first['href'].should_not == ""
|
205
|
+
(instance/'realm').first['id'].should_not == ""
|
206
|
+
do_xml_request (instance/'realm').first['href']
|
207
|
+
(last_xml_response/'realm').should_not == nil
|
208
|
+
(last_xml_response/'realm').first['href'] == (instance/'realm').first['href']
|
209
|
+
|
210
|
+
(instance/'hardware_profile').size.should > 0
|
211
|
+
(instance/'hardware_profile').first['href'].should_not == ""
|
212
|
+
(instance/'hardware_profile').first['id'].should_not == ""
|
213
|
+
do_xml_request (instance/'hardware_profile').first['href']
|
214
|
+
(last_xml_response/'hardware_profile').should_not == nil
|
215
|
+
(last_xml_response/'hardware_profile').first['href'] == (instance/'hardware_profile').first['href']
|
216
|
+
end
|
127
217
|
|
128
|
-
def test_005_destroy_instance
|
129
|
-
delete '/api/instances/'+self.temp_inst_id+'.xml', {}, rack_headers
|
130
|
-
doc = Nokogiri::XML.parse(last_response.body)
|
131
|
-
assert last_response.ok?
|
132
218
|
end
|
133
|
-
|
134
|
-
include DeltacloudTest
|
135
|
-
|
136
219
|
end
|
data/tests/realms_test.rb
CHANGED
@@ -1,56 +1,78 @@
|
|
1
|
-
require 'tests/
|
1
|
+
require 'tests/common'
|
2
2
|
|
3
|
-
|
3
|
+
module DeltacloudUnitTest
|
4
|
+
class RealmsTest < Test::Unit::TestCase
|
5
|
+
include Rack::Test::Methods
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@options = [:id, :name, :state]
|
9
|
-
@params = {}
|
10
|
-
super(*args)
|
11
|
-
end
|
7
|
+
def app
|
8
|
+
Sinatra::Application
|
9
|
+
end
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
assert_not_equal 0, doc.xpath('/realms/realm').size
|
17
|
-
end
|
11
|
+
def test_it_not_require_authentication
|
12
|
+
require_authentication?('/api/realms').should_not == true
|
13
|
+
end
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
get '/api/realms.xml', @params, rack_headers
|
23
|
-
doc = Nokogiri::XML.parse(last_response.body)
|
24
|
-
realm = doc.xpath('/realms/realm[1]').first
|
25
|
-
assert_not_nil realm.xpath(option.to_s).first
|
15
|
+
def test_it_returns_realms
|
16
|
+
do_xml_request '/api/realms', {}, true
|
17
|
+
(last_xml_response/'realms/realm').map.size.should > 0
|
26
18
|
end
|
27
|
-
end
|
28
19
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
realm = doc.xpath('/realm').first
|
35
|
-
assert_not_nil realm.xpath(option.to_s).first
|
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
|
36
25
|
end
|
37
|
-
end
|
38
26
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
assert_equal @params[:state], doc.xpath('/realms/realm/state').first.text
|
45
|
-
end
|
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
|
46
32
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
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
|
53
38
|
|
54
|
-
|
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
|
55
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
|
56
78
|
end
|