incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1003006 - in /incubator/deltacloud/trunk/server: tests/common.rb tests/instance_states_test.rb tests/instances_test.rb tests/url_for_test.rb views/instance_states/show.gv.erb views/instance_states/show.png.erb
Date Thu, 30 Sep 2010 10:59:50 GMT
Author: mfojtik
Date: Thu Sep 30 10:59:50 2010
New Revision: 1003006

URL: http://svn.apache.org/viewvc?rev=1003006&view=rev
Log:
Removed extension-based content negotiation for Test::Unit

Added:
    incubator/deltacloud/trunk/server/views/instance_states/show.png.erb
      - copied, changed from r1003005, incubator/deltacloud/trunk/server/views/instance_states/show.gv.erb
Removed:
    incubator/deltacloud/trunk/server/views/instance_states/show.gv.erb
Modified:
    incubator/deltacloud/trunk/server/tests/common.rb
    incubator/deltacloud/trunk/server/tests/instance_states_test.rb
    incubator/deltacloud/trunk/server/tests/instances_test.rb
    incubator/deltacloud/trunk/server/tests/url_for_test.rb

Modified: incubator/deltacloud/trunk/server/tests/common.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/tests/common.rb?rev=1003006&r1=1003005&r2=1003006&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/tests/common.rb (original)
+++ incubator/deltacloud/trunk/server/tests/common.rb Thu Sep 30 10:59:50 2010
@@ -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

Modified: incubator/deltacloud/trunk/server/tests/instance_states_test.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/tests/instance_states_test.rb?rev=1003006&r1=1003005&r2=1003006&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/tests/instance_states_test.rb (original)
+++ incubator/deltacloud/trunk/server/tests/instance_states_test.rb Thu Sep 30 10:59:50 2010
@@ -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

Modified: incubator/deltacloud/trunk/server/tests/instances_test.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/tests/instances_test.rb?rev=1003006&r1=1003005&r2=1003006&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/tests/instances_test.rb (original)
+++ incubator/deltacloud/trunk/server/tests/instances_test.rb Thu Sep 30 10:59:50 2010
@@ -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/link[@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/link[@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/link[@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/link[@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/link[@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

Modified: incubator/deltacloud/trunk/server/tests/url_for_test.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/tests/url_for_test.rb?rev=1003006&r1=1003005&r2=1003006&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/tests/url_for_test.rb (original)
+++ incubator/deltacloud/trunk/server/tests/url_for_test.rb Thu Sep 30 10:59:50 2010
@@ -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)
 

Copied: incubator/deltacloud/trunk/server/views/instance_states/show.png.erb (from r1003005,
incubator/deltacloud/trunk/server/views/instance_states/show.gv.erb)
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/instance_states/show.png.erb?p2=incubator/deltacloud/trunk/server/views/instance_states/show.png.erb&p1=incubator/deltacloud/trunk/server/views/instance_states/show.gv.erb&r1=1003005&r2=1003006&rev=1003006&view=diff
==============================================================================
    (empty)



Mime
View raw message