test different status message and query parsing
This commit is contained in:
parent
85148d1283
commit
2cddf90e49
@ -19,6 +19,16 @@ Then /^response should be well-formed$/ do
|
||||
@json['status'].class.should == Fixnum
|
||||
end
|
||||
|
||||
Then /^status code should be (\d+)$/ do |code|
|
||||
@json = JSON.parse @response.body
|
||||
@json['status'].should == code.to_i
|
||||
end
|
||||
|
||||
Then /^status message should be "(.*?)"$/ do |message|
|
||||
@json = JSON.parse @response.body
|
||||
@json['status_message'].should == message
|
||||
end
|
||||
|
||||
Then /^response should be a well-formed route$/ do
|
||||
step "response should be well-formed"
|
||||
@json['status_message'].class.should == String
|
||||
|
@ -3,29 +3,36 @@ When /^I route I should get$/ do |table|
|
||||
actual = []
|
||||
OSRMBackgroundLauncher.new("#{@osm_file}.osrm") do
|
||||
table.hashes.each_with_index do |row,ri|
|
||||
waypoints = []
|
||||
if row['from'] and row['to']
|
||||
node = find_node_by_name(row['from'])
|
||||
raise "*** unknown from-node '#{row['from']}" unless node
|
||||
waypoints << node
|
||||
|
||||
node = find_node_by_name(row['to'])
|
||||
raise "*** unknown to-node '#{row['to']}" unless node
|
||||
waypoints << node
|
||||
|
||||
got = {'from' => row['from'], 'to' => row['to'] }
|
||||
elsif row['waypoints']
|
||||
row['waypoints'].split(',').each do |n|
|
||||
node = find_node_by_name(n.strip)
|
||||
raise "*** unknown waypoint node '#{n.strip}" unless node
|
||||
waypoints << node
|
||||
end
|
||||
got = {'waypoints' => row['waypoints'] }
|
||||
if row['request']
|
||||
got = {'request' => row['request'] }
|
||||
response = request_url row['request']
|
||||
else
|
||||
raise "*** no waypoints"
|
||||
params = {}
|
||||
waypoints = []
|
||||
if row['from'] and row['to']
|
||||
node = find_node_by_name(row['from'])
|
||||
raise "*** unknown from-node '#{row['from']}" unless node
|
||||
waypoints << node
|
||||
|
||||
node = find_node_by_name(row['to'])
|
||||
raise "*** unknown to-node '#{row['to']}" unless node
|
||||
waypoints << node
|
||||
|
||||
got = {'from' => row['from'], 'to' => row['to'] }
|
||||
response = request_route waypoints, params
|
||||
elsif row['waypoints']
|
||||
row['waypoints'].split(',').each do |n|
|
||||
node = find_node_by_name(n.strip)
|
||||
raise "*** unknown waypoint node '#{n.strip}" unless node
|
||||
waypoints << node
|
||||
end
|
||||
got = {'waypoints' => row['waypoints'] }
|
||||
response = request_route waypoints, params
|
||||
else
|
||||
raise "*** no waypoints"
|
||||
end
|
||||
end
|
||||
|
||||
params = {}
|
||||
row.each_pair do |k,v|
|
||||
if k =~ /param:(.*)/
|
||||
if v=='(nil)'
|
||||
@ -37,9 +44,11 @@ When /^I route I should get$/ do |table|
|
||||
end
|
||||
end
|
||||
|
||||
response = request_route(waypoints, params)
|
||||
if response.code == "200" && response.body.empty? == false
|
||||
if response.body.empty? == false
|
||||
json = JSON.parse response.body
|
||||
end
|
||||
|
||||
if response.body.empty? == false
|
||||
if json['status'] == 0
|
||||
instructions = way_list json['route_instructions']
|
||||
bearings = bearing_list json['route_instructions']
|
||||
@ -51,61 +60,64 @@ When /^I route I should get$/ do |table|
|
||||
end
|
||||
end
|
||||
|
||||
if table.headers.include? 'start'
|
||||
got['start'] = instructions ? json['route_summary']['start_point'] : nil
|
||||
if table.headers.include? 'status'
|
||||
got['status'] = json['status'].to_s
|
||||
end
|
||||
if table.headers.include? 'end'
|
||||
got['end'] = instructions ? json['route_summary']['end_point'] : nil
|
||||
if table.headers.include? 'message'
|
||||
got['message'] = json['status_message']
|
||||
end
|
||||
if table.headers.include? 'route'
|
||||
got['route'] = (instructions || '').strip
|
||||
if table.headers.include?('distance')
|
||||
if row['distance']!=''
|
||||
raise "*** Distance must be specied in meters. (ex: 250m)" unless row['distance'] =~ /\d+m/
|
||||
if table.headers.include? '#' # comment column
|
||||
got['#'] = row['#'] # copy value so it always match
|
||||
end
|
||||
|
||||
if response.code == "200"
|
||||
if table.headers.include? 'start'
|
||||
got['start'] = instructions ? json['route_summary']['start_point'] : nil
|
||||
end
|
||||
if table.headers.include? 'end'
|
||||
got['end'] = instructions ? json['route_summary']['end_point'] : nil
|
||||
end
|
||||
if table.headers.include? 'route'
|
||||
got['route'] = (instructions || '').strip
|
||||
if table.headers.include?('distance')
|
||||
if row['distance']!=''
|
||||
raise "*** Distance must be specied in meters. (ex: 250m)" unless row['distance'] =~ /\d+m/
|
||||
end
|
||||
got['distance'] = instructions ? "#{json['route_summary']['total_distance'].to_s}m" : ''
|
||||
end
|
||||
got['distance'] = instructions ? "#{json['route_summary']['total_distance'].to_s}m" : ''
|
||||
end
|
||||
if table.headers.include?('time')
|
||||
raise "*** Time must be specied in seconds. (ex: 60s)" unless row['time'] =~ /\d+s/
|
||||
got['time'] = instructions ? "#{json['route_summary']['total_time'].to_s}s" : ''
|
||||
end
|
||||
if table.headers.include?('speed')
|
||||
if row['speed'] != '' && instructions
|
||||
raise "*** Speed must be specied in km/h. (ex: 50 km/h)" unless row['speed'] =~ /\d+ km\/h/
|
||||
time = json['route_summary']['total_time']
|
||||
distance = json['route_summary']['total_distance']
|
||||
speed = time>0 ? (3.6*distance/time).to_i : nil
|
||||
got['speed'] = "#{speed} km/h"
|
||||
else
|
||||
got['speed'] = ''
|
||||
if table.headers.include?('time')
|
||||
raise "*** Time must be specied in seconds. (ex: 60s)" unless row['time'] =~ /\d+s/
|
||||
got['time'] = instructions ? "#{json['route_summary']['total_time'].to_s}s" : ''
|
||||
end
|
||||
if table.headers.include?('speed')
|
||||
if row['speed'] != '' && instructions
|
||||
raise "*** Speed must be specied in km/h. (ex: 50 km/h)" unless row['speed'] =~ /\d+ km\/h/
|
||||
time = json['route_summary']['total_time']
|
||||
distance = json['route_summary']['total_distance']
|
||||
speed = time>0 ? (3.6*distance/time).to_i : nil
|
||||
got['speed'] = "#{speed} km/h"
|
||||
else
|
||||
got['speed'] = ''
|
||||
end
|
||||
end
|
||||
if table.headers.include? 'bearing'
|
||||
got['bearing'] = bearings
|
||||
end
|
||||
if table.headers.include? 'compass'
|
||||
got['compass'] = compasses
|
||||
end
|
||||
if table.headers.include? 'turns'
|
||||
got['turns'] = turns
|
||||
end
|
||||
if table.headers.include? 'modes'
|
||||
got['modes'] = modes
|
||||
end
|
||||
if table.headers.include? 'times'
|
||||
got['times'] = times
|
||||
end
|
||||
if table.headers.include? 'distances'
|
||||
got['distances'] = distances
|
||||
end
|
||||
end
|
||||
if table.headers.include? 'bearing'
|
||||
got['bearing'] = bearings
|
||||
end
|
||||
if table.headers.include? 'compass'
|
||||
got['compass'] = compasses
|
||||
end
|
||||
if table.headers.include? 'turns'
|
||||
got['turns'] = turns
|
||||
end
|
||||
if table.headers.include? 'modes'
|
||||
got['modes'] = modes
|
||||
end
|
||||
if table.headers.include? 'times'
|
||||
got['times'] = times
|
||||
end
|
||||
if table.headers.include? 'distances'
|
||||
got['distances'] = distances
|
||||
end
|
||||
if table.headers.include? 'status'
|
||||
got['status'] = json['status'].to_s
|
||||
end
|
||||
if table.headers.include? 'message'
|
||||
got['message'] = json['status_message']
|
||||
end
|
||||
if table.headers.include? '#' # comment column
|
||||
got['#'] = row['#'] # copy value so it always match
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -26,6 +26,18 @@ rescue Timeout::Error
|
||||
raise "*** osrm-routed did not respond."
|
||||
end
|
||||
|
||||
def request_url path
|
||||
uri = URI.parse"#{HOST}/#{path}"
|
||||
@query = uri.to_s
|
||||
Timeout.timeout(OSRM_TIMEOUT) do
|
||||
Net::HTTP.get_response uri
|
||||
end
|
||||
rescue Errno::ECONNREFUSED => e
|
||||
raise "*** osrm-routed is not running."
|
||||
rescue Timeout::Error
|
||||
raise "*** osrm-routed did not respond."
|
||||
end
|
||||
|
||||
def request_route waypoints, params={}
|
||||
defaults = { 'output' => 'json', 'instructions' => true, 'alt' => false }
|
||||
request_path "viaroute", waypoints, defaults.merge(params)
|
||||
|
36
features/testbot/query.feature
Normal file
36
features/testbot/query.feature
Normal file
@ -0,0 +1,36 @@
|
||||
@routing @query
|
||||
Feature: Query message parsing
|
||||
|
||||
Background:
|
||||
Given the profile "testbot"
|
||||
|
||||
Scenario: Malformed requests
|
||||
Given the node locations
|
||||
| node | lat | lon |
|
||||
| a | 1.00 | 1.00 |
|
||||
| b | 1.01 | 1.00 |
|
||||
|
||||
And the ways
|
||||
| nodes |
|
||||
| ab |
|
||||
|
||||
When I route I should get
|
||||
| request | status | message |
|
||||
| viaroute?loc=1,1&loc=1.01,1 | 0 | Found route between points |
|
||||
| nonsense | 400 | Bad Request |
|
||||
| nonsense?loc=1,1&loc=1.01,1 | 400 | Bad Request |
|
||||
| | 400 | Query string malformed close to position 0 |
|
||||
| / | 400 | Query string malformed close to position 0 |
|
||||
| ? | 400 | Query string malformed close to position 0 |
|
||||
| viaroute/loc= | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=1 | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=1,1 | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=1,1,1 | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=x | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=x,y | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=1,1&loc= | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=1,1&loc=1 | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=1,1&loc=1,1 | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=1,1&loc=1,1,1 | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=1,1&loc=x | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=1,1&loc=x,y | 400 | Query string malformed close to position 9 |
|
@ -4,6 +4,19 @@ Feature: Status messages
|
||||
Background:
|
||||
Given the profile "testbot"
|
||||
|
||||
Scenario: Route found
|
||||
Given the node map
|
||||
| a | b |
|
||||
|
||||
Given the ways
|
||||
| nodes |
|
||||
| ab |
|
||||
|
||||
When I route I should get
|
||||
| from | to | route | status | message |
|
||||
| a | b | ab | 0 | Found route between points |
|
||||
| b | a | ab | 0 | Found route between points |
|
||||
|
||||
Scenario: No route found
|
||||
Given the node map
|
||||
| a | b |
|
||||
@ -21,3 +34,34 @@ Feature: Status messages
|
||||
| c | d | cd | 0 | Found route between points |
|
||||
| a | c | | 207 | Cannot find route between points |
|
||||
| b | d | | 207 | Cannot find route between points |
|
||||
|
||||
Scenario: Malformed requests
|
||||
Given the node locations
|
||||
| node | lat | lon |
|
||||
| a | 1.00 | 1.00 |
|
||||
| b | 1.01 | 1.00 |
|
||||
|
||||
And the ways
|
||||
| nodes |
|
||||
| ab |
|
||||
|
||||
When I route I should get
|
||||
| request | status | message |
|
||||
| viaroute?loc=1,1&loc=1.01,1 | 0 | Found route between points |
|
||||
| nonsense | 400 | Bad Request |
|
||||
| nonsense?loc=1,1&loc=1.01,1 | 400 | Bad Request |
|
||||
| | 400 | Query string malformed close to position 0 |
|
||||
| / | 400 | Query string malformed close to position 0 |
|
||||
| ? | 400 | Query string malformed close to position 0 |
|
||||
| viaroute/loc= | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=1 | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=1,1 | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=1,1,1 | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=x | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=x,y | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=1,1&loc= | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=1,1&loc=1 | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=1,1&loc=1,1 | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=1,1&loc=1,1,1 | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=1,1&loc=x | 400 | Query string malformed close to position 9 |
|
||||
| viaroute/loc=1,1&loc=x,y | 400 | Query string malformed close to position 9 |
|
Loading…
Reference in New Issue
Block a user