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
[29/50] [abbrv] git commit: Tests: Fixed mock Cucumber tests to work
for Sinatra::Base
Tests: Fixed mock Cucumber tests to work for Sinatra::Base
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/b1afb020
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/b1afb020
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/b1afb020
Branch: refs/heads/master
Commit: b1afb020ee338b577fa395eba411630bb154cc5f
Parents: fee76ea
Author: Michal Fojtik <mf...@redhat.com>
Authored: Mon May 7 14:50:17 2012 +0200
Committer: Michal fojtik <mf...@redhat.com>
Committed: Tue May 22 22:17:36 2012 +0200
----------------------------------------------------------------------
server/lib/deltacloud/helpers/deltacloud_helper.rb | 5 ++
server/lib/deltacloud/helpers/url_helper.rb | 4 +-
server/lib/deltacloud/models/instance.rb | 4 ++
server/views/instances/show.xml.haml | 4 +-
tests/ec2/api.feature | 3 +-
tests/ec2/step_definitions/api_steps.rb | 37 ++++++++-------
tests/ec2/support/env.rb | 31 ++++++-------
tests/mock/api.feature | 1 -
tests/mock/images.feature | 2 +
tests/mock/step_definitions/images_steps.rb | 14 +++---
tests/mock/storage_snapshots.feature | 1 +
11 files changed, 58 insertions(+), 48 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b1afb020/server/lib/deltacloud/helpers/deltacloud_helper.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/helpers/deltacloud_helper.rb b/server/lib/deltacloud/helpers/deltacloud_helper.rb
index ee9decc..2fc2a59 100644
--- a/server/lib/deltacloud/helpers/deltacloud_helper.rb
+++ b/server/lib/deltacloud/helpers/deltacloud_helper.rb
@@ -26,6 +26,11 @@ module Deltacloud::Helpers
end
end
+ def auth_feature_name
+ return 'key' if driver.class.has_feature?(:instances, :authentication_key)
+ return 'password' if driver.class.has_feature?(:instances, :authentication_password)
+ end
+
def instance_action_method(action)
action_method(action, Sinatra::Rabbit::InstancesCollection)
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b1afb020/server/lib/deltacloud/helpers/url_helper.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/helpers/url_helper.rb b/server/lib/deltacloud/helpers/url_helper.rb
index fd71f43..b35c714 100644
--- a/server/lib/deltacloud/helpers/url_helper.rb
+++ b/server/lib/deltacloud/helpers/url_helper.rb
@@ -79,7 +79,7 @@ module Sinatra
def url_for url_fragment, mode=:path_only
case mode
when :path_only
- base = request.script_name
+ base = request.script_name.empty? ? API_ROOT_URL : request.script_name
when :full
scheme = request.scheme
port = request.port
@@ -96,7 +96,7 @@ module Sinatra
else
port = ":#{port}"
end
- base = "#{scheme}://#{request_host}#{port}#{request.script_name}"
+ base = "#{scheme}://#{request_host}#{port}#{request.script_name.empty? ? API_ROOT_URL : request.script_name}"
else
raise TypeError, "Unknown url_for mode #{mode}"
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b1afb020/server/lib/deltacloud/models/instance.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/models/instance.rb b/server/lib/deltacloud/models/instance.rb
index c2cc0e3..9db5b4b 100644
--- a/server/lib/deltacloud/models/instance.rb
+++ b/server/lib/deltacloud/models/instance.rb
@@ -34,6 +34,10 @@ class Instance < BaseModel
attr_accessor :firewalls
attr_accessor :storage_volumes
+ def storage_volumes
+ @storage_volumes || []
+ end
+
def can_create_image?
self.create_image
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b1afb020/server/views/instances/show.xml.haml
----------------------------------------------------------------------
diff --git a/server/views/instances/show.xml.haml b/server/views/instances/show.xml.haml
index 3a62ed3..a91c0c5 100644
--- a/server/views/instances/show.xml.haml
+++ b/server/views/instances/show.xml.haml
@@ -45,8 +45,8 @@
%storage_volumes<
- @instance.storage_volumes.each do |volume|
%storage_volume{:href=> storage_volume_url(volume.keys.first), :id => volume.keys.first, :device => volume.values.first}
- - if driver.class.has_feature?(:authentication_key) or driver.class.has_feature?(:authentication_password)
- %authentication{ :type => driver_auth_feature_name }
+ - if driver.class.has_feature?(:instances, :authentication_key) or driver.class.has_feature?(:instances, :authentication_password)
+ %authentication{ :type => auth_feature_name }
- if @instance.authn_feature_failed?
%error #{@instance.authn_error}
- else
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b1afb020/tests/ec2/api.feature
----------------------------------------------------------------------
diff --git a/tests/ec2/api.feature b/tests/ec2/api.feature
index 2dcd1b2..9d53722 100644
--- a/tests/ec2/api.feature
+++ b/tests/ec2/api.feature
@@ -26,6 +26,7 @@ Feature: Accessing API entry points
| storage_volumes |
| addresses |
| firewalls |
+ | metrics |
And this URI should be available in XML, JSON, HTML format
Scenario: Following entry points
@@ -46,6 +47,7 @@ Feature: Accessing API entry points
| storage_volumes |
| addresses |
| firewalls |
+ | metrics |
And each link should have 'rel' attribute with valid name
And each link should have 'href' attribute with valid URL
When client follow this attribute
@@ -61,4 +63,3 @@ Feature: Accessing API entry points
| user_data |
| instance_count |
| firewalls |
- | hardware_profiles |
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b1afb020/tests/ec2/step_definitions/api_steps.rb
----------------------------------------------------------------------
diff --git a/tests/ec2/step_definitions/api_steps.rb b/tests/ec2/step_definitions/api_steps.rb
index c42af6f..27172e8 100644
--- a/tests/ec2/step_definitions/api_steps.rb
+++ b/tests/ec2/step_definitions/api_steps.rb
@@ -8,11 +8,11 @@ end
Given /^URI ([\w\/\-_]+) exists in (.+) format$/ do |uri, format|
@uri = uri
case format.downcase
- when 'xml':
+ when 'xml' then
header 'Accept', 'application/xml;q=9'
- when 'json'
+ when 'json' then
header 'Accept', 'application/json;q=9'
- when 'html'
+ when 'html' then
header 'Accept', 'application/xml+xhtml;q=9'
end
get @uri, {}
@@ -52,11 +52,11 @@ Then /^this URI should be available in (.+) format$/ do |formats|
@no_header = true
formats.split(',').each do |format|
case format.downcase
- when 'xml':
+ when 'xml' then
header 'Accept', 'application/xml;q=9'
- when 'json'
+ when 'json' then
header 'Accept', 'application/json;q=9'
- when 'html'
+ when 'html' then
header 'Accept', 'application/xml+xhtml;q=9'
end
get @uri, {}
@@ -75,15 +75,15 @@ end
Then /^each (\w+) should have '(.+)' attribute with valid (.+)$/ do |el, attr, t|
case el
- when 'link':
+ when 'link' then
path = '/api/link'
- when 'image':
+ when 'image' then
path = '/images/image'
- when 'instance':
+ when 'instance' then
path = '/instances/instance'
- when 'key':
+ when 'key' then
path = '/keys/key'
- when 'realm':
+ when 'realm' then
path = '/realms/realm'
end
output_xml.xpath(path).each do |entry_point|
@@ -97,11 +97,11 @@ end
Then /^each ([\w\-]+) should have '(.+)' attribute set to '(.+)'$/ do |el, attr, v|
case el
- when 'image':
+ when 'image' then
path = "/images/image"
- when 'hardware_profile':
+ when 'hardware_profile' then
path = "/hardware_profiles/hardware_profile"
- when 'instance':
+ when 'instance' then
path = "/instances/instance"
end
output_xml.xpath(path).each do |element|
@@ -111,11 +111,11 @@ end
Then /^each ([\w\-]+) should have '(.+)' element set to '(.+)'$/ do |el, child, v|
case el
- when 'image':
+ when 'image' then
path = "/images/image"
- when 'hardware_profile':
+ when 'hardware_profile' then
path = "/hardware_profiles/hardware_profile"
- when 'instance':
+ when 'instance' then
path = "/instances/instance"
end
output_xml.xpath(path).each do |element|
@@ -126,7 +126,7 @@ end
Then /^each ([\w\-]+) should have '(.+)' property set to '(.+)'$/ do |el, property, v|
case el
- when 'hardware_profile':
+ when 'hardware_profile' then
path = "/hardware_profiles/hardware_profile"
end
output_xml.xpath(path).each do |element|
@@ -143,6 +143,7 @@ When /^client follow this attribute$/ do
end
Then /^client should get a valid response$/ do
+ puts last_response.body
last_response.status.should_not == 500
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b1afb020/tests/ec2/support/env.rb
----------------------------------------------------------------------
diff --git a/tests/ec2/support/env.rb b/tests/ec2/support/env.rb
index 5245bb1..5eb006a 100644
--- a/tests/ec2/support/env.rb
+++ b/tests/ec2/support/env.rb
@@ -1,21 +1,20 @@
-SERVER_DIR = File::expand_path(File::join(File::dirname(__FILE__), "../../../server"))
+require 'rubygems'
+require 'nokogiri'
+SERVER_DIR = File::expand_path(File::join(File::dirname(__FILE__), "../../../server"))
$top_srcdir = SERVER_DIR
$:.unshift File::join($top_srcdir, 'lib')
-
Dir.chdir(SERVER_DIR)
-ENV['API_DRIVER'] = 'ec2'
+API_VERSION = "9.9.9"
+API_ROOT_URL = "/api"
-require 'rubygems'
-require 'nokogiri'
-require 'deltacloud/server'
-require 'rack/test'
+ENV['API_DRIVER'] = 'ec2'
+ENV.delete('API_VERBOSE')
-Sinatra::Application.set :environment, :test
-Sinatra::Application.set :root, SERVER_DIR
+load File.join($top_srcdir, 'lib', 'deltacloud', 'server.rb')
-require '../server/lib/deltacloud/base_driver/mock_driver'
+require 'rack/test'
CONFIG = {
:username => 'mockuser',
@@ -26,13 +25,11 @@ World do
include Rack::Test::Methods
def app
- @app = Rack::Builder.new do
- set :environment => :test
- set :loggining => true
- set :raise_errors => true
- set :show_exceptions => false
- run Sinatra::Application
- end
+ @app = Rack::URLMap.new(
+ "/" => Deltacloud::API.new,
+ "/stylesheets" => Rack::Directory.new( "public/stylesheets" ),
+ "/javascripts" => Rack::Directory.new( "public/javascripts" )
+ )
end
def output_xml
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b1afb020/tests/mock/api.feature
----------------------------------------------------------------------
diff --git a/tests/mock/api.feature b/tests/mock/api.feature
index d7fb044..59d00d1 100644
--- a/tests/mock/api.feature
+++ b/tests/mock/api.feature
@@ -53,4 +53,3 @@ Feature: Accessing API entry points
| user_name |
| user_data |
| authentication_key |
- | hardware_profiles |
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b1afb020/tests/mock/images.feature
----------------------------------------------------------------------
diff --git a/tests/mock/images.feature b/tests/mock/images.feature
index 0bae93d..0094548 100644
--- a/tests/mock/images.feature
+++ b/tests/mock/images.feature
@@ -12,6 +12,7 @@ Feature: Listing and showing images
| architecture |
| owner_id |
| state |
+ | hardware_profiles |
| actions |
And each image should have 'href' attribute with valid URL
And this URI should be available in XML, JSON, HTML format
@@ -29,6 +30,7 @@ Feature: Listing and showing images
| name |
| description |
| architecture |
+ | hardware_profiles |
| owner_id |
| state |
| actions |
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b1afb020/tests/mock/step_definitions/images_steps.rb
----------------------------------------------------------------------
diff --git a/tests/mock/step_definitions/images_steps.rb b/tests/mock/step_definitions/images_steps.rb
index 323778c..46963bb 100644
--- a/tests/mock/step_definitions/images_steps.rb
+++ b/tests/mock/step_definitions/images_steps.rb
@@ -27,17 +27,17 @@ end
When /^client want to show first (.+)$/ do |element|
case element
- when 'image':
+ when 'image' then
path = '/images/image'
- when 'instance':
+ when 'instance' then
path = '/instances/instance'
- when 'realm':
+ when 'realm' then
path = '/realms/realm'
- when 'hardware_profile'
+ when 'hardware_profile' then
path = '/hardware_profiles/hardware_profile'
- when 'storage_volume':
+ when 'storage_volume' then
path = '/storage_volumes/storage_volume'
- when 'storage_snapshot':
+ when 'storage_snapshot' then
path = '/storage_snapshots/storage_snapshot'
end
@element = output_xml.xpath(path).first
@@ -58,7 +58,7 @@ Then /^client follow (\w+) attribute in first (.+)$/ do |attr, el|
end
Then /^client should get this (.+)$/ do |el|
- last_response.status.should == 200
+ last_response.status.to_s =~ /2(\d{2})/
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b1afb020/tests/mock/storage_snapshots.feature
----------------------------------------------------------------------
diff --git a/tests/mock/storage_snapshots.feature b/tests/mock/storage_snapshots.feature
index fdaff9c..350a2a3 100644
--- a/tests/mock/storage_snapshots.feature
+++ b/tests/mock/storage_snapshots.feature
@@ -23,4 +23,5 @@ Feature: Accessing storage snapshots
Then client should get this storage_snapshot
And this storage_snapshot should have:
| created |
+ | name |
| storage_volume |