tests added
This commit is contained in:
parent
daa6d02887
commit
eb711787ae
44
features/step_definitions/post.rb
Normal file
44
features/step_definitions/post.rb
Normal file
@ -0,0 +1,44 @@
|
||||
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
|
23
features/support/post.rb
Normal file
23
features/support/post.rb
Normal file
@ -0,0 +1,23 @@
|
||||
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
|
23
features/testbot/post.feature
Normal file
23
features/testbot/post.feature
Normal file
@ -0,0 +1,23 @@
|
||||
@post @testbot
|
||||
Feature: POST request
|
||||
|
||||
Background:
|
||||
Given the profile "testbot"
|
||||
|
||||
Scenario: Accept POST Request
|
||||
Given the node locations
|
||||
| node | lat | lon |
|
||||
| a | 1.00 | 1.00 |
|
||||
| b | 1.01 | 1.00 |
|
||||
|
||||
And the ways
|
||||
| nodes |
|
||||
| ab |
|
||||
|
||||
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 |
|
Loading…
Reference in New Issue
Block a user