-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | |