You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2012/05/22 22:19:37 UTC
[7/50] [abbrv] git commit: Google: Partialy fixed the unit tests,
added VCR version to Gemfile
Google: Partialy fixed the unit tests, added VCR version to Gemfile
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/8edf3074
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/8edf3074
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/8edf3074
Branch: refs/heads/master
Commit: 8edf307426057ccd85b1f35817d298ee22ccaa22
Parents: 5d61f5b
Author: Michal Fojtik <mf...@redhat.com>
Authored: Thu May 17 14:06:25 2012 +0200
Committer: Michal fojtik <mf...@redhat.com>
Committed: Tue May 22 22:17:39 2012 +0200
----------------------------------------------------------------------
server/Gemfile | 2 +-
server/tests/drivers/google/api_test.rb | 17 +++--
server/tests/drivers/google/buckets_test.rb | 13 +++--
server/tests/drivers/google/common.rb | 74 ++++++++++++++++++++++
4 files changed, 93 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/8edf3074/server/Gemfile
----------------------------------------------------------------------
diff --git a/server/Gemfile b/server/Gemfile
index 244814c..9bc9375 100644
--- a/server/Gemfile
+++ b/server/Gemfile
@@ -4,7 +4,7 @@ gemspec
group :development do
gem "compass", ">= 0.8.17"
- gem "vcr"
+ gem "vcr", "<=1.11.3"
gem "webmock"
gem "rack-test", ">= 0.5.3"
gem "ci_reporter"
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/8edf3074/server/tests/drivers/google/api_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/google/api_test.rb b/server/tests/drivers/google/api_test.rb
index bd86d95..88ff74d 100644
--- a/server/tests/drivers/google/api_test.rb
+++ b/server/tests/drivers/google/api_test.rb
@@ -1,30 +1,33 @@
-$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
-require 'tests/common'
-
module GoogleTest
class ApiTest < Test::Unit::TestCase
include Rack::Test::Methods
def app
- Sinatra::Application
+ Rack::Builder.new {
+ map '/' do
+ use Rack::Static, :urls => ["/stylesheets", "/javascripts"], :root => "public"
+ run Rack::Cascade.new([Deltacloud::API])
+ end
+ }
end
def test_01_it_returns_entry_points
- get_auth_url '/api;driver=google/?force_auth=1'
+ get_auth_url '/api?force_auth=1'
(last_xml_response/'/api').first[:driver].should == 'google'
(last_xml_response/'/api/link').length.should > 0
end
def test_02_it_has_google_features
- get_url '/api;driver=google'
+ get_url '/api'
features = (last_xml_response/'/api/link[@rel="buckets"]/feature').collect { |f| f[:name] }
features.include?('bucket_location').should == true
features.length.should == 1
end
def test_03_it_has_google_collections
- get_url '/api;driver=google'
+ get_url '/api'
+ puts last_xml_response
collections = (last_xml_response/'/api/link').collect { |f| f[:rel] }
collections.include?('buckets').should == true
collections.include?('drivers').should == true
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/8edf3074/server/tests/drivers/google/buckets_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/google/buckets_test.rb b/server/tests/drivers/google/buckets_test.rb
index dd4e065..dac8c87 100644
--- a/server/tests/drivers/google/buckets_test.rb
+++ b/server/tests/drivers/google/buckets_test.rb
@@ -1,13 +1,15 @@
-$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
-require 'tests/common'
-#require 'webmock/test_unit'
module GoogleTest
class BucketsTest < Test::Unit::TestCase
include Rack::Test::Methods
def app
- Sinatra::Application
+ Rack::Builder.new {
+ map '/' do
+ use Rack::Static, :urls => ["/stylesheets", "/javascripts"], :root => "public"
+ run Rack::Cascade.new([Deltacloud::API])
+ end
+ }
end
@@bucket_name_google="#{@@created_bucket_name}googel"
@@ -75,7 +77,8 @@ module GoogleTest
:'api[driver]' => 'google'
}
head_url "/api/buckets/#{@@bucket_name_google}/#{@@blob_name_google}", params
- last_response.status.should == 204
+ last_response.status.should == 200
+ puts last_response.body
blob_meta_hash = last_response.headers.inject({}){|result, (k,v)| result[k]=v if k=~/^X-Deltacloud-Blobmeta-/i ; result}
blob_meta_hash.gsub_keys(/x-.*meta-/i, "")
({"author"=>"deltacloud", "foo"=>"bar"}.eql?(blob_meta_hash)).should == true
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/8edf3074/server/tests/drivers/google/common.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/google/common.rb b/server/tests/drivers/google/common.rb
new file mode 100644
index 0000000..d9da302
--- /dev/null
+++ b/server/tests/drivers/google/common.rb
@@ -0,0 +1,74 @@
+ENV['API_DRIVER'] = "google"
+ENV['API_USER'] = 'GOOGK7JXLS6UEYS6AYVO'
+ENV['API_PASSWORD'] = 'QjxUunLgszKhBGn/LISQajGR82CfwvraxA9lqnkg'
+
+load File.join(File.dirname(__FILE__), '..', '..', 'common.rb')
+require 'vcr'
+
+DeltacloudTestCommon::record!
+
+VCR.config do |c|
+ c.cassette_library_dir = "#{File.dirname(__FILE__)}/fixtures/"
+ c.stub_with :excon
+ c.default_cassette_options = { :record => :new_episodes}
+end
+
+#monkey patch fix for VCR normalisation code:
+#see https://github.com/myronmarston/vcr/issues/4
+#when body is a tempfile, like when creating new blob
+#this method of normalisation fails and excon throws errors
+#(Excon::Errors::SocketError:can't convert Tempfile into String)
+#
+#RELEVANT: https://github.com/myronmarston/vcr/issues/101
+#(will need revisiting when vcr 2 comes along)
+
+module VCR
+ module Normalizers
+ module Body
+
+ private
+ def normalize_body
+ self.body = case body
+ when nil, ''; nil
+ else
+ String.new(body) unless body.is_a?(Tempfile)
+ end
+ end
+ end
+ end
+end
+
+module Deltacloud
+ module Test
+ include Rack::Test::Methods
+
+ def included?(sub)
+ sub.class_eval do
+ before do
+ header 'Accept', 'application/xml'
+ end
+ end
+ end
+
+ def xml_response
+ Nokogiri::XML(last_response.body)
+ end
+
+ def auth_as_mock
+ authorize ENV['API_USERNAME'], ENV['API_PASSWORD']
+ end
+
+ def collection_url(collection)
+ [Deltacloud[:root_url], collection.to_s].join('/')
+ end
+
+ def app
+ Rack::Builder.new {
+ map '/' do
+ use Rack::Static, :urls => ["/stylesheets", "/javascripts"], :root => "public"
+ run Rack::Cascade.new([Deltacloud::API])
+ end
+ }
+ end
+ end
+end