From eb711787aef5d2629ea76c2bbaa3d2e939fc37c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Gru=C3=9F?= Date: Wed, 3 Jun 2015 15:31:20 +0200 Subject: [PATCH] tests added --- features/step_definitions/post.rb | 44 +++++++++++++++++++++++++++++++ features/support/post.rb | 23 ++++++++++++++++ features/testbot/post.feature | 23 ++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 features/step_definitions/post.rb create mode 100644 features/support/post.rb create mode 100644 features/testbot/post.feature diff --git a/features/step_definitions/post.rb b/features/step_definitions/post.rb new file mode 100644 index 000000000..20fe143c4 --- /dev/null +++ b/features/step_definitions/post.rb @@ -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 \ No newline at end of file diff --git a/features/support/post.rb b/features/support/post.rb new file mode 100644 index 000000000..bc532a870 --- /dev/null +++ b/features/support/post.rb @@ -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 diff --git a/features/testbot/post.feature b/features/testbot/post.feature new file mode 100644 index 000000000..ce9ca5036 --- /dev/null +++ b/features/testbot/post.feature @@ -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 |