diff --git a/devops-service/features/flavor.feature b/devops-service/features/api_v2/flavor.feature similarity index 78% rename from devops-service/features/flavor.feature rename to devops-service/features/api_v2/flavor.feature index e4c1952..020a104 100644 --- a/devops-service/features/flavor.feature +++ b/devops-service/features/api_v2/flavor.feature @@ -46,6 +46,15 @@ Feature: Flavors And the JSON response should be an array And response array should be empty + @static + Scenario: Get flavors list of static provider without 'Accept' header + When I send GET '/v2.0/flavors/static' query without headers 'Accept' + Then response should be '406' + Scenario: Get flavors list of unknown provider When I send GET '/v2.0/flavors/foo' query Then response should be '404' + + Scenario: Get flavors list of unknown provider without 'Accept' header + When I send GET '/v2.0/flavors/foo' query without headers 'Accept' + Then response should be '406' diff --git a/devops-service/features/api_v2/group.feature b/devops-service/features/api_v2/group.feature new file mode 100644 index 0000000..c25bfde --- /dev/null +++ b/devops-service/features/api_v2/group.feature @@ -0,0 +1,39 @@ +@group +Feature: Groups + + @openstack + Scenario: Get list of openstack groups + When I send GET '/v2.0/groups/openstack' query + Then response should be '200' + And the Content-Type header should include 'application/json' + And the JSON response should be an object + And response should contains openstack groups elements + + @ec2 + Scenario: Get list of ec2 groups + When I send GET '/v2.0/groups/ec2' query + Then response should be '200' + And the Content-Type header should include 'application/json' + And the JSON response should be an object + And response should contains ec2 groups elements + + @static + Scenario: Get list of static groups + When I send GET '/v2.0/groups/static' query + Then response should be '200' + And the Content-Type header should include 'application/json' + And the JSON response should be an object + And response object should be empty + + @static + Scenario: Get groups list of static provider without 'Accept' header + When I send GET '/v2.0/groups/static' query without headers 'Accept' + Then response should be '406' + + Scenario: Get groups list of unknown provider + When I send GET '/v2.0/groups/foo' query + Then response should be '404' + + Scenario: Get groups list of unknown provider without 'Accept' header + When I send GET '/v2.0/groups/foo' query without headers 'Accept' + Then response should be '406' diff --git a/devops-service/features/image.feature b/devops-service/features/api_v2/image.feature similarity index 95% rename from devops-service/features/image.feature rename to devops-service/features/api_v2/image.feature index 34fff8b..1d7a14b 100644 --- a/devops-service/features/image.feature +++ b/devops-service/features/api_v2/image.feature @@ -23,7 +23,7 @@ Feature: Manage images Then response should be '200' And the Content-Type header should include 'application/json' And the JSON response should be a hash - And response should be JSON, image object: + And response should be JSON object like: """ { "provider": "foo_provider", diff --git a/devops-service/features/project.feature b/devops-service/features/api_v2/project.feature similarity index 100% rename from devops-service/features/project.feature rename to devops-service/features/api_v2/project.feature diff --git a/devops-service/features/server.feature b/devops-service/features/api_v2/server.feature similarity index 100% rename from devops-service/features/server.feature rename to devops-service/features/api_v2/server.feature diff --git a/devops-service/features/step_definitions/group_steps.rb b/devops-service/features/step_definitions/group_steps.rb new file mode 100644 index 0000000..51440e2 --- /dev/null +++ b/devops-service/features/step_definitions/group_steps.rb @@ -0,0 +1,24 @@ +Then(/^response should contains ec2 groups elements$/) do + obj = JSON.parse(last_response.body) + assert obj.key?("default"), "Group 'default' is missing" + if obj.key?("default") + d = obj["default"] + %w{description id rules}.each do |k| + assert d.key?(k), "Group 'default' has no '#{k}' field" + end + assert d["rules"].is_a?(Array), "Field 'rules' should be an array" + end +end + +Then(/^response should contains openstack groups elements$/) do + obj = JSON.parse(last_response.body) + assert obj.key?("default"), "Group 'default' is missing" + if obj.key?("default") + d = obj["default"] + %w{description rules}.each do |k| + assert d.key?(k), "Group 'default' has no '#{k}' field" + end + assert d["rules"].is_a?(Array), "Field 'rules' should be an array" + end +end + diff --git a/devops-service/features/step_definitions/http_queries_steps.rb b/devops-service/features/step_definitions/http_queries_steps.rb index 9065a88..f73dcae 100644 --- a/devops-service/features/step_definitions/http_queries_steps.rb +++ b/devops-service/features/step_definitions/http_queries_steps.rb @@ -7,6 +7,14 @@ When(/^I send GET '(.*)' query$/) do |path| get(path, {}, DEFAULT_HEADERS) end +When(/^I send GET '(.*)' query without headers '(.*)'$/) do |path, hs| + buf = hs.split(",").map{|e| e.strip} + headers = {} + DEFAULT_HEADERS.each{|h, v| headers[h] = v unless buf.include?(h)} + puts headers + get(path, {}, headers) +end + When(/^I send POST '(.*)' query with params '(.*)'$/) do |path, params| if params == '' p = Hash.new @@ -19,3 +27,12 @@ end When(/^I send DELETE '(.*)' query$/) do |path| delete(path, {}, DEFAULT_HEADERS) end + +Then(/^response should be '(\d+)'$/) do |code| + assert(code.to_i == last_response.status, "Status is not #{code}, it is #{last_response.status}") +end + +Then(/^the Content\-Type header should include 'application\/json'$/) do + assert last_response.header.contenttype.include?("application/json"), "Response has no header 'Content-Type' with 'application/json'" +end + diff --git a/devops-service/features/step_definitions/image_steps.rb b/devops-service/features/step_definitions/image_steps.rb deleted file mode 100644 index 40e48d1..0000000 --- a/devops-service/features/step_definitions/image_steps.rb +++ /dev/null @@ -1,42 +0,0 @@ -Then(/^response should be '(\d+)'$/) do |code| - assert last_response.ok?, "Status is not #{code}, it is #{last_response.status}" -end - -Then(/^the Content\-Type header should include 'application\/json'$/) do - assert last_response.header.contenttype.include?("application/json"), "Response has no header 'Content-Type' with 'application/json'" -end - -Then(/^the JSON response should be an array$/) do - body = JSON.parse(last_response.body) - assert body.is_a?(Array), "Body is not an array" -end - -Then(/^the array elements should be strings$/) do - body = JSON.parse(last_response.body) - body.each do |e| - assert e.is_a?(String), "Array element is not a string" - end -end - -Then(/^the JSON response should be a hash$/) do - body = JSON.parse(last_response.body) - assert body.is_a?(Hash), "Body is not a hash" -end - -=begin -Then(/^response should be JSON, images list:$/) do |string| - src_image = JSON.parse(string).first - image = JSON.parse(last_response.body).first - src_image.each do |key, value| - assert image.key?(key), "Image has no key '#{key}'" - end -end -=end - -Then(/^response should be JSON, image object:$/) do |string| - src_image = JSON.parse(string) - image = JSON.parse(last_response.body) - src_image.each do |key, value| - assert image.key?(key), "Image has no key '#{key}'" - end -end diff --git a/devops-service/features/step_definitions/json_steps.rb b/devops-service/features/step_definitions/json_steps.rb index f808249..178a747 100644 --- a/devops-service/features/step_definitions/json_steps.rb +++ b/devops-service/features/step_definitions/json_steps.rb @@ -12,3 +12,33 @@ Then(/^response array should be empty$/) do array = JSON.parse(last_response.body) assert array.empty?, "Array is not empty" end + +Then(/^response object should be empty$/) do + obj = JSON.parse(last_response.body) + assert obj.empty?, "Object is not empty" +end + +Then(/^the JSON response should be an array$/) do + body = JSON.parse(last_response.body) + assert body.is_a?(Array), "Body is not an array" +end + +Then(/^the JSON response should be an object$/) do + body = JSON.parse(last_response.body) + assert body.is_a?(Hash), "Body is not an object" +end + +Then(/^the array elements should be strings$/) do + body = JSON.parse(last_response.body) + body.each do |e| + assert e.is_a?(String), "Array element is not a string" + end +end + +Then(/^response should be JSON object like:$/) do |string| + src = JSON.parse(string) + obj = JSON.parse(last_response.body) + src.each do |key, value| + assert obj.key?(key), "Object has no key '#{key}'" + end +end diff --git a/devops-service/features/support/config.yml b/devops-service/features/support/config.yml new file mode 100644 index 0000000..78d87c7 --- /dev/null +++ b/devops-service/features/support/config.yml @@ -0,0 +1,5 @@ +host: "host" +port: port +username: "test" +password: "test" +path_prefix: "" diff --git a/devops-service/features/support/env.rb b/devops-service/features/support/env.rb index 2e5ce5d..2f8aecd 100644 --- a/devops-service/features/support/env.rb +++ b/devops-service/features/support/env.rb @@ -1,10 +1,10 @@ ENV["RACK_ENV"] = "test" #require File.join(File.dirname(__FILE__), '..', '..', 'config.ru') +require "rubygems" require 'test/unit' require 'rack/test' require "json" -require 'httpclient' USERNAME = '' PASSWORD = '' @@ -21,6 +21,8 @@ class MyWorld end class RequestSender + require "httpclient" + require "yaml" @last_res = nil $test_hash = Hash.new @@ -31,39 +33,41 @@ class RequestSender # username= # password= def initialize - file = "tests.conf" + file = ENV["CONFIG"] || "./features/support/config.yml" abort("File does not exist: #{File.absolute_path(file)}") unless File.exists?(file) - @config = {} - File.open(file).each_line do |l| - b = l.split("=") - @config[ b[0] ] = b[1].strip - end + @config = config(file) + @default_headers = { + } end def host "http://#{@config["host"]}:#{@config["port"]}" end + def create_url path + host + @config["path_prefix"] + path + end + def last_response @last_res end - def get path, query, headers + def get path, query, headers={} submit do |http| - http.get(host + path, query, headers) + http.get(create_url(path), query, @default_headers.merge(headers)) end end - def post path, query, headers + def post path, query, headers={} submit do |http| http.receive_timeout = 0 #!!! bring out to appropriate server step - http.post(host + path, JSON.pretty_generate(query), headers) + http.post(create_url(path), JSON.pretty_generate(query), @default_headers.merge(headers)) end end - def delete path, query, headers + def delete path, query, headers={} submit do |http| - http.delete(host + path, JSON.pretty_generate(query), headers) + http.delete(create_url(path), JSON.pretty_generate(query), @default_headers.merge(headers)) end end @@ -73,6 +77,10 @@ class RequestSender res = yield http @last_res = res end + + def config path + YAML.load_file(path) + end end World do diff --git a/devops-service/providers/static.rb b/devops-service/providers/static.rb index 1166b6b..9baf2e8 100644 --- a/devops-service/providers/static.rb +++ b/devops-service/providers/static.rb @@ -23,6 +23,10 @@ module Provider [] end + def groups filter=nil + {} + end + def images filters [] end