post tests via query options available
This commit is contained in:
parent
eb711787ae
commit
dce917eb74
@ -9,7 +9,8 @@ When /^I request locate I should get$/ do |table|
|
||||
out_node = find_node_by_name row['out']
|
||||
raise "*** unknown out-node '#{row['out']}" unless out_node
|
||||
|
||||
response = request_locate("#{in_node.lat},#{in_node.lon}")
|
||||
params = @query_params
|
||||
response = request_locate("#{in_node.lat},#{in_node.lon}", params)
|
||||
if response.code == "200" && response.body.empty? == false
|
||||
json = JSON.parse response.body
|
||||
if json['status'] == 0
|
||||
|
@ -9,7 +9,8 @@ When /^I request nearest I should get$/ do |table|
|
||||
out_node = find_node_by_name row['out']
|
||||
raise "*** unknown out-node '#{row['out']}" unless out_node
|
||||
|
||||
response = request_nearest("#{in_node.lat},#{in_node.lon}")
|
||||
params = @query_params
|
||||
response = request_nearest("#{in_node.lat},#{in_node.lon}", params)
|
||||
if response.code == "200" && response.body.empty? == false
|
||||
json = JSON.parse response.body
|
||||
if json['status'] == 0
|
||||
|
@ -1,44 +0,0 @@
|
||||
When /^I request post I should get$/ do |table|
|
||||
reprocess
|
||||
actual = []
|
||||
OSRMLoader.load(self,"#{prepared_file}.osrm") do
|
||||
table.hashes.each_with_index do |row,ri|
|
||||
request_string = row['request'].split("?")
|
||||
got = {'request' => row['request'] }
|
||||
response = request_post_url request_string[0], request_string[1]
|
||||
|
||||
row.each_pair do |k,v|
|
||||
if k =~ /param:(.*)/
|
||||
if v=='(nil)'
|
||||
params[$1]=nil
|
||||
elsif v!=nil
|
||||
params[$1]=v
|
||||
end
|
||||
got[k]=v
|
||||
end
|
||||
end
|
||||
|
||||
if table.headers.include? 'status_code'
|
||||
# the only thing we want to test is
|
||||
# an accepted request
|
||||
got['status_code'] = response.code.to_s
|
||||
end
|
||||
|
||||
ok = true
|
||||
row.keys.each do |key|
|
||||
if FuzzyMatch.match got[key], row[key]
|
||||
got[key] = row[key]
|
||||
else
|
||||
ok = false
|
||||
end
|
||||
end
|
||||
|
||||
unless ok
|
||||
log_fail row,got, { 'route' => {:query => @query, :response => response} }
|
||||
end
|
||||
|
||||
actual << got
|
||||
end
|
||||
end
|
||||
table.diff! actual
|
||||
end
|
@ -1,10 +1,25 @@
|
||||
require 'net/http'
|
||||
|
||||
def request_locate_url path
|
||||
def request_locate_url path, method={}
|
||||
@query = path
|
||||
|
||||
if method.has_key?("post")
|
||||
request_method = "POST"
|
||||
else
|
||||
request_method = "GET"
|
||||
end
|
||||
if request_method.eql? "GET"
|
||||
uri = URI.parse "#{HOST}/#{path}"
|
||||
elsif request_method.eql? "POST"
|
||||
uri = URI.parse "#{HOST}/locate"
|
||||
end
|
||||
Timeout.timeout(OSRM_TIMEOUT) do
|
||||
if request_method.eql? "GET"
|
||||
Net::HTTP.get_response uri
|
||||
elsif request_method.eql? "POST"
|
||||
path.slice!(0, 11)
|
||||
Net::HTTP.post_form uri, "loc" => path
|
||||
end
|
||||
end
|
||||
rescue Errno::ECONNREFUSED => e
|
||||
raise "*** osrm-routed is not running."
|
||||
@ -12,6 +27,6 @@ rescue Timeout::Error
|
||||
raise "*** osrm-routed did not respond."
|
||||
end
|
||||
|
||||
def request_locate a
|
||||
request_locate_url "locate?loc=#{a}"
|
||||
def request_locate a, method
|
||||
request_locate_url "locate?loc=#{a}", method
|
||||
end
|
||||
|
@ -13,10 +13,31 @@ def request_matching trace=[], timestamps=[], options={}
|
||||
end
|
||||
params = (trace_params + defaults.merge(options).to_param).join('&')
|
||||
params = nil if params==""
|
||||
|
||||
if options.has_key?("post")
|
||||
request_method = "POST"
|
||||
options.delete("post")
|
||||
else
|
||||
request_method = "GET"
|
||||
end
|
||||
if request_method.eql? "GET"
|
||||
uri = URI.parse ["#{HOST}/match", params].compact.join('?')
|
||||
elsif request_method.eql? "POST"
|
||||
uri = URI.parse "#{HOST}/match"
|
||||
end
|
||||
@query = uri.to_s
|
||||
Timeout.timeout(OSRM_TIMEOUT) do
|
||||
if request_method.eql? "GET"
|
||||
Net::HTTP.get_response uri
|
||||
elsif request_method.eql? "POST"
|
||||
datas = {}
|
||||
datas[:loc] = trace.compact.map { |w| "#{w.lat},#{w.lon}" }
|
||||
if ts.length > 0
|
||||
datas[:t] = timestamps.compact.map { |t| "#{t}" }
|
||||
end
|
||||
datas.merge! options
|
||||
Net::HTTP.post_form uri, datas
|
||||
end
|
||||
end
|
||||
rescue Errno::ECONNREFUSED => e
|
||||
raise "*** osrm-routed is not running."
|
||||
|
@ -1,10 +1,25 @@
|
||||
require 'net/http'
|
||||
|
||||
def request_nearest_url path
|
||||
def request_nearest_url path, method={}
|
||||
@query = path
|
||||
|
||||
if method.has_key?("post")
|
||||
request_method = "POST"
|
||||
else
|
||||
request_method = "GET"
|
||||
end
|
||||
if request_method.eql? "GET"
|
||||
uri = URI.parse "#{HOST}/#{path}"
|
||||
elsif request_method.eql? "POST"
|
||||
uri = URI.parse "#{HOST}/nearest"
|
||||
end
|
||||
Timeout.timeout(OSRM_TIMEOUT) do
|
||||
if request_method.eql? "GET"
|
||||
Net::HTTP.get_response uri
|
||||
elsif request_method.eql? "POST"
|
||||
path.slice!(0, 12)
|
||||
Net::HTTP.post_form uri, "loc" => path
|
||||
end
|
||||
end
|
||||
rescue Errno::ECONNREFUSED => e
|
||||
raise "*** osrm-routed is not running."
|
||||
@ -12,6 +27,6 @@ rescue Timeout::Error
|
||||
raise "*** osrm-routed did not respond."
|
||||
end
|
||||
|
||||
def request_nearest a
|
||||
request_nearest_url "nearest?loc=#{a}"
|
||||
def request_nearest a, method
|
||||
request_nearest_url "nearest?loc=#{a}", method
|
||||
end
|
||||
|
@ -1,23 +0,0 @@
|
||||
require 'net/http'
|
||||
|
||||
HOST = "http://127.0.0.1:#{OSRM_PORT}"
|
||||
|
||||
def request_post_url service, param_string
|
||||
uri = URI.parse"#{HOST}/#{service}"
|
||||
@query = uri.to_s
|
||||
Timeout.timeout(OSRM_TIMEOUT) do
|
||||
params = {}
|
||||
values = param_string.split("loc=")
|
||||
locs = []
|
||||
values.each do |value|
|
||||
locs << "#{value}".gsub(/[&]/, '')
|
||||
end
|
||||
locs.reject! { |c| c.empty? }
|
||||
params.merge!(loc: locs)
|
||||
Net::HTTP.post_form uri, params
|
||||
end
|
||||
rescue Errno::ECONNREFUSED => e
|
||||
raise "*** osrm-routed is not running."
|
||||
rescue Timeout::Error
|
||||
raise "*** osrm-routed did not respond."
|
||||
end
|
@ -15,10 +15,28 @@ def request_path path, waypoints=[], options={}
|
||||
locs = waypoints.compact.map { |w| "loc=#{w.lat},#{w.lon}" }
|
||||
params = (locs + options.to_param).join('&')
|
||||
params = nil if params==""
|
||||
|
||||
if options.has_key?("post")
|
||||
request_method = "POST"
|
||||
options.delete("post")
|
||||
else
|
||||
request_method = "GET"
|
||||
end
|
||||
if request_method.eql? "GET"
|
||||
uri = URI.parse ["#{HOST}/#{path}", params].compact.join('?')
|
||||
elsif request_method.eql? "POST"
|
||||
uri = URI.parse "#{HOST}/#{path}"
|
||||
end
|
||||
@query = uri.to_s
|
||||
Timeout.timeout(OSRM_TIMEOUT) do
|
||||
if request_method.eql? "GET"
|
||||
Net::HTTP.get_response uri
|
||||
elsif request_method.eql? "POST"
|
||||
datas = {}
|
||||
datas[:loc] = waypoints.compact.map { |w| "#{w.lat},#{w.lon}" }
|
||||
datas.merge! options
|
||||
Net::HTTP.post_form uri, datas
|
||||
end
|
||||
end
|
||||
rescue Errno::ECONNREFUSED => e
|
||||
raise "*** osrm-routed is not running."
|
||||
|
@ -4,20 +4,111 @@ Feature: POST request
|
||||
Background:
|
||||
Given the profile "testbot"
|
||||
|
||||
Scenario: Accept POST Request
|
||||
Scenario: Testbot - viaroute POST request
|
||||
Given the node locations
|
||||
| node | lat | lon |
|
||||
| a | 1.00 | 1.00 |
|
||||
| b | 1.01 | 1.00 |
|
||||
| a | 55.68740 | 12.52430 |
|
||||
| b | 55.68745 | 12.52409 |
|
||||
| c | 55.68711 | 12.52383 |
|
||||
| x | -55.68740 | 12.52430 |
|
||||
| y | -55.68745 | 12.52409 |
|
||||
| z | -55.68711 | 12.52383 |
|
||||
|
||||
And the ways
|
||||
| nodes |
|
||||
| ab |
|
||||
| bc |
|
||||
| xy |
|
||||
| yz |
|
||||
|
||||
When I request post I should get
|
||||
| request | status_code |
|
||||
| locate?loc=1.0,1.0 | 200 |
|
||||
| nearest?loc=1.0,1.0 | 200 |
|
||||
| viaroute?loc=1,1&loc=1.01,1 | 200 |
|
||||
| match?loc=1,1&loc=1.01,1 | 200 |
|
||||
| table?loc=1,1&loc=1.01,1 | 200 |
|
||||
And the query options
|
||||
| post | true |
|
||||
|
||||
When I route I should get
|
||||
| from | to | route | turns |
|
||||
| a | c | ab,bc | head,left,destination |
|
||||
| c | a | bc,ab | head,right,destination |
|
||||
| x | z | xy,yz | head,right,destination |
|
||||
| z | x | yz,xy | head,left,destination |
|
||||
|
||||
Scenario: Testbot - match POST request
|
||||
Given the node map
|
||||
| a | b | c | d |
|
||||
| e | f | g | h |
|
||||
|
||||
And the ways
|
||||
| nodes | oneway |
|
||||
| abcd | yes |
|
||||
| hgfe | yes |
|
||||
|
||||
And the query options
|
||||
| post | true |
|
||||
|
||||
When I match I should get
|
||||
| trace | matchings |
|
||||
| dcba | hgfe |
|
||||
|
||||
Scenario: Testbot - table POST request
|
||||
Given the node map
|
||||
| x | a | b | y |
|
||||
| | d | e | |
|
||||
|
||||
And the ways
|
||||
| nodes | oneway |
|
||||
| abeda | yes |
|
||||
| xa | |
|
||||
| by | |
|
||||
|
||||
And the query options
|
||||
| post | true |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | x | y | d | e |
|
||||
| x | 0 | 300 | 400 | 300 |
|
||||
| y | 500 | 0 | 300 | 200 |
|
||||
| d | 200 | 300 | 0 | 300 |
|
||||
| e | 300 | 400 | 100 | 0 |
|
||||
|
||||
Scenario: Testbot - locate POST request
|
||||
Given the node locations
|
||||
| node | lat | lon |
|
||||
| a | -85 | -180 |
|
||||
| b | 0 | 0 |
|
||||
| c | 85 | 180 |
|
||||
| x | -84 | -180 |
|
||||
| y | 84 | 180 |
|
||||
|
||||
And the ways
|
||||
| nodes |
|
||||
| abc |
|
||||
|
||||
And the query options
|
||||
| post | true |
|
||||
|
||||
When I request locate I should get
|
||||
| in | out |
|
||||
| x | a |
|
||||
| y | c |
|
||||
|
||||
Scenario: Testbot - nearest POST request
|
||||
Given the node locations
|
||||
| node | lat | lon |
|
||||
| a | -85 | -180 |
|
||||
| b | -85 | -160 |
|
||||
| c | -85 | -140 |
|
||||
| x | -84.999 | -180 |
|
||||
| y | -84.999 | -160 |
|
||||
| z | -84.999 | -140 |
|
||||
|
||||
And the ways
|
||||
| nodes |
|
||||
| abc |
|
||||
|
||||
And the query options
|
||||
| post | true |
|
||||
|
||||
When I request nearest I should get
|
||||
| in | out |
|
||||
| x | a |
|
||||
| y | b |
|
||||
| z | c |
|
||||
|
Loading…
Reference in New Issue
Block a user