1 require File.dirname(__FILE__) + '/../test_helper'
2 require 'api_controller'
4 # Re-raise errors caught by the controller.
5 class ApiController; def rescue_action(e) raise e end; end
7 class ApiControllerTest < Test::Unit::TestCase
11 @controller = ApiController.new
12 @request = ActionController::TestRequest.new
13 @response = ActionController::TestResponse.new
16 def basic_authorization(user, pass)
17 @request.env["HTTP_AUTHORIZATION"] = "Basic %s" % Base64.encode64("#{user}:#{pass}")
20 # -------------------------------------
21 # Test reading a bounding box.
22 # -------------------------------------
25 node = current_nodes(:used_node_1)
26 # Need to split the min/max lat/lon out into their own variables here
27 # so that we can test they are returned later.
32 bbox = "#{minlon},#{minlat},#{maxlon},#{maxlat}"
33 get :map, :bbox => bbox
35 print @request.to_yaml
38 assert_response :success
39 assert_select "osm[version='#{API_VERSION}'][generator='#{GENERATOR}']:root", :count => 1 do
40 assert_select "bounds[minlon=#{minlon}][minlat=#{minlat}][maxlon=#{maxlon}][maxlat=#{maxlat}]", :count => 1
41 assert_select "node[id=#{node.id}][lat=#{node.lat}][lon=#{node.lon}][version=#{node.version}][changeset=#{node.changeset_id}][visible=#{node.visible}][timestamp=#{node.timestamp.xmlschema}]", :count => 1 do
42 # This should really be more generic
43 assert_select "tag[k=test][v=1]"
45 # Should also test for the ways and relation
49 def test_map_without_bbox
51 assert_response :bad_request
52 assert_equal "The parameter bbox is required, and must be of the form min_lon,min_lat,max_lon,max_lat", @response.body
55 def test_traces_without_bbox
57 assert_response :bad_request
58 assert_equal "The parameter bbox is required, and must be of the form min_lon,min_lat,max_lon,max_lat", @response.body
61 def test_traces_page_less_than_0
63 get :trackpoints, :page => i, :bbox => "-0.1,-0.1,0.1,0.1"
64 assert_response :bad_request
65 assert_equal "Page number must be greater than or equal to 0", @response.body
68 get :trackpoints, :page => i, :bbox => "-0.1,-0.1,0.1,0.1"
69 assert_response :success
73 def test_traces_bbox_too_big
74 bad = %w{ -0.1,-0.1,1.1,1.1 10,10,11,11 }
76 get :trackpoints, :bbox => bbox
77 assert_response :bad_request
78 assert_equal "The maximum bbox size is #{APP_CONFIG['max_request_area']}, and your request was too large. Either request a smaller area, or use planet.osm", @response.body
84 assert_response :success
85 assert_select "osm:root[version='#{API_VERSION}'][generator='#{GENERATOR}']", :count => 1 do
86 assert_select "api", :count => 1 do
87 assert_select "version[minimum=#{API_VERSION}][maximum=#{API_VERSION}]", :count => 1
88 assert_select "area[maximum=#{APP_CONFIG['max_request_area']}]", :count => 1
89 assert_select "tracepoints[per_page=#{APP_CONFIG['tracepoints_per_page']}]", :count => 1