From 863480899ae96271e0795c2026bd5a7b868f6f6c Mon Sep 17 00:00:00 2001 From: amartynov Date: Wed, 15 Jul 2015 16:52:50 +0300 Subject: [PATCH] filters tests --- devops-service/db/mongo/connectors/user.rb | 2 +- .../sinatra/methods_with_headers.rb | 2 +- .../step_definitions/http_queries_steps.rb | 46 ++++++++++++++----- devops-service/tests/generate_tests.rb | 2 +- .../api_v2/10_create/00_filter.feature.erb | 8 ++-- .../api_v2/90_delete/99_filter.feature.erb | 8 ++-- 6 files changed, 46 insertions(+), 22 deletions(-) diff --git a/devops-service/db/mongo/connectors/user.rb b/devops-service/db/mongo/connectors/user.rb index d2d5650..7954b63 100644 --- a/devops-service/db/mongo/connectors/user.rb +++ b/devops-service/db/mongo/connectors/user.rb @@ -36,7 +36,7 @@ module Connectors def check_user_privileges(id, cmd, required_privelege) 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}'") end diff --git a/devops-service/sinatra/methods_with_headers.rb b/devops-service/sinatra/methods_with_headers.rb index 1a36622..aeafdf9 100644 --- a/devops-service/sinatra/methods_with_headers.rb +++ b/devops-service/sinatra/methods_with_headers.rb @@ -101,7 +101,7 @@ module Sinatra # Can client works with JSON? def accept_json 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' halt_response("Accept header should contains 'application/json' type", 406) end diff --git a/devops-service/tests/features/step_definitions/http_queries_steps.rb b/devops-service/tests/features/step_definitions/http_queries_steps.rb index 14321ae..4720a95 100644 --- a/devops-service/tests/features/step_definitions/http_queries_steps.rb +++ b/devops-service/tests/features/step_definitions/http_queries_steps.rb @@ -31,9 +31,16 @@ When(/^I send POST '(.*)' query with JSON body$/) do |path, body| res = post_body(path, body, DEFAULT_HEADERS) 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? - headers = DEFAULT_HEADERS.select{|h, v| h != hs} + headers = DEFAULT_HEADERS.clone + headers.delete("Content-Type") res = post_body(path, body, headers) end @@ -46,20 +53,28 @@ When(/^I send DELETE '(.*)' query$/) do |path| delete(path, {}, DEFAULT_HEADERS) 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| JSON.parse(body) unless body.strip.empty? res = delete_body(path, body, DEFAULT_HEADERS) end -When(/^I send DELETE '(.*)' query without header '(.*)'$/) do |path, hs| - headers = DEFAULT_HEADERS.select{|h, v| h != hs} - puts headers +When(/^I send DELETE '(.*)' query without header 'Content-Type'$/) do |path, hs| + headers = DEFAULT_HEADERS.clone + headers.delete("Content-Type") res = delete_body(path, nil, headers) 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? - headers = DEFAULT_HEADERS.select{|h, v| h != hs} + headers = DEFAULT_HEADERS.clone + headers.delete("Content-Type") res = delete_body(path, body, headers) end @@ -80,14 +95,23 @@ When(/^I send PUT '(.*)' query with user without privileges$/) do |path| put_without_privileges(path, {}, DEFAULT_HEADERS) end -When(/^I send PUT '(.*)' query with body without header '(.*)'$/) do |path, hs, body| - headers = DEFAULT_HEADERS.select{|h, v| h != hs} +When(/^I send PUT '(.*)' 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 = put_body(path, body, headers) 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? - headers = DEFAULT_HEADERS.select{|h, v| h != hs} + headers = DEFAULT_HEADERS.clone + headers.delete("Content-Type") res = put_body(path, body, headers) end diff --git a/devops-service/tests/generate_tests.rb b/devops-service/tests/generate_tests.rb index ded4523..5557cb2 100755 --- a/devops-service/tests/generate_tests.rb +++ b/devops-service/tests/generate_tests.rb @@ -15,7 +15,7 @@ class Generator < OpenStruct config_file = ENV["DEVOPS_FEATURES_GENERATOR_CONFIG"] || ENV["CONFIG"] || CONFIG @config = YAML.load_file(File.new(config_file)) load_fixtures() - super(:config => @config) + super(:config => @config, :formatter => @formatter, :fixtures => @fixtures) end def configure! diff --git a/devops-service/tests/templates/api_v2/10_create/00_filter.feature.erb b/devops-service/tests/templates/api_v2/10_create/00_filter.feature.erb index 2a1198b..19ac70b 100644 --- a/devops-service/tests/templates/api_v2/10_create/00_filter.feature.erb +++ b/devops-service/tests/templates/api_v2/10_create/00_filter.feature.erb @@ -7,8 +7,8 @@ Feature: Filters Then response should be '401' @openstack - Scenario: Add openstack image filter without header 'Accept' - When I send PUT '/v2.0/filter/openstack/image' query with JSON body 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 with header 'Accept' value 'text/*' """ [ "<%= @config["openstack"]["image"] %>" @@ -102,8 +102,8 @@ Feature: Filters Then response should be '401' @ec2 - Scenario: Add ec2 image filter without header 'Accept' - When I send PUT '/v2.0/filter/ec2/image' query with JSON body 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 with header 'Accept' value 'text/*' """ [ "<%= @config["ec2"]["image"] %>" diff --git a/devops-service/tests/templates/api_v2/90_delete/99_filter.feature.erb b/devops-service/tests/templates/api_v2/90_delete/99_filter.feature.erb index 4c10c7c..1fb2f54 100644 --- a/devops-service/tests/templates/api_v2/90_delete/99_filter.feature.erb +++ b/devops-service/tests/templates/api_v2/90_delete/99_filter.feature.erb @@ -7,8 +7,8 @@ Feature: Filters Then response should be '401' @openstack - Scenario: Delete openstack image filter without header 'Accept' - When I send DELETE '/v2.0/filter/openstack/image' query with JSON body 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 with header 'Accept' value 'text/*' """ [ "<%= @config["openstack"]["image"] %>" @@ -92,8 +92,8 @@ Feature: Filters Then response should be '401' @ec2 - Scenario: Delete ec2 image filter without header 'Accept' - When I send DELETE '/v2.0/filter/ec2/image' query with JSON body 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 with header 'Accept' value 'text/*' """ [ "<%= @config["ec2"]["image"] %>"