<s> import base64 <EOL> from datetime import datetime <EOL> from pytz import timezone <EOL> from geopy import exc <EOL> from geopy . compat import u <EOL> from geopy . point import Point <EOL> from geopy . geocoders import GoogleV3 <EOL> from test . geocoders . util import GeocoderTestBase <EOL> class GoogleV3TestCase ( GeocoderTestBase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> cls . geocoder = GoogleV3 ( ) <EOL> cls . new_york_point = Point ( <NUM_LIT> , - <NUM_LIT> ) <EOL> cls . america_new_york = timezone ( "<STR_LIT>" ) <EOL> def test_user_agent_custom ( self ) : <EOL> geocoder = GoogleV3 ( <EOL> user_agent = '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( geocoder . headers [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_configuration_error ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( exc . ConfigurationError ) : <EOL> GoogleV3 ( client_id = '<STR_LIT:a>' ) <EOL> with self . assertRaises ( exc . ConfigurationError ) : <EOL> GoogleV3 ( secret_key = '<STR_LIT:a>' ) <EOL> def test_check_status ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . geocoder . _check_status ( "<STR_LIT>" ) , None ) <EOL> with self . assertRaises ( exc . GeocoderQuotaExceeded ) : <EOL> self . geocoder . _check_status ( "<STR_LIT>" ) <EOL> with self . assertRaises ( exc . GeocoderQueryError ) : <EOL> self . geocoder . _check_status ( "<STR_LIT>" ) <EOL> with self . assertRaises ( exc . GeocoderQueryError ) : <EOL> self . geocoder . _check_status ( "<STR_LIT>" ) <EOL> with self . assertRaises ( exc . GeocoderQueryError ) : <EOL> self . geocoder . _check_status ( "<STR_LIT:_>" ) <EOL> def test_get_signed_url ( self ) : <EOL> """<STR_LIT>""" <EOL> geocoder = GoogleV3 ( <EOL> client_id = '<STR_LIT>' , <EOL> secret_key = base64 . urlsafe_b64encode ( '<STR_LIT>' . encode ( '<STR_LIT:utf8>' ) ) <EOL> ) <EOL> self . assertTrue ( geocoder . premier ) <EOL> self . assertTrue ( <EOL> geocoder . _get_signed_url ( <EOL> { '<STR_LIT:address>' : '<STR_LIT>' } <EOL> ) in ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> ) <EOL> def test_format_components_param ( self ) : <EOL> """<STR_LIT>""" <EOL> f = GoogleV3 . _format_components_param <EOL> self . assertEqual ( f ( { } ) , '<STR_LIT>' ) <EOL> self . assertEqual ( f ( { '<STR_LIT>' : '<STR_LIT>' } ) , '<STR_LIT>' ) <EOL> output = f ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertTrue ( <EOL> output in ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) , output <EOL> ) <EOL> with self . assertRaises ( AttributeError ) : <EOL> f ( None ) <EOL> with self . assertRaises ( AttributeError ) : <EOL> f ( [ ] ) <EOL> with self . assertRaises ( AttributeError ) : <EOL> f ( '<STR_LIT>' ) <EOL> def test_geocode ( self ) : <EOL> """<STR_LIT>""" <EOL> self . geocode_run ( <EOL> { "<STR_LIT>" : "<STR_LIT>" } , <EOL> { "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : - <NUM_LIT> } , <EOL> ) <EOL> def test_unicode_name ( self ) : <EOL> """<STR_LIT>""" <EOL> self . geocode_run ( <EOL> { "<STR_LIT>" : u ( "<STR_LIT>" ) } , <EOL> { "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> } , <EOL> ) <EOL> def test_geocode_components ( self ) : <EOL> """<STR_LIT>""" <EOL> self . geocode_run ( <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } , <EOL> { } , <EOL> expect_failure = True <EOL> ) <EOL> def test_components ( self ) : <EOL> """<STR_LIT>""" <EOL> self . geocode_run ( <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } , <EOL> { "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : - <NUM_LIT> } , <EOL> ) <EOL> def test_reverse_string ( self ) : <EOL> """<STR_LIT>""" <EOL> self . reverse_run ( <EOL> { "<STR_LIT>" : "<STR_LIT>" } , <EOL> { "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : - <NUM_LIT> } , <EOL> ) <EOL> def test_reverse_point ( self ) : <EOL> """<STR_LIT>""" <EOL> self . reverse_run ( <EOL> { "<STR_LIT>" : self . new_york_point } , <EOL> { "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : - <NUM_LIT> } , <EOL> ) <EOL> def test_zero_results ( self ) : <EOL> """<STR_LIT>""" <EOL> result = self . _make_request ( self . geocoder . geocode , '<STR_LIT>' ) <EOL> self . assertIsNone ( result ) <EOL> def test_timezone_datetime ( self ) : <EOL> """<STR_LIT>""" <EOL> tz = self . _make_request ( <EOL> self . geocoder . timezone , <EOL> self . new_york_point , <EOL> datetime . utcfromtimestamp ( <NUM_LIT:0> ) <EOL> ) <EOL> self . assertEqual ( tz , self . america_new_york ) <EOL> def test_timezone_integer ( self ) : <EOL> """<STR_LIT>""" <EOL> tz = self . _make_request ( <EOL> self . geocoder . timezone , <EOL> self . new_york_point , <EOL> <NUM_LIT:0> <EOL> ) <EOL> self . assertEqual ( tz , self . america_new_york ) <EOL> def test_timezone_no_date ( self ) : <EOL> """<STR_LIT>""" <EOL> tz = self . _make_request ( <EOL> self . geocoder . timezone , <EOL> self . new_york_point , <EOL> ) <EOL> self . assertEqual ( tz , self . america_new_york ) <EOL> def test_timezone_invalid_at_time ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( exc . GeocoderQueryError ) : <EOL> self . geocoder . timezone ( self . new_york_point , "<STR_LIT>" ) <EOL> def test_geocode_bounds ( self ) : <EOL> """<STR_LIT>""" <EOL> self . geocode_run ( <EOL> { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : [ <NUM_LIT:50> , - <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:2> ] } , <EOL> { "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : - <NUM_LIT> } , <EOL> ) <EOL> def test_geocode_bounds_invalid ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( exc . GeocoderQueryError ) : <EOL> self . geocode_run ( <EOL> { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : [ <NUM_LIT:50> , - <NUM_LIT:2> , <NUM_LIT> ] } , <EOL> { "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : - <NUM_LIT> } , <EOL> ) </s>
