<s> import json <EOL> import unittest <EOL> from tests import DictPartialMatcher <EOL> from uber import UberClient , GPSLocation , UberException , Place , VehicleView , SimpleLocation , UberLocationNotFound , PaymentProfile <EOL> from flexmock import flexmock <EOL> import uber . client <EOL> from uber import settings <EOL> from tests import mocked_response <EOL> from uber import geolocation <EOL> class TestUberClient ( unittest . TestCase ) : <EOL> mock_location = GPSLocation ( <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> def setUp ( self ) : <EOL> self . _client = UberClient ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_post ( self ) : <EOL> data = { '<STR_LIT:a>' : '<STR_LIT:b>' } <EOL> ( flexmock ( self . _client . _session ) <EOL> . should_receive ( '<STR_LIT>' ) <EOL> . with_args ( '<STR_LIT>' , json . dumps ( data ) , headers = self . _client . _headers ) <EOL> . and_return ( mocked_response ( { '<STR_LIT>' : '<STR_LIT>' } ) ) <EOL> . times ( <NUM_LIT:1> ) <EOL> ) <EOL> self . assertEqual ( self . _client . _post ( '<STR_LIT>' , data = data ) . json ( ) , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_message_error_handling ( self ) : <EOL> error_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } <EOL> ( flexmock ( self . _client . _session ) <EOL> . should_receive ( '<STR_LIT>' ) <EOL> . and_return ( mocked_response ( error_data ) ) <EOL> . times ( <NUM_LIT:1> ) <EOL> ) <EOL> with self . assertRaises ( UberException ) as expected_exception : <EOL> self . _client . _send_message ( '<STR_LIT>' ) <EOL> self . assertEqual ( expected_exception . exception . description , '<STR_LIT>' ) <EOL> self . assertEqual ( expected_exception . exception . error_code , <NUM_LIT> ) <EOL> def test_http_error_handling ( self ) : <EOL> ( flexmock ( self . _client . _session ) <EOL> . should_receive ( '<STR_LIT>' ) <EOL> . and_return ( mocked_response ( '<STR_LIT>' , <NUM_LIT> ) ) <EOL> . times ( <NUM_LIT:1> ) <EOL> ) <EOL> with self . assertRaises ( UberException ) as expected_exception : <EOL> self . _client . _post ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( expected_exception . exception . error_code , <NUM_LIT> ) <EOL> self . assertEqual ( expected_exception . exception . description , '<STR_LIT>' ) <EOL> def test_send_message ( self ) : <EOL> client = UberClient ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> response = mocked_response ( '<STR_LIT>' ) <EOL> expected_data = { <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : settings . DEVICE_OS , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : settings . DEVICE_MODEL , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:version>' : settings . UBER_VERSION , <EOL> '<STR_LIT>' : settings . DEVICE_NAME , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> ( flexmock ( UberClient ) <EOL> . should_receive ( '<STR_LIT>' ) <EOL> . with_args ( self . mock_location , dict ) <EOL> . times ( <NUM_LIT:1> ) <EOL> ) <EOL> ( flexmock ( UberClient ) <EOL> . should_receive ( '<STR_LIT>' ) <EOL> . with_args ( UberClient . ENDPOINT , data = DictPartialMatcher ( expected_data ) ) <EOL> . times ( <NUM_LIT:1> ) <EOL> . and_return ( response ) ) <EOL> ( flexmock ( UberClient ) <EOL> . should_receive ( '<STR_LIT>' ) <EOL> . with_args ( response . json ( ) ) <EOL> . times ( <NUM_LIT:1> ) <EOL> ) <EOL> params = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> self . assertEqual ( '<STR_LIT>' , client . _send_message ( '<STR_LIT>' , params , self . mock_location ) ) <EOL> def test_login ( self ) : <EOL> ( flexmock ( uber . client ) <EOL> . should_receive ( '<STR_LIT>' ) <EOL> . and_return ( '<STR_LIT>' ) <EOL> ) <EOL> ( flexmock ( UberClient ) <EOL> . should_receive ( '<STR_LIT>' ) <EOL> . with_args ( '<STR_LIT>' , params = { '<STR_LIT:password>' : '<STR_LIT>' , '<STR_LIT:email>' : '<STR_LIT>' } ) <EOL> . and_return ( { <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } <EOL> } ) <EOL> ) <EOL> token = UberClient . login ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( token , '<STR_LIT>' ) <EOL> def test_hash_password ( self ) : <EOL> from uber . client import hash_password <EOL> self . assertEqual ( hash_password ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_nearby_places ( self ) : <EOL> params = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> expected_places = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] <EOL> ( flexmock ( self . _client ) <EOL> . should_receive ( '<STR_LIT>' ) <EOL> . with_args ( '<STR_LIT>' , params = params , location = '<STR_LIT>' ) <EOL> . and_return ( { '<STR_LIT>' : expected_places } ) <EOL> ) <EOL> result = self . _client . nearby_places ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( [ x . raw for x in result ] , expected_places ) <EOL> for item in result : <EOL> self . assertEqual ( type ( item ) , Place ) <EOL> def test_copy_location_for_message ( self ) : <EOL> data = { } <EOL> self . _client . _copy_location_for_message ( { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:0.5> } , data ) <EOL> self . assertEqual ( data , { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:0.5> } ) <EOL> data = { } <EOL> self . _client . _copy_location_for_message ( GPSLocation ( latitude = <NUM_LIT:0.5> , longitude = <NUM_LIT:1> ) , data ) <EOL> self . assertEqual ( data , { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:0.5> } ) <EOL> data = { } <EOL> self . _client . _copy_location_for_message ( GPSLocation ( <EOL> latitude = <NUM_LIT:0.5> , <EOL> longitude = <NUM_LIT:1> , <EOL> vertical_accuracy = <NUM_LIT:0.1> , <EOL> horizontal_accuracy = <NUM_LIT> , <EOL> altitude = <NUM_LIT> ) , data ) <EOL> self . assertEqual ( data , { <EOL> '<STR_LIT>' : <NUM_LIT:0.5> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:0.1> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } ) <EOL> def test_request_pickup ( self ) : <EOL> ( flexmock ( UberClient ) <EOL> . should_receive ( '<STR_LIT>' ) <EOL> . with_args ( '<STR_LIT>' , <EOL> params = { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : True , '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } , <EOL> location = self . mock_location ) <EOL> ) <EOL> self . _client . request_pickup ( <EOL> vehicle_type = VehicleView ( { '<STR_LIT:id>' : <NUM_LIT:1> } ) , <EOL> pickup_address = { '<STR_LIT>' : '<STR_LIT>' } , <EOL> gps_location = self . mock_location ) <EOL> def test_request_pickup_with_string_address ( self ) : <EOL> ( flexmock ( geolocation ) <EOL> . should_receive ( '<STR_LIT>' ) <EOL> . with_args ( '<STR_LIT>' ) <EOL> . and_return ( [ { '<STR_LIT>' : '<STR_LIT>' } ] ) <EOL> ) <EOL> ( flexmock ( UberClient ) <EOL> . should_receive ( '<STR_LIT>' ) <EOL> . with_args ( '<STR_LIT>' , <EOL> params = { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : True , '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } , <EOL> location = self . mock_location ) <EOL> ) <EOL> self . _client . request_pickup ( <EOL> vehicle_type = VehicleView ( { '<STR_LIT:id>' : <NUM_LIT:1> } ) , <EOL> pickup_address = '<STR_LIT>' , <EOL> gps_location = self . mock_location ) <EOL> def test_request_pickup_with_bad_string_address ( self ) : <EOL> ( flexmock ( geolocation ) <EOL> . should_receive ( '<STR_LIT>' ) <EOL> . with_args ( '<STR_LIT>' ) <EOL> . and_return ( [ ] ) <EOL> ) <EOL> with self . assertRaises ( UberLocationNotFound ) : <EOL> self . _client . request_pickup ( <EOL> vehicle_type = VehicleView ( { '<STR_LIT:id>' : <NUM_LIT:1> } ) , <EOL> pickup_address = '<STR_LIT>' , <EOL> gps_location = self . mock_location ) <EOL> def test_request_pickup_int_args ( self ) : <EOL> ( flexmock ( geolocation ) <EOL> . should_receive ( '<STR_LIT>' ) <EOL> . with_args ( '<STR_LIT>' ) <EOL> . and_return ( [ { '<STR_LIT>' : '<STR_LIT>' } ] ) <EOL> ) <EOL> ( flexmock ( UberClient ) <EOL> . should_receive ( '<STR_LIT>' ) <EOL> . with_args ( '<STR_LIT>' , <EOL> params = { '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } <EOL> } , <EOL> location = self . mock_location ) <EOL> ) <EOL> self . _client . request_pickup ( <EOL> vehicle_type = <NUM_LIT> , <EOL> pickup_address = '<STR_LIT>' , <EOL> payment_profile = <NUM_LIT> , <EOL> gps_location = self . mock_location ) <EOL> def test_request_pickup_model_args ( self ) : <EOL> ( flexmock ( geolocation ) <EOL> . should_receive ( '<STR_LIT>' ) <EOL> . with_args ( '<STR_LIT>' ) <EOL> . and_return ( [ { '<STR_LIT>' : '<STR_LIT>' } ] ) <EOL> ) <EOL> ( flexmock ( UberClient ) <EOL> . should_receive ( '<STR_LIT>' ) <EOL> . with_args ( '<STR_LIT>' , <EOL> params = { '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } <EOL> } , <EOL> location = self . mock_location ) <EOL> ) <EOL> self . _client . request_pickup ( <EOL> vehicle_type = VehicleView ( { '<STR_LIT:id>' : <NUM_LIT> } ) , <EOL> pickup_address = '<STR_LIT>' , <EOL> payment_profile = PaymentProfile ( { '<STR_LIT:id>' : <NUM_LIT> } ) , <EOL> gps_location = self . mock_location ) <EOL> def test_ping ( self ) : <EOL> ( flexmock ( UberClient ) <EOL> . should_receive ( '<STR_LIT>' ) <EOL> . with_args ( '<STR_LIT>' , <EOL> location = self . mock_location ) <EOL> ) <EOL> self . _client . ping ( self . mock_location ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
