From: Michal Fojtik <[email protected]>
---
server/tests/common.rb | 19 +++++++-----
server/tests/instance_states_test.rb | 3 +-
server/tests/instances_test.rb | 21 ++++++++------
server/tests/url_for_test.rb | 2 +-
server/views/instance_states/show.gv.erb | 45 -----------------------------
server/views/instance_states/show.png.erb | 45 +++++++++++++++++++++++++++++
6 files changed, 70 insertions(+), 65 deletions(-)
delete mode 100644 server/views/instance_states/show.gv.erb
create mode 100644 server/views/instance_states/show.png.erb
diff --git a/server/tests/common.rb b/server/tests/common.rb
index b38f246..d848e3b 100644
--- a/server/tests/common.rb
+++ b/server/tests/common.rb
@@ -33,11 +33,11 @@ module DeltacloudTestCommon
"Basic " +
Base64.encode64("#{credentials[:user]}:#{credentials[:password]}")
end
- def authenticate(opts={ :format => :xml })
+ def authenticate(opts={})
credentials = opts[:credentials] || { :user => ENV['API_USER'], :password
=> ENV['API_PASSWORD']}
return {
'HTTP_AUTHORIZATION' => auth_hash(credentials),
- }.merge(accept_header(opts[:format]))
+ }
end
def default_headers
@@ -46,21 +46,24 @@ module DeltacloudTestCommon
def accept_header(format=:xml)
case format
- when :json then { 'Accept' => 'application/json' }
- when :xml then { 'Accept' => 'application/xml;q=1' }
- else { 'Accept' => 'application/xhtml+xml;text/html' }
- end.merge(default_headers)
+ when :json then 'application/json;q=0.9'
+ when :html then 'text/html;q=0.9'
+ when :xml then 'application/xml;q=0.9'
+ else 'application/xml;q=0.9'
+ end
end
def create_url(url, format = :xml)
- "#{url}.#{format.to_s}"
+ "#{url}"
end
def do_request(uri, params=nil, authentication=false, opts={ :format => :xml
})
- get create_url(uri, opts[:format]), params || {}, (authentication) ?
authenticate(opts) : {}
+ header 'Accept', accept_header(opts[:format])
+ get create_url(uri), params || {}, (authentication) ? authenticate(opts) :
{}
end
def do_xml_request(uri, params=nil, authentication=false)
+ header 'Accept', accept_header(:xml)
get create_url(uri), params || {}, (authentication) ? authenticate : {}
puts "[401] Authentication required to get #{uri}" if last_response.status
== 401
if last_response.status == 200
diff --git a/server/tests/instance_states_test.rb
b/server/tests/instance_states_test.rb
index 3de7be7..77acf3c 100644
--- a/server/tests/instance_states_test.rb
+++ b/server/tests/instance_states_test.rb
@@ -42,10 +42,9 @@ module DeltacloudUnitTest
end
def test_it_responses_to_png
- do_request '/api/instance_states', {}, false, { :format => :png }
+ do_request '/api/instance_states.png', {}, false
last_response.status.should == 200
last_response.headers['Content-Type'].should == 'image/png'
- #last_response.headers['Content-Length'].should == '4371'
end
end
diff --git a/server/tests/instances_test.rb b/server/tests/instances_test.rb
index 276ff3d..b1a4404 100644
--- a/server/tests/instances_test.rb
+++ b/server/tests/instances_test.rb
@@ -70,8 +70,9 @@ module DeltacloudUnitTest
params = {
:image_id => 'img1'
}
- post '/api/instances', params, authenticate(:format => :xml)
- last_response.status.should == 302
+ header 'Accept', accept_header(:xml)
+ post '/api/instances', params, authenticate
+ last_response.status.should == 201
last_response.headers['Location'].should_not == nil
do_xml_request last_response.headers['Location'], {}, true
(last_xml_response/'instance/name').should_not == nil
@@ -84,8 +85,9 @@ module DeltacloudUnitTest
:image_id => 'img1',
:name => "unit_test_instance1"
}
+ header 'Accept', accept_header(:xml)
post '/api/instances', params, authenticate(:format => :xml)
- last_response.status.should == 302
+ last_response.status.should == 201
last_response.headers['Location'].should_not == nil
do_xml_request last_response.headers['Location'], {}, true
(last_xml_response/'instance/name').text.should == 'unit_test_instance1'
@@ -99,8 +101,9 @@ module DeltacloudUnitTest
:name => "unit_test_instance1",
:hwp_id => "m1-xlarge"
}
+ header 'Accept', accept_header(:xml)
post '/api/instances', params, authenticate(:format => :xml)
- last_response.status.should == 302
+ last_response.status.should == 201
last_response.headers['Location'].should_not == nil
do_xml_request last_response.headers['Location'], {}, true
(last_xml_response/'instance/name').text.should == 'unit_test_instance1'
@@ -114,7 +117,7 @@ module DeltacloudUnitTest
do_xml_request "/api/instances/#{instance_id}", {}, true
stop_url =
(last_xml_response/'actions/li...@rel="stop"]').first['href']
stop_url.should_not == nil
- post create_url(stop_url), {}, authenticate(:format => :xml)
+ post create_url(stop_url), { :format => 'xml' }, authenticate
last_response.status.should == 200
instance = Nokogiri::XML(last_response.body)
test_instance_attributes(instance)
@@ -122,7 +125,7 @@ module DeltacloudUnitTest
do_xml_request "/api/instances/#{instance_id}", {}, true
start_url =
(last_xml_response/'actions/li...@rel="start"]').first['href']
start_url.should_not == nil
- post create_url(start_url), {}, authenticate(:format => :xml)
+ post create_url(start_url), { :format => 'xml'}, authenticate
last_response.status.should == 200
instance = Nokogiri::XML(last_response.body)
test_instance_attributes(instance)
@@ -135,7 +138,7 @@ module DeltacloudUnitTest
do_xml_request "/api/instances/#{instance_id}", {}, true
reboot_url =
(last_xml_response/'actions/li...@rel="reboot"]').first['href']
reboot_url.should_not == nil
- post create_url(reboot_url), {}, authenticate(:format => :xml)
+ post create_url(reboot_url), { :format => "xml"}, authenticate
last_response.status.should == 200
instance = Nokogiri::XML(last_response.body)
test_instance_attributes(instance)
@@ -148,7 +151,7 @@ module DeltacloudUnitTest
do_xml_request "/api/instances/#{instance_id}", {}, true
stop_url =
(last_xml_response/'actions/li...@rel="stop"]').first['href']
stop_url.should_not == nil
- post create_url(stop_url), {}, authenticate(:format => :xml)
+ post create_url(stop_url), {}, authenticate
last_response.status.should == 200
instance = Nokogiri::XML(last_response.body)
test_instance_attributes(instance)
@@ -161,7 +164,7 @@ module DeltacloudUnitTest
do_xml_request "/api/instances/#{instance_id}", {}, true
destroy_url =
(last_xml_response/'actions/li...@rel="destroy"]').first['href']
destroy_url.should_not == nil
- delete create_url(destroy_url), {}, authenticate(:format => :xml)
+ delete create_url(destroy_url), {}, authenticate
last_response.status.should == 302
do_xml_request last_response.headers['Location'], {}, true
(last_xml_response/'instances').should_not == nil
diff --git a/server/tests/url_for_test.rb b/server/tests/url_for_test.rb
index 805cf11..400821d 100644
--- a/server/tests/url_for_test.rb
+++ b/server/tests/url_for_test.rb
@@ -30,7 +30,7 @@ module DeltacloudUnitTest
def verify_url_for(url, expected_url, mode=:path_only, params={},
rack_env={})
# generate a unique url for each test
- test_url = "/url_for_test/#{expected_url.hash}/#{Time.now.to_f}"
+ test_url = "/url_for_test/#{expected_url.hash}/#{Time.now.to_i}"
# Create our sinatra test endpoint
self.class.create_test_url_content(test_url, url, mode)
diff --git a/server/views/instance_states/show.gv.erb
b/server/views/instance_states/show.gv.erb
deleted file mode 100644
index e3f97a7..0000000
--- a/server/views/instance_states/show.gv.erb
+++ /dev/null
@@ -1,45 +0,0 @@
-digraph instance_states {
- rankdir=LR;
- <% for state in @machine.states do %>
- <%= state %>
- [
- label="<%= state.to_s.titlecase %>",
- labelloc="c",
- fontsize="12.0",
- <% if ( state.name == :start || state.name == :finish ) %>
- fontname="Liberation Sans Bold",
- color="<%= state.name == :start ? '#449944' : '#994444' %>",
- fillcolor="<%= state.name == :start ? '#88DD88' : '#DD8888' %>",
- style="filled",
- shape="doublecircle",
- <% else %>
- fontname="Liberation Sans Bold",
- shape="rect",
- color="#999999",
- fillcolor="#DDDDDD",
- style="filled",
- <% end %>
- height=0.5
- ]
- <% end %>
-
- <% for state in @machine.states do %>
- <% for transition in state.transitions do %>
- <%= state %> -> <%= transition.destination %>
- [
- label="<%= transition.automatically? ? 'auto' : transition.action
%>",
- fontsize="14.0",
- penwidth="2.0",
- labelloc="t",
- color="#CCCCCC",
- <% if transition.automatically? %>
- fontcolor="#227722",
- fontname="Liberation Sans Bold Italic",
- <% else %>
- fontcolor="#333333",
- fontname="Liberation Sans Bold",
- <% end %>
- ];
- <% end %>
- <% end %>
-}
diff --git a/server/views/instance_states/show.png.erb
b/server/views/instance_states/show.png.erb
new file mode 100644
index 0000000..e3f97a7
--- /dev/null
+++ b/server/views/instance_states/show.png.erb
@@ -0,0 +1,45 @@
+digraph instance_states {
+ rankdir=LR;
+ <% for state in @machine.states do %>
+ <%= state %>
+ [
+ label="<%= state.to_s.titlecase %>",
+ labelloc="c",
+ fontsize="12.0",
+ <% if ( state.name == :start || state.name == :finish ) %>
+ fontname="Liberation Sans Bold",
+ color="<%= state.name == :start ? '#449944' : '#994444' %>",
+ fillcolor="<%= state.name == :start ? '#88DD88' : '#DD8888' %>",
+ style="filled",
+ shape="doublecircle",
+ <% else %>
+ fontname="Liberation Sans Bold",
+ shape="rect",
+ color="#999999",
+ fillcolor="#DDDDDD",
+ style="filled",
+ <% end %>
+ height=0.5
+ ]
+ <% end %>
+
+ <% for state in @machine.states do %>
+ <% for transition in state.transitions do %>
+ <%= state %> -> <%= transition.destination %>
+ [
+ label="<%= transition.automatically? ? 'auto' : transition.action
%>",
+ fontsize="14.0",
+ penwidth="2.0",
+ labelloc="t",
+ color="#CCCCCC",
+ <% if transition.automatically? %>
+ fontcolor="#227722",
+ fontname="Liberation Sans Bold Italic",
+ <% else %>
+ fontcolor="#333333",
+ fontname="Liberation Sans Bold",
+ <% end %>
+ ];
+ <% end %>
+ <% end %>
+}
--
1.7.2.3