filters tests
This commit is contained in:
parent
92a43ed67c
commit
863480899a
@ -36,7 +36,7 @@ module Connectors
|
|||||||
def check_user_privileges(id, cmd, required_privelege)
|
def check_user_privileges(id, cmd, required_privelege)
|
||||||
user = show(id)
|
user = show(id)
|
||||||
|
|
||||||
unless %w(r w x).include?(required_privelege)
|
unless Devops::Model::User::PRIVILEGES.include?(required_privelege)
|
||||||
raise InvalidPrivileges.new("Access internal problem with privilege '#{required_privelege}'")
|
raise InvalidPrivileges.new("Access internal problem with privilege '#{required_privelege}'")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -101,7 +101,7 @@ module Sinatra
|
|||||||
# Can client works with JSON?
|
# Can client works with JSON?
|
||||||
def accept_json
|
def accept_json
|
||||||
types = request.accept_media_types
|
types = request.accept_media_types
|
||||||
unless types.include?('application/json')# or types.include?("*/*")
|
unless types.include?('application/json') or types.include?("*/*")
|
||||||
response.headers['Accept'] = 'application/json'
|
response.headers['Accept'] = 'application/json'
|
||||||
halt_response("Accept header should contains 'application/json' type", 406)
|
halt_response("Accept header should contains 'application/json' type", 406)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -31,9 +31,16 @@ When(/^I send POST '(.*)' query with JSON body$/) do |path, body|
|
|||||||
res = post_body(path, body, DEFAULT_HEADERS)
|
res = post_body(path, body, DEFAULT_HEADERS)
|
||||||
end
|
end
|
||||||
|
|
||||||
When(/^I send POST '(.*)' query with JSON body without header '(.*)'$/) do |path, hs, body|
|
When(/^I send POST '(.*)' query with body with header 'Accept' value '(.*)'$/) do |path, hv, body|
|
||||||
|
headers = DEFAULT_HEADERS.clone
|
||||||
|
headers["Accept"] = hv
|
||||||
|
res = post_body(path, body, headers)
|
||||||
|
end
|
||||||
|
|
||||||
|
When(/^I send POST '(.*)' query with JSON body without header 'Content-Type'$/) do |path, body|
|
||||||
JSON.parse(body) unless body.strip.empty?
|
JSON.parse(body) unless body.strip.empty?
|
||||||
headers = DEFAULT_HEADERS.select{|h, v| h != hs}
|
headers = DEFAULT_HEADERS.clone
|
||||||
|
headers.delete("Content-Type")
|
||||||
res = post_body(path, body, headers)
|
res = post_body(path, body, headers)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -46,20 +53,28 @@ When(/^I send DELETE '(.*)' query$/) do |path|
|
|||||||
delete(path, {}, DEFAULT_HEADERS)
|
delete(path, {}, DEFAULT_HEADERS)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
When(/^I send DELETE '(.*)' query with JSON body with header 'Accept' value '(.*)'$/) do |path, hv, body|
|
||||||
|
JSON.parse(body) unless body.strip.empty?
|
||||||
|
headers = DEFAULT_HEADERS.clone
|
||||||
|
headers["Accept"] = hv
|
||||||
|
res = delete_body(path, body, headers)
|
||||||
|
end
|
||||||
|
|
||||||
When(/^I send DELETE '(.*)' query with JSON body$/) do |path, body|
|
When(/^I send DELETE '(.*)' query with JSON body$/) do |path, body|
|
||||||
JSON.parse(body) unless body.strip.empty?
|
JSON.parse(body) unless body.strip.empty?
|
||||||
res = delete_body(path, body, DEFAULT_HEADERS)
|
res = delete_body(path, body, DEFAULT_HEADERS)
|
||||||
end
|
end
|
||||||
|
|
||||||
When(/^I send DELETE '(.*)' query without header '(.*)'$/) do |path, hs|
|
When(/^I send DELETE '(.*)' query without header 'Content-Type'$/) do |path, hs|
|
||||||
headers = DEFAULT_HEADERS.select{|h, v| h != hs}
|
headers = DEFAULT_HEADERS.clone
|
||||||
puts headers
|
headers.delete("Content-Type")
|
||||||
res = delete_body(path, nil, headers)
|
res = delete_body(path, nil, headers)
|
||||||
end
|
end
|
||||||
|
|
||||||
When(/^I send DELETE '(.*)' query with JSON body without header '(.*)'$/) do |path, hs, body|
|
When(/^I send DELETE '(.*)' query with JSON body without header 'Content-Type'$/) do |path, body|
|
||||||
JSON.parse(body) unless body.strip.empty?
|
JSON.parse(body) unless body.strip.empty?
|
||||||
headers = DEFAULT_HEADERS.select{|h, v| h != hs}
|
headers = DEFAULT_HEADERS.clone
|
||||||
|
headers.delete("Content-Type")
|
||||||
res = delete_body(path, body, headers)
|
res = delete_body(path, body, headers)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -80,14 +95,23 @@ When(/^I send PUT '(.*)' query with user without privileges$/) do |path|
|
|||||||
put_without_privileges(path, {}, DEFAULT_HEADERS)
|
put_without_privileges(path, {}, DEFAULT_HEADERS)
|
||||||
end
|
end
|
||||||
|
|
||||||
When(/^I send PUT '(.*)' query with body without header '(.*)'$/) do |path, hs, body|
|
When(/^I send PUT '(.*)' query with JSON body with header 'Accept' value '(.*)'$/) do |path, hv, body|
|
||||||
headers = DEFAULT_HEADERS.select{|h, v| h != hs}
|
JSON.parse(body) unless body.strip.empty?
|
||||||
|
headers = DEFAULT_HEADERS.clone
|
||||||
|
headers["Accept"] = hv
|
||||||
res = put_body(path, body, headers)
|
res = put_body(path, body, headers)
|
||||||
end
|
end
|
||||||
|
|
||||||
When(/^I send PUT '(.*)' query with JSON body without header '(.*)'$/) do |path, hs, body|
|
When(/^I send PUT '(.*)' query with body without header 'Content-Type'$/) do |path, body|
|
||||||
|
headers = DEFAULT_HEADERS.clone
|
||||||
|
headers.delete("Content-Type")
|
||||||
|
res = put_body(path, body, headers)
|
||||||
|
end
|
||||||
|
|
||||||
|
When(/^I send PUT '(.*)' query with JSON body without header 'Content-Type'$/) do |path, body|
|
||||||
JSON.parse(body) unless body.strip.empty?
|
JSON.parse(body) unless body.strip.empty?
|
||||||
headers = DEFAULT_HEADERS.select{|h, v| h != hs}
|
headers = DEFAULT_HEADERS.clone
|
||||||
|
headers.delete("Content-Type")
|
||||||
res = put_body(path, body, headers)
|
res = put_body(path, body, headers)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,7 @@ class Generator < OpenStruct
|
|||||||
config_file = ENV["DEVOPS_FEATURES_GENERATOR_CONFIG"] || ENV["CONFIG"] || CONFIG
|
config_file = ENV["DEVOPS_FEATURES_GENERATOR_CONFIG"] || ENV["CONFIG"] || CONFIG
|
||||||
@config = YAML.load_file(File.new(config_file))
|
@config = YAML.load_file(File.new(config_file))
|
||||||
load_fixtures()
|
load_fixtures()
|
||||||
super(:config => @config)
|
super(:config => @config, :formatter => @formatter, :fixtures => @fixtures)
|
||||||
end
|
end
|
||||||
|
|
||||||
def configure!
|
def configure!
|
||||||
|
|||||||
@ -7,8 +7,8 @@ Feature: Filters
|
|||||||
Then response should be '401'
|
Then response should be '401'
|
||||||
|
|
||||||
@openstack
|
@openstack
|
||||||
Scenario: Add openstack image filter without header 'Accept'
|
Scenario: Add openstack image filter with header 'Accept' value 'text/*'
|
||||||
When I send PUT '/v2.0/filter/openstack/image' query with JSON body without header 'Accept'
|
When I send PUT '/v2.0/filter/openstack/image' query with JSON body with header 'Accept' value 'text/*'
|
||||||
"""
|
"""
|
||||||
[
|
[
|
||||||
"<%= @config["openstack"]["image"] %>"
|
"<%= @config["openstack"]["image"] %>"
|
||||||
@ -102,8 +102,8 @@ Feature: Filters
|
|||||||
Then response should be '401'
|
Then response should be '401'
|
||||||
|
|
||||||
@ec2
|
@ec2
|
||||||
Scenario: Add ec2 image filter without header 'Accept'
|
Scenario: Add ec2 image filter with header 'Accept' value 'text/*'
|
||||||
When I send PUT '/v2.0/filter/ec2/image' query with JSON body without header 'Accept'
|
When I send PUT '/v2.0/filter/ec2/image' query with JSON body with header 'Accept' value 'text/*'
|
||||||
"""
|
"""
|
||||||
[
|
[
|
||||||
"<%= @config["ec2"]["image"] %>"
|
"<%= @config["ec2"]["image"] %>"
|
||||||
|
|||||||
@ -7,8 +7,8 @@ Feature: Filters
|
|||||||
Then response should be '401'
|
Then response should be '401'
|
||||||
|
|
||||||
@openstack
|
@openstack
|
||||||
Scenario: Delete openstack image filter without header 'Accept'
|
Scenario: Delete openstack image filter with header 'Accept' value 'text/*'
|
||||||
When I send DELETE '/v2.0/filter/openstack/image' query with JSON body without header 'Accept'
|
When I send DELETE '/v2.0/filter/openstack/image' query with JSON body with header 'Accept' value 'text/*'
|
||||||
"""
|
"""
|
||||||
[
|
[
|
||||||
"<%= @config["openstack"]["image"] %>"
|
"<%= @config["openstack"]["image"] %>"
|
||||||
@ -92,8 +92,8 @@ Feature: Filters
|
|||||||
Then response should be '401'
|
Then response should be '401'
|
||||||
|
|
||||||
@ec2
|
@ec2
|
||||||
Scenario: Delete ec2 image filter without header 'Accept'
|
Scenario: Delete ec2 image filter with header 'Accept' value 'text/*'
|
||||||
When I send DELETE '/v2.0/filter/ec2/image' query with JSON body without header 'Accept'
|
When I send DELETE '/v2.0/filter/ec2/image' query with JSON body with header 'Accept' value 'text/*'
|
||||||
"""
|
"""
|
||||||
[
|
[
|
||||||
"<%= @config["ec2"]["image"] %>"
|
"<%= @config["ec2"]["image"] %>"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user