flavors and groups tests v2.0

This commit is contained in:
amartynov 2014-06-23 13:58:14 +04:00
parent 3dcd7ad905
commit 4585a7f26f
12 changed files with 150 additions and 56 deletions

View File

@ -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'

View 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'

View File

@ -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",

View 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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,5 @@
host: "host"
port: port
username: "test"
password: "test"
path_prefix: ""

View File

@ -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 = '<username>'
PASSWORD = '<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=<user>
# password=<psw>
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

View File

@ -23,6 +23,10 @@ module Provider
[]
end
def groups filter=nil
{}
end
def images filters
[]
end