server/lib/deltacloud/drivers/sbc/sbc_client.rb
#
# Executes a fake request from local fixtures
#
Executes a fake request from local fixtures
Executes a fake request from local fixtures
def mock_request(*args)
    http_method, request_uri, params, headers = args[0].to_sym, args[1], args[2], args[3]
    params ||= {}
    fixture_filename = fixture_filename = "#{Digest::MD5.hexdigest("#{http_method}#{request_uri}#{params.inspect}#{headers.reject{|key, value| key == "Authorization"}}")}.fixture"
    begin
      return read_fake_url(fixture_filename)[2]["body"]
    rescue FixtureNotFound
      if http_method.eql?(:get)
        r = @service.get(@rest_base + request_uri, headers)
      elsif http_method.eql?(:post)
        r = @service.post(@rest_base + request_uri, body, headers)
      elsif http_method.eql?(:put)
        r = @service.put(@rest_base + request_uri, params, headers)
      elsif http_method.eql?(:delete)
        r = @service.delete(@rest_base + request_uri, headers)
      end
      response = {
        "body" => r.body,
        "status" => r.code,
        "Content-Type" => r["Content-Type"]
      }
      fixtures_dir = "../tests/sbc/support/fixtures/"
      FileUtils.mkdir_p(fixtures_dir)
      File.open(File::join(fixtures_dir, fixture_filename), 'w') do |f|
        f.puts [request_uri, http_method, response].to_json
      end
      retry
    end
  end
def mock_request ( * args ) http_method , request_uri , params , headers = args [ 0 ] . to_sym , args [ 1 ] , args [ 2 ] , args [ 3 ] params ||= { } fixture_filename = fixture_filename = "#{Digest::MD5.hexdigest("#{http_method}#{request_uri}#{params.inspect}#{headers.reject{|key, value| key == "Authorization"}}")}.fixture" begin return read_fake_url ( fixture_filename ) [ 2 ] [ "body" ] rescue FixtureNotFound if http_method . eql? ( :get ) r = @service . get ( @rest_base + request_uri , headers ) elsif http_method . eql? ( :post ) r = @service . post ( @rest_base + request_uri , body , headers ) elsif http_method . eql? ( :put ) r = @service . put ( @rest_base + request_uri , params , headers ) elsif http_method . eql? ( :delete ) r = @service . delete ( @rest_base + request_uri , headers ) end response = { "body" => r . body , "status" => r . code , "Content-Type" => r [ "Content-Type" ] } fixtures_dir = "../tests/sbc/support/fixtures/" FileUtils . mkdir_p ( fixtures_dir ) File . open ( File :: join ( fixtures_dir , fixture_filename ) , 'w' ) do | f | f . puts [ request_uri , http_method , response ] . to_json end retry end end
Executes a fake request from local fixtures
Executes a fake request from local fixtures
args
<not_specific>