fluke/devops-service/tests/features/step_definitions/http_queries_steps.rb

154 lines
5.0 KiB
Ruby
Raw Normal View History

2014-06-02 18:31:34 +04:00
DEFAULT_HEADERS = {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
}
When(/^I send GET '(.*)' query$/) do |path|
get(path, {}, DEFAULT_HEADERS)
end
When(/^I send GET '(.*)' query with header 'Accept' value '(.*)'$/) do |path, hv|
headers = {"Accept" => hv}
get(path, {}, headers)
end
2014-07-02 11:45:02 +04:00
When(/^I send GET '(.*)' query with user without privileges$/) do |path|
get_without_privileges(path, {}, DEFAULT_HEADERS)
end
2014-06-23 13:58:14 +04:00
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)}
get(path, {}, headers)
end
2014-06-02 18:31:34 +04:00
When(/^I send POST '(.*)' query with params '(.*)'$/) do |path, params|
if params == ''
p = Hash.new
else
p = JSON.parse params
end
res = post(path, p, DEFAULT_HEADERS)
end
When(/^I send POST '(.*)' query with JSON body$/) do |path, body|
2014-07-09 12:36:06 +04:00
JSON.parse(body) unless body.strip.empty?
res = post_body(path, body, DEFAULT_HEADERS)
end
When(/^I send POST '(.*)' query with JSON body with header '(.*)' value '(.*)'$/) do |path, header, hv, body|
JSON.parse(body) unless body.strip.empty?
headers = DEFAULT_HEADERS.clone
headers[header] = hv
res = post_body(path, body, headers)
end
When(/^I send POST '(.*)' query with body with header '(.*)' value '(.*)'$/) do |path, header, hv, body|
2015-07-15 16:52:50 +03:00
headers = DEFAULT_HEADERS.clone
headers[header] = hv
2015-07-15 16:52:50 +03:00
res = post_body(path, body, headers)
end
When(/^I send POST '(.*)' query with JSON body without header 'Content-Type'$/) do |path, body|
2014-07-09 12:36:06 +04:00
JSON.parse(body) unless body.strip.empty?
2015-07-15 16:52:50 +03:00
headers = DEFAULT_HEADERS.clone
headers.delete("Content-Type")
res = post_body(path, body, headers)
end
2014-07-15 12:57:21 +04:00
When(/^I send POST '(.*)' query with JSON body with user without privileges$/) do |path, body|
JSON.parse(body) unless body.strip.empty?
2015-07-27 18:27:52 +03:00
post_without_privileges(path, body, DEFAULT_HEADERS)
end
When(/^I send POST '(.*)' query with user without privileges$/) do |path|
post_without_privileges(path, {}, DEFAULT_HEADERS)
2014-07-15 12:57:21 +04:00
end
2014-06-02 18:31:34 +04:00
When(/^I send DELETE '(.*)' query$/) do |path|
delete(path, {}, DEFAULT_HEADERS)
end
2014-06-23 13:58:14 +04:00
When(/^I send DELETE '(.*)' query with JSON body with header '(.*)' value '(.*)'$/) do |path, header, hv, body|
2015-07-15 16:52:50 +03:00
JSON.parse(body) unless body.strip.empty?
headers = DEFAULT_HEADERS.clone
headers[header] = hv
2015-07-15 16:52:50 +03:00
res = delete_body(path, body, headers)
end
When(/^I send DELETE '(.*)' query with header '(.*)' value '(.*)'$/) do |path, header, hv|
headers = DEFAULT_HEADERS.clone
headers[header] = hv
res = delete_body(path, nil, headers)
end
When(/^I send DELETE '(.*)' query with JSON body$/) do |path, body|
2014-07-09 12:36:06 +04:00
JSON.parse(body) unless body.strip.empty?
res = delete_body(path, body, DEFAULT_HEADERS)
end
2015-07-15 16:52:50 +03:00
When(/^I send DELETE '(.*)' query without header 'Content-Type'$/) do |path, hs|
headers = DEFAULT_HEADERS.clone
headers.delete("Content-Type")
2014-07-08 11:48:23 +04:00
res = delete_body(path, nil, headers)
end
2015-07-15 16:52:50 +03:00
When(/^I send DELETE '(.*)' query with JSON body without header 'Content-Type'$/) do |path, body|
2014-07-09 12:36:06 +04:00
JSON.parse(body) unless body.strip.empty?
2015-07-15 16:52:50 +03:00
headers = DEFAULT_HEADERS.clone
headers.delete("Content-Type")
res = delete_body(path, body, headers)
end
When(/^I send DELETE '(.*)' query with user without privileges$/) do |path|
delete_without_privileges(path, {}, DEFAULT_HEADERS)
end
2014-07-08 14:21:45 +04:00
When(/^I send PUT '(.*)' query with body$/) do |path, body|
res = put_body(path, body, DEFAULT_HEADERS)
end
When(/^I send PUT '(.*)' query with JSON body$/) do |path, body|
2014-07-09 12:36:06 +04:00
JSON.parse(body) unless body.strip.empty?
res = put_body(path, body, DEFAULT_HEADERS)
end
When(/^I send PUT '(.*)' query with user without privileges$/) do |path|
put_without_privileges(path, {}, DEFAULT_HEADERS)
end
When(/^I send PUT '(.*)' query with JSON body with header '(.*)' value '(.*)'$/) do |path, header, hv, body|
2015-07-15 16:52:50 +03:00
JSON.parse(body) unless body.strip.empty?
headers = DEFAULT_HEADERS.clone
headers[header] = hv
2015-07-15 16:52:50 +03:00
res = put_body(path, body, headers)
end
When(/^I send PUT '(.*)' query with JSON body without header 'Content-Type'$/) do |path, body|
2014-07-09 12:36:06 +04:00
JSON.parse(body) unless body.strip.empty?
2015-07-15 16:52:50 +03:00
headers = DEFAULT_HEADERS.clone
headers.delete("Content-Type")
res = put_body(path, body, headers)
end
2014-07-16 13:32:59 +04:00
When(/^I send PUT '(.*)' query with JSON body with user without privileges$/) do |path, body|
JSON.parse(body) unless body.strip.empty?
res = put_without_privileges(path, body, DEFAULT_HEADERS)
end
2014-06-23 13:58:14 +04:00
Then(/^response should be '(\d+)'$/) do |code|
assert(code.to_i == last_response.status, "Status is not #{code}, it is #{last_response.status}")
end
2014-11-27 18:45:35 +03:00
Then(/^response error should be "([^"]+)"$/) do |error_msg|
json = JSON.parse(last_response.body)
message = json['message']
stripped_message = message.sub(/Project '\w+'. Deploy environment '\w+'. /, '')
assert(error_msg == stripped_message, "Error message is not \n #{error_msg}\nit is \n #{stripped_message}")
end
2014-06-23 13:58:14 +04:00
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