flavors and groups tests v2.0
This commit is contained in:
parent
3dcd7ad905
commit
4585a7f26f
@ -46,6 +46,15 @@ Feature: Flavors
|
|||||||
And the JSON response should be an array
|
And the JSON response should be an array
|
||||||
And response array should be empty
|
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
|
Scenario: Get flavors list of unknown provider
|
||||||
When I send GET '/v2.0/flavors/foo' query
|
When I send GET '/v2.0/flavors/foo' query
|
||||||
Then response should be '404'
|
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'
|
||||||
39
devops-service/features/api_v2/group.feature
Normal file
39
devops-service/features/api_v2/group.feature
Normal file
@ -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'
|
||||||
@ -23,7 +23,7 @@ Feature: Manage images
|
|||||||
Then response should be '200'
|
Then response should be '200'
|
||||||
And the Content-Type header should include 'application/json'
|
And the Content-Type header should include 'application/json'
|
||||||
And the JSON response should be a hash
|
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",
|
"provider": "foo_provider",
|
||||||
24
devops-service/features/step_definitions/group_steps.rb
Normal file
24
devops-service/features/step_definitions/group_steps.rb
Normal file
@ -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
|
||||||
|
|
||||||
@ -7,6 +7,14 @@ When(/^I send GET '(.*)' query$/) do |path|
|
|||||||
get(path, {}, DEFAULT_HEADERS)
|
get(path, {}, DEFAULT_HEADERS)
|
||||||
end
|
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|
|
When(/^I send POST '(.*)' query with params '(.*)'$/) do |path, params|
|
||||||
if params == ''
|
if params == ''
|
||||||
p = Hash.new
|
p = Hash.new
|
||||||
@ -19,3 +27,12 @@ end
|
|||||||
When(/^I send DELETE '(.*)' query$/) do |path|
|
When(/^I send DELETE '(.*)' query$/) do |path|
|
||||||
delete(path, {}, DEFAULT_HEADERS)
|
delete(path, {}, DEFAULT_HEADERS)
|
||||||
end
|
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
|
||||||
|
|
||||||
|
|||||||
@ -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
|
|
||||||
@ -12,3 +12,33 @@ Then(/^response array should be empty$/) do
|
|||||||
array = JSON.parse(last_response.body)
|
array = JSON.parse(last_response.body)
|
||||||
assert array.empty?, "Array is not empty"
|
assert array.empty?, "Array is not empty"
|
||||||
end
|
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
|
||||||
|
|||||||
5
devops-service/features/support/config.yml
Normal file
5
devops-service/features/support/config.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
host: "host"
|
||||||
|
port: port
|
||||||
|
username: "test"
|
||||||
|
password: "test"
|
||||||
|
path_prefix: ""
|
||||||
@ -1,10 +1,10 @@
|
|||||||
ENV["RACK_ENV"] = "test"
|
ENV["RACK_ENV"] = "test"
|
||||||
#require File.join(File.dirname(__FILE__), '..', '..', 'config.ru')
|
#require File.join(File.dirname(__FILE__), '..', '..', 'config.ru')
|
||||||
|
|
||||||
|
require "rubygems"
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'rack/test'
|
require 'rack/test'
|
||||||
require "json"
|
require "json"
|
||||||
require 'httpclient'
|
|
||||||
|
|
||||||
USERNAME = '<username>'
|
USERNAME = '<username>'
|
||||||
PASSWORD = '<password>'
|
PASSWORD = '<password>'
|
||||||
@ -21,6 +21,8 @@ class MyWorld
|
|||||||
end
|
end
|
||||||
|
|
||||||
class RequestSender
|
class RequestSender
|
||||||
|
require "httpclient"
|
||||||
|
require "yaml"
|
||||||
|
|
||||||
@last_res = nil
|
@last_res = nil
|
||||||
$test_hash = Hash.new
|
$test_hash = Hash.new
|
||||||
@ -31,39 +33,41 @@ class RequestSender
|
|||||||
# username=<user>
|
# username=<user>
|
||||||
# password=<psw>
|
# password=<psw>
|
||||||
def initialize
|
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)
|
abort("File does not exist: #{File.absolute_path(file)}") unless File.exists?(file)
|
||||||
@config = {}
|
@config = config(file)
|
||||||
File.open(file).each_line do |l|
|
@default_headers = {
|
||||||
b = l.split("=")
|
}
|
||||||
@config[ b[0] ] = b[1].strip
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def host
|
def host
|
||||||
"http://#{@config["host"]}:#{@config["port"]}"
|
"http://#{@config["host"]}:#{@config["port"]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_url path
|
||||||
|
host + @config["path_prefix"] + path
|
||||||
|
end
|
||||||
|
|
||||||
def last_response
|
def last_response
|
||||||
@last_res
|
@last_res
|
||||||
end
|
end
|
||||||
|
|
||||||
def get path, query, headers
|
def get path, query, headers={}
|
||||||
submit do |http|
|
submit do |http|
|
||||||
http.get(host + path, query, headers)
|
http.get(create_url(path), query, @default_headers.merge(headers))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def post path, query, headers
|
def post path, query, headers={}
|
||||||
submit do |http|
|
submit do |http|
|
||||||
http.receive_timeout = 0 #!!! bring out to appropriate server step
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete path, query, headers
|
def delete path, query, headers={}
|
||||||
submit do |http|
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -73,6 +77,10 @@ class RequestSender
|
|||||||
res = yield http
|
res = yield http
|
||||||
@last_res = res
|
@last_res = res
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def config path
|
||||||
|
YAML.load_file(path)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
World do
|
World do
|
||||||
|
|||||||
@ -23,6 +23,10 @@ module Provider
|
|||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def groups filter=nil
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
|
||||||
def images filters
|
def images filters
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user