tests with config

This commit is contained in:
amartynov 2014-06-20 13:21:42 +04:00
parent bfbf56e08d
commit 2b18cefb82
3 changed files with 21 additions and 7 deletions

View File

@ -10,10 +10,10 @@ Feature: flavors
""" """
[ [
{ {
"id" => "flavor_id", "id": "flavor_id",
"v_cpus" => "v_cpus", "v_cpus": "v_cpus",
"ram" => "ram", "ram": "ram",
"disk" => "disk" "disk": "disk"
} }
] ]
""" """

View File

@ -4,7 +4,6 @@ DEFAULT_HEADERS = {
'Accept' => 'application/json' 'Accept' => 'application/json'
} }
When(/^I send GET '(.*)' query$/) do |path| When(/^I send GET '(.*)' query$/) do |path|
puts path
get(path, {}, DEFAULT_HEADERS) get(path, {}, DEFAULT_HEADERS)
end end

View File

@ -25,8 +25,23 @@ class RequestSender
@last_res = nil @last_res = nil
$test_hash = Hash.new $test_hash = Hash.new
# config:
# host=<host>
# port=<port>
# username=<user>
# password=<psw>
def initialize
file = "tests.conf"
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
end
def host def host
"http://#{HOST}:#{PORT}" "http://#{@config["host"]}:#{@config["port"]}"
end end
def last_response def last_response
@ -54,7 +69,7 @@ class RequestSender
def submit def submit
http = HTTPClient.new http = HTTPClient.new
http.set_auth(host, USERNAME, PASSWORD) http.set_auth(nil, @config["username"], @config["password"])
res = yield http res = yield http
@last_res = res @last_res = res
end end