test/test_google_geocoder.rb in geokit-1.8.4 vs test/test_google_geocoder.rb in geokit-1.8.5
- old
+ new
@@ -31,16 +31,30 @@
Geokit::Geocoders::GoogleGeocoder.client_id = 'clientID'
Geokit::Geocoders::GoogleGeocoder.cryptographic_key = 'vNIXE0xscrmjlyV-12Nj_BvUPaw='
url = Geokit::Geocoders::GoogleGeocoder.send(:submit_url, 'address=New+York')
Geokit::Geocoders::GoogleGeocoder.client_id = nil
Geokit::Geocoders::GoogleGeocoder.cryptographic_key = nil
- assert_equal 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=New+York&client=clientID&signature=9mevp7SoVsSKzF9nj-vApMYbatg=', url
+ assert_equal 'https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=New+York&client=clientID&signature=9mevp7SoVsSKzF9nj-vApMYbatg=', url
end
+ def test_google_api_key
+ Geokit::Geocoders::GoogleGeocoder.api_key = 'someKey'
+ url = Geokit::Geocoders::GoogleGeocoder.send(:submit_url, 'address=New+York')
+ Geokit::Geocoders::GoogleGeocoder.api_key = nil
+ assert_equal 'https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=New+York&key=someKey', url
+ end
+
+ def test_google_insecure_url
+ Geokit::Geocoders.secure = false
+ url = Geokit::Geocoders::GoogleGeocoder.send(:submit_url, 'address=New+York')
+ Geokit::Geocoders.secure = true
+ assert_equal 'http://maps.google.com/maps/api/geocode/json?sensor=false&address=New+York', url
+ end
+
def test_google_full_address
VCR.use_cassette('google_full_short') do
- url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
TestHelper.expects(:last_url).with(url)
res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
assert_equal "CA", res.state
assert_equal "San Francisco", res.city
assert_array_in_delta [37.7749295, -122.4194155], res.to_a # slightly dif from yahoo
@@ -50,11 +64,11 @@
end
end
def test_google_full_address_with_geo_loc
VCR.use_cassette('google_full') do
- url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@full_address_short_zip)}"
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@full_address_short_zip)}"
TestHelper.expects(:last_url).with(url)
res=Geokit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
assert_equal "CA", res.state
assert_equal "San Francisco", res.city
assert_array_in_delta [37.7921509, -122.394], res.to_a # slightly dif from yahoo
@@ -64,21 +78,21 @@
end
end
def test_google_full_address_accuracy
VCR.use_cassette('google_full') do
- url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@full_address_short_zip)}"
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@full_address_short_zip)}"
TestHelper.expects(:last_url).with(url)
res=Geokit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
assert_equal 9, res.accuracy
end
end
def test_google_city
VCR.use_cassette('google_city') do
- url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
TestHelper.expects(:last_url).with(url)
res=Geokit::Geocoders::GoogleGeocoder.do_geocode(@address)
assert_nil res.street_address
assert_equal "CA", res.state
assert_equal "San Francisco", res.city
@@ -89,20 +103,20 @@
end
end
def test_google_city_accuracy
VCR.use_cassette('google_city') do
- url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
TestHelper.expects(:last_url).with(url)
res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
assert_equal 4, res.accuracy
end
end
def test_google_city_with_geo_loc
VCR.use_cassette('google_city') do
- url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
TestHelper.expects(:last_url).with(url)
res=Geokit::Geocoders::GoogleGeocoder.geocode(@google_city_loc)
assert_equal "CA", res.state
assert_equal "San Francisco", res.city
assert_equal "37.7749295,-122.4194155", res.ll
@@ -113,11 +127,11 @@
end
end
def test_google_suggested_bounds
VCR.use_cassette('google_full') do
- url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@full_address_short_zip)}"
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@full_address_short_zip)}"
TestHelper.expects(:last_url).with(url)
res = Geokit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
assert_instance_of Geokit::Bounds, res.suggested_bounds
assert_array_in_delta [37.7908019197085, -122.3953489802915], res.suggested_bounds.sw.to_a
assert_array_in_delta [37.7934998802915, -122.3926510197085], res.suggested_bounds.ne.to_a
@@ -127,25 +141,25 @@
def test_google_suggested_bounds_url
bounds = Geokit::Bounds.new(
Geokit::LatLng.new(33.7036917, -118.6681759),
Geokit::LatLng.new(34.3373061, -118.1552891)
)
- url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=Winnetka&bounds=33.7036917%2C-118.6681759%7C34.3373061%2C-118.1552891"
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=Winnetka&bounds=33.7036917%2C-118.6681759%7C34.3373061%2C-118.1552891"
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url)
Geokit::Geocoders::GoogleGeocoder.geocode('Winnetka', :bias => bounds)
end
def test_service_unavailable
response = MockFailure.new
- url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
assert !Geokit::Geocoders::GoogleGeocoder.geocode(@google_city_loc).success
end
def test_multiple_results
VCR.use_cassette('google_multi') do
- url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape('via Sandro Pertini 8, Ossona, MI')}"
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape('via Sandro Pertini 8, Ossona, MI')}"
TestHelper.expects(:last_url).with(url)
res=Geokit::Geocoders::GoogleGeocoder.geocode('via Sandro Pertini 8, Ossona, MI')
assert_equal 5, res.all.size
res = res.all[0]
assert_equal "Lombardy", res.state
@@ -169,11 +183,11 @@
#
def test_reverse_geocode
VCR.use_cassette('google_reverse_madrid') do
madrid = Geokit::GeoLoc.new
madrid.lat, madrid.lng = "40.4167413", "-3.7032498"
- url = "http://maps.google.com/maps/api/geocode/json?sensor=false&latlng=#{Geokit::Inflector::url_escape(madrid.ll)}"
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&latlng=#{Geokit::Inflector::url_escape(madrid.ll)}"
TestHelper.expects(:last_url).with(url)
res=Geokit::Geocoders::GoogleGeocoder.do_reverse_geocode(madrid.ll)
assert_equal madrid.lat.to_s.slice(1..5), res.lat.to_s.slice(1..5)
assert_equal madrid.lng.to_s.slice(1..5), res.lng.to_s.slice(1..5)
@@ -189,33 +203,33 @@
end
end
def test_reverse_geocode_language
VCR.use_cassette('google_reverse_madrid_es') do
- url = "http://maps.google.com/maps/api/geocode/json?sensor=false&latlng=40.416%2C-3.703&language=es"
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&latlng=40.416%2C-3.703&language=es"
TestHelper.expects(:last_url).with(url)
language_result = Geokit::Geocoders::GoogleGeocoder.reverse_geocode('40.416,-3.703', :language => 'es')
assert_equal 'ES', language_result.country_code
assert_equal 'Madrid', language_result.city
end
end
def test_country_code_biasing
VCR.use_cassette('google_country_code_biased_result') do
- url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=Syracuse®ion=it"
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=Syracuse®ion=it"
TestHelper.expects(:last_url).with(url)
biased_result = Geokit::Geocoders::GoogleGeocoder.geocode('Syracuse', :bias => 'it')
assert_equal 'IT', biased_result.country_code
assert_equal 'Sicilia', biased_result.state
end
end
def test_language_response
VCR.use_cassette('google_language_response_fr') do
- url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=Hanoi&language=FR"
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=Hanoi&language=FR"
TestHelper.expects(:last_url).with(url)
language_result = Geokit::Geocoders::GoogleGeocoder.geocode('Hanoi', :language => 'FR')
assert_equal 'VN', language_result.country_code
assert_equal 'Hanoï', language_result.city
@@ -223,20 +237,20 @@
end
def test_too_many_queries
response = MockSuccess.new
response.expects(:body).returns %q/{"status": "OVER_QUERY_LIMIT"}/
- url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@address)}"
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape(@address)}"
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
assert_raise Geokit::Geocoders::TooManyQueriesError do
res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
end
end
def test_invalid_request
response = MockSuccess.new
response.expects(:body).returns %q/{"results" : [], "status" : "INVALID_REQUEST"}/
- url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape("3961 V\u00EDa Marisol")}"
+ url = "https://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape("3961 V\u00EDa Marisol")}"
Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
assert_raise Geokit::Geocoders::GeocodeError do
Geokit::Geocoders::GoogleGeocoder.geocode("3961 V\u00EDa Marisol")
end
end