Parent

Included Modules

Class/Module Index [+]

Quicksearch

DeltacloudUnitTest::ApiTest

Public Instance Methods

app() click to toggle source
# File tests/drivers/mock/api_test.rb, line 24
def app
  Sinatra::Application
end
setup() click to toggle source
# File tests/rabbit_test.rb, line 27
def setup
  @app ||= Sinatra::Application
  @driver ||= Deltacloud::Drivers::Mock::MockDriver.new
end
teardown() click to toggle source
# File tests/rabbit_test.rb, line 32
def teardown
  @app = nil
  @driver = nil
end
test_effective_params() click to toggle source
# File tests/rabbit_test.rb, line 42
def test_effective_params
  features = @driver.features(:instances).collect { |f| f.name }
  features.should =~ [:hardware_profiles, :user_name, :authentication_key, :user_data]

  op = @app.collections[:instances].operations[:create]
  op.effective_params(@driver).keys.should =~ [:image_id, :hwp_memory, :hwp_id, :keyname, :name, :hwp_storage, :realm_id, :user_data, :hwp_architecture, :hwp_cpu]

  op.params.keys =~ [:realm_id, :image_id, :hwp_id]
end
test_it_allows_accessing_docs() click to toggle source
# File tests/drivers/mock/api_test.rb, line 76
def test_it_allows_accessing_docs
  get_url '/api/docs/instances'
  last_response.status.should == 200

  with_provider("storage") do
    get_url '/api/docs/instances'
    last_response.status.should == 403
  end
end
test_it_change_features_after_driver_change() click to toggle source
# File tests/drivers/mock/api_test.rb, line 123
def test_it_change_features_after_driver_change
  get_auth_url "/api;driver=ec2"
  (last_xml_response/'api/link[@rel="instances"]/feature[@name="user_name"]').first.should == nil
  (last_xml_response/'api/link[@rel="instances"]/feature[@name="user_data"]').first.should_not == nil
  get_auth_url "/api;driver=mock"
  (last_xml_response/'api/link[@rel="instances"]/feature[@name="user_name"]').first.should_not == nil
  (last_xml_response/'api/link[@rel="instances"]/feature[@name="firewalls"]').first.should == nil
end
test_it_expose_available_drivers() click to toggle source
# File tests/drivers/mock/api_test.rb, line 92
def test_it_expose_available_drivers
  get_auth_url '/api/drivers'
  last_response.status.should == 200
  (last_xml_response/"drivers").length.should > 0
  (last_xml_response/'drivers/driver').length.should > 0
  (last_xml_response/"drivers/driver[@id = 'mock']").length.should == 1
end
test_it_expose_ec2_driver_entrypoints() click to toggle source
# File tests/drivers/mock/api_test.rb, line 100
def test_it_expose_ec2_driver_entrypoints
  get_auth_url '/api/drivers'
  last_response.status.should == 200
  ec2 = (last_xml_response/'drivers/driver[@id=ec2]').first
  (ec2/"provider").length.should > 0
  (ec2/"provider[@id = 'eu-west-1']").length.should == 1
  get_auth_url ec2[:href]
  eu_west = (last_xml_response/"provider[@id = 'eu-west-1']").first
  (eu_west/"entrypoint").length.should > 0
  (eu_west/"entrypoint[@kind = 'ec2']").length.should == 1
end
test_it_handles_unsupported_collections() click to toggle source
# File tests/drivers/mock/api_test.rb, line 66
def test_it_handles_unsupported_collections
  get_auth_url '/api/no_such_collection'
  last_response.status.should == 404

  with_provider("storage") do
    get_auth_url '/api/instances'
    last_response.status.should == 403
  end
end
test_it_has_correct_attributes_set() click to toggle source
# File tests/drivers/mock/api_test.rb, line 33
def test_it_has_correct_attributes_set
  get_auth_url '/api'
  (last_xml_response/'/api/link').each do |link|
    link.attributes.keys.sort.should == [ 'href', 'rel' ]
  end
end
test_it_respond_to_head() click to toggle source
# File tests/drivers/mock/api_test.rb, line 86
def test_it_respond_to_head
  head '/api/instances'
  last_response.headers['Allow'].should_not == nil
  last_response.headers['Allow'].split(',').include?('HEAD').should == true
end
test_it_responses_to_html() click to toggle source
# File tests/drivers/mock/api_test.rb, line 40
def test_it_responses_to_html
  get_url '/api', {}, { :format => :html }
  last_response.status.should == 200
  Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
end
test_it_responses_to_json() click to toggle source
# File tests/drivers/mock/api_test.rb, line 46
def test_it_responses_to_json
  get_url '/api', {}, { :format => :json }
  last_response.status.should == 200
  JSON::parse(last_response.body).class.should == Hash
  JSON::parse(last_response.body)['api'].class.should == Hash
end
test_it_returns_entry_points() click to toggle source
# File tests/drivers/mock/api_test.rb, line 28
def test_it_returns_entry_points
  get_auth_url '/api'
  (last_xml_response/'/api/link').length.should > 0
end
test_it_supports_matrix_params() click to toggle source
# File tests/drivers/mock/api_test.rb, line 112
def test_it_supports_matrix_params
  get_auth_url "/api;driver=ec2"
  last_response.status.should == 200
  (last_xml_response/'api').first[:driver].should == 'ec2'
  get_auth_url "/api;driver=mock"
  (last_xml_response/'api').first[:driver].should == 'mock'
  get_auth_url "/api;driver=ec2/hardware_profiles"
  (last_xml_response/'hardware_profiles/hardware_profile/@id').map {|n| n.to_s}.include?('m1.small').should == true
  last_response.status.should == 200
end
test_it_switches_drivers() click to toggle source
# File tests/drivers/mock/api_test.rb, line 53
def test_it_switches_drivers
  with_provider("") do
    get_auth_url '/api'
    (last_xml_response/"api/link[rel = 'instances']").first.should_not == nil
  end

  # Switch to storage-only mock driver
  with_provider("storage") do
    get_auth_url '/api'
    (last_xml_response/"api/link[rel = 'instances']").first.should == nil
  end
end
test_params() click to toggle source
# File tests/rabbit_test.rb, line 37
def test_params
  op = @app.collections[:instances].operations[:create]
  op.params.keys =~ [:realm_id, :image_id, :hwp_id]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.