test/test_yahoo_geocoder.rb in rjaswal-geokit-1.5.0.2 vs test/test_yahoo_geocoder.rb in rjaswal-geokit-1.5.1
- old
+ new
@@ -2,19 +2,19 @@
Geokit::Geocoders::yahoo = 'Yahoo'
class YahooGeocoderTest < BaseGeocoderTest #:nodoc: all
YAHOO_FULL=<<-EOF.strip
- <?xml version="1.0"?>
- <ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:maps" xsi:schemaLocation="urn:yahoo:maps http://api.local.yahoo.com/MapsService/V1/GeocodeResponse.xsd"><Result precision="address"><Latitude>37.792406</Latitude><Longitude>-122.39411</Longitude><Address>100 SPEAR ST</Address><City>SAN FRANCISCO</City><State>CA</State><Zip>94105-1522</Zip><Country>US</Country></Result></ResultSet>
- <!-- ws01.search.scd.yahoo.com uncompressed/chunked Mon Jan 29 16:23:43 PST 2007 -->
+ <?xml version="1.0" encoding="UTF-8"?>
+ <ResultSet version="1.0"><Error>0</Error><ErrorMessage>No error</ErrorMessage><Locale>us_US</Locale><Quality>87</Quality><Found>1</Found><Result><quality>87</quality><latitude>37.792418</latitude><longitude>-122.393913</longitude><offsetlat>37.792332</offsetlat><offsetlon>-122.394027</offsetlon><radius>500</radius><name></name><line1>100 Spear St</line1><line2>San Francisco, CA 94105-1578</line2><line3></line3><line4>United States</line4><house>100</house><street>Spear St</street><xstreet></xstreet><unittype></unittype><unit></unit><postal>94105-1578</postal><neighborhood></neighborhood><city>San Francisco</city><county>San Francisco County</county><state>California</state><country>United States</country><countrycode>US</countrycode><statecode>CA</statecode><countycode></countycode><uzip>94105</uzip><hash>0FA06819B5F53E75</hash><woeid>12797156</woeid><woetype>11</woetype></Result></ResultSet>
+ <!-- gws17.maps.sp1.yahoo.com uncompressed/chunked Fri Feb 11 13:41:03 PST 2011 -->
EOF
YAHOO_CITY=<<-EOF.strip
- <?xml version="1.0"?>
- <ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:maps" xsi:schemaLocation="urn:yahoo:maps http://api.local.yahoo.com/MapsService/V1/GeocodeResponse.xsd"><Result precision="city"><Latitude>37.7742</Latitude><Longitude>-122.417068</Longitude><Address></Address><City>SAN FRANCISCO</City><State>CA</State><Zip></Zip><Country>US</Country></Result></ResultSet>
- <!-- ws02.search.scd.yahoo.com uncompressed/chunked Mon Jan 29 18:00:28 PST 2007 -->
+ <?xml version="1.0" encoding="UTF-8"?>
+ <ResultSet version="1.0"><Error>0</Error><ErrorMessage>No error</ErrorMessage><Locale>us_US</Locale><Quality>40</Quality><Found>1</Found><Result><quality>40</quality><latitude>37.777125</latitude><longitude>-122.419644</longitude><offsetlat>37.777125</offsetlat><offsetlon>-122.419644</offsetlon><radius>10700</radius><name></name><line1></line1><line2>San Francisco, CA</line2><line3></line3><line4>United States</line4><house></house><street></street><xstreet></xstreet><unittype></unittype><unit></unit><postal></postal><neighborhood></neighborhood><city>San Francisco</city><county>San Francisco County</county><state>California</state><country>United States</country><countrycode>US</countrycode><statecode>CA</statecode><countycode></countycode><uzip>94102</uzip><hash></hash><woeid>2487956</woeid><woetype>7</woetype></Result></ResultSet>
+ <!-- gws31.maps.sp1.yahoo.com uncompressed/chunked Fri Feb 11 13:38:19 PST 2011 -->
EOF
def setup
super
@yahoo_full_hash = {:street_address=>"100 Spear St", :city=>"San Francisco", :state=>"CA", :zip=>"94105-1522", :country_code=>"US"}
@@ -25,79 +25,97 @@
# the testing methods themselves
def test_yahoo_full_address
response = MockSuccess.new
response.expects(:body).returns(YAHOO_FULL)
- url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@address)}"
+ url = "http://where.yahooapis.com/geocode?appid=Yahoo&count=100&location=#{Geokit::Inflector.url_escape(@address)}"
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
do_full_address_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@address))
end
def test_yahoo_full_address_accuracy
response = MockSuccess.new
response.expects(:body).returns(YAHOO_FULL)
- url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@address)}"
+ url = "http://where.yahooapis.com/geocode?appid=Yahoo&count=100&location=#{Geokit::Inflector.url_escape(@address)}"
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
res = Geokit::Geocoders::YahooGeocoder.geocode(@address)
assert_equal 8, res.accuracy
end
+ def test_yahoo_full_address_precision
+ response = MockSuccess.new
+ response.expects(:body).returns(YAHOO_FULL)
+ url = "http://where.yahooapis.com/geocode?appid=Yahoo&count=100&location=#{Geokit::Inflector.url_escape(@address)}"
+ Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
+ res = Geokit::Geocoders::YahooGeocoder.geocode(@address)
+ assert_equal 'address', res.precision
+ end
+
def test_yahoo_full_address_with_geo_loc
response = MockSuccess.new
response.expects(:body).returns(YAHOO_FULL)
- url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@full_address)}"
+ url = "http://where.yahooapis.com/geocode?appid=Yahoo&count=100&location=#{Geokit::Inflector.url_escape(@full_address)}"
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
do_full_address_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@yahoo_full_loc))
end
def test_yahoo_city
response = MockSuccess.new
response.expects(:body).returns(YAHOO_CITY)
- url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@address)}"
+ url = "http://where.yahooapis.com/geocode?appid=Yahoo&count=100&location=#{Geokit::Inflector.url_escape(@address)}"
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
do_city_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@address))
end
def test_yahoo_city_accuracy
response = MockSuccess.new
response.expects(:body).returns(YAHOO_CITY)
- url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@address)}"
+ url = "http://where.yahooapis.com/geocode?appid=Yahoo&count=100&location=#{Geokit::Inflector.url_escape(@address)}"
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
res = Geokit::Geocoders::YahooGeocoder.geocode(@address)
assert_equal 4, res.accuracy
end
+ def test_yahoo_city_precision
+ response = MockSuccess.new
+ response.expects(:body).returns(YAHOO_CITY)
+ url = "http://where.yahooapis.com/geocode?appid=Yahoo&count=100&location=#{Geokit::Inflector.url_escape(@address)}"
+ Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
+ res = Geokit::Geocoders::YahooGeocoder.geocode(@address)
+ assert_equal 'city', res.precision
+ end
+
def test_yahoo_city_with_geo_loc
response = MockSuccess.new
response.expects(:body).returns(YAHOO_CITY)
- url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@address)}"
+ url = "http://where.yahooapis.com/geocode?appid=Yahoo&count=100&location=#{Geokit::Inflector.url_escape(@address)}"
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
do_city_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@yahoo_city_loc))
end
def test_service_unavailable
response = MockFailure.new
- url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@address)}"
+ url = "http://where.yahooapis.com/geocode?appid=Yahoo&count=100&location=#{Geokit::Inflector.url_escape(@address)}"
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
assert !Geokit::Geocoders::YahooGeocoder.geocode(@yahoo_city_loc).success
end
private
# next two methods do the assertions for both address-level and city-level lookups
def do_full_address_assertions(res)
assert_equal "CA", res.state
assert_equal "San Francisco", res.city
- assert_equal "37.792406,-122.39411", res.ll
+ assert_equal "37.792418,-122.393913", res.ll
assert res.is_us?
- assert_equal "100 Spear St, San Francisco, CA, 94105-1522, US", res.full_address
+ assert_equal "100 Spear St, San Francisco, CA 94105-1578", res.full_address
assert_equal "yahoo", res.provider
end
def do_city_assertions(res)
assert_equal "CA", res.state
assert_equal "San Francisco", res.city
- assert_equal "37.7742,-122.417068", res.ll
+ assert_equal "37.777125,-122.419644", res.ll
assert res.is_us?
assert_equal "San Francisco, CA, US", res.full_address
assert_nil res.street_address
assert_equal "yahoo", res.provider
end
\ No newline at end of file