<s> from datetime import date <EOL> from mock import patch , Mock <EOL> from nose . tools import assert_true <EOL> from twilio . rest . resources import Calls , Call <EOL> from tests . tools import create_mock_json <EOL> BASE_URI = "<STR_LIT>" <EOL> ACCOUNT_SID = "<STR_LIT>" <EOL> AUTH = ( ACCOUNT_SID , "<STR_LIT>" ) <EOL> CALL_SID = "<STR_LIT>" <EOL> list_resource = Calls ( BASE_URI , AUTH ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_create_call ( mock ) : <EOL> resp = create_mock_json ( "<STR_LIT>" ) <EOL> resp . status_code = <NUM_LIT> <EOL> mock . return_value = resp <EOL> uri = "<STR_LIT>" % ( BASE_URI ) <EOL> list_resource . create ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:url>" , record = True , application_sid = '<STR_LIT>' ) <EOL> exp_params = { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT:url>" , <EOL> '<STR_LIT>' : "<STR_LIT:true>" , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> mock . assert_called_with ( "<STR_LIT:POST>" , uri , data = exp_params , auth = AUTH , <EOL> use_json_extension = True ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_create_call_status_events ( mock ) : <EOL> resp = create_mock_json ( "<STR_LIT>" ) <EOL> resp . status_code = <NUM_LIT> <EOL> mock . return_value = resp <EOL> uri = "<STR_LIT>" % ( BASE_URI ) <EOL> list_resource . create ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:url>" , <EOL> status_callback = "<STR_LIT>" , <EOL> status_events = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> exp_params = { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT:url>" , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> mock . assert_called_with ( "<STR_LIT:POST>" , uri , data = exp_params , auth = AUTH , <EOL> use_json_extension = True ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_create_call_status_events_none ( mock ) : <EOL> resp = create_mock_json ( "<STR_LIT>" ) <EOL> resp . status_code = <NUM_LIT> <EOL> mock . return_value = resp <EOL> uri = "<STR_LIT>" % ( BASE_URI ) <EOL> list_resource . create ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:url>" , <EOL> status_callback = "<STR_LIT>" ) <EOL> exp_params = { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT:url>" , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> mock . assert_called_with ( "<STR_LIT:POST>" , uri , data = exp_params , auth = AUTH , <EOL> use_json_extension = True ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_paging ( mock ) : <EOL> resp = create_mock_json ( "<STR_LIT>" ) <EOL> mock . return_value = resp <EOL> uri = "<STR_LIT>" % ( BASE_URI ) <EOL> list_resource . list ( started_before = date ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:5> ) ) <EOL> exp_params = { '<STR_LIT>' : '<STR_LIT>' } <EOL> mock . assert_called_with ( "<STR_LIT:GET>" , uri , params = exp_params , auth = AUTH , <EOL> use_json_extension = True ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_paging_iter ( mock ) : <EOL> resp = create_mock_json ( "<STR_LIT>" ) <EOL> mock . return_value = resp <EOL> uri = "<STR_LIT>" % ( BASE_URI ) <EOL> next ( list_resource . iter ( started_before = date ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:5> ) ) ) <EOL> exp_params = { '<STR_LIT>' : '<STR_LIT>' } <EOL> mock . assert_called_with ( "<STR_LIT:GET>" , uri , params = exp_params , auth = AUTH , <EOL> use_json_extension = True ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_get ( mock ) : <EOL> resp = create_mock_json ( "<STR_LIT>" ) <EOL> mock . return_value = resp <EOL> uri = "<STR_LIT>" % ( BASE_URI , CALL_SID ) <EOL> list_resource . get ( CALL_SID ) <EOL> mock . assert_called_with ( "<STR_LIT:GET>" , uri , auth = AUTH , <EOL> use_json_extension = True ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_hangup ( mock ) : <EOL> resp = create_mock_json ( "<STR_LIT>" ) <EOL> resp . status_code = <NUM_LIT> <EOL> mock . return_value = resp <EOL> uri = "<STR_LIT>" % ( BASE_URI , CALL_SID ) <EOL> r = list_resource . hangup ( CALL_SID ) <EOL> exp_data = { "<STR_LIT>" : "<STR_LIT>" } <EOL> mock . assert_called_with ( "<STR_LIT:POST>" , uri , data = exp_data , auth = AUTH , <EOL> use_json_extension = True ) <EOL> assert_true ( r ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_cancel ( mock ) : <EOL> resp = create_mock_json ( "<STR_LIT>" ) <EOL> resp . status_code = <NUM_LIT> <EOL> mock . return_value = resp <EOL> uri = "<STR_LIT>" % ( BASE_URI , CALL_SID ) <EOL> r = list_resource . cancel ( CALL_SID ) <EOL> exp_data = { "<STR_LIT>" : "<STR_LIT>" } <EOL> mock . assert_called_with ( "<STR_LIT:POST>" , uri , data = exp_data , auth = AUTH , <EOL> use_json_extension = True ) <EOL> assert_true ( r ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_delete ( req ) : <EOL> """<STR_LIT>""" <EOL> resp = Mock ( ) <EOL> resp . content = "<STR_LIT>" <EOL> resp . status_code = <NUM_LIT> <EOL> req . return_value = resp , { } <EOL> app = Call ( list_resource , "<STR_LIT>" ) <EOL> app . delete ( ) <EOL> uri = "<STR_LIT>" <EOL> req . assert_called_with ( "<STR_LIT>" , uri ) </s>
