<s> import requests <EOL> from climateclient import base <EOL> from climateclient import exception <EOL> from climateclient import tests <EOL> class BaseClientManagerTestCase ( tests . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( BaseClientManagerTestCase , self ) . setUp ( ) <EOL> self . url = "<STR_LIT>" <EOL> self . token = "<STR_LIT>" <EOL> self . fake_key = "<STR_LIT>" <EOL> self . response = "<STR_LIT>" <EOL> self . exception = exception <EOL> self . manager = base . BaseClientManager ( self . url , self . token ) <EOL> self . request = self . patch ( requests , "<STR_LIT>" ) <EOL> def test_get ( self ) : <EOL> self . patch ( <EOL> self . manager , "<STR_LIT>" ) . return_value = ( <EOL> self . response , { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . assertEqual ( self . manager . _get ( self . url , self . fake_key ) , "<STR_LIT>" ) <EOL> def test_create ( self ) : <EOL> self . patch ( <EOL> self . manager , "<STR_LIT>" ) . return_value = ( <EOL> self . response , { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . assertEqual ( self . manager . _create ( self . url , { } , self . fake_key ) , <EOL> "<STR_LIT>" ) <EOL> def test_delete ( self ) : <EOL> request = self . patch ( self . manager , "<STR_LIT>" ) <EOL> request . return_value = ( self . response , { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . manager . _delete ( self . url ) <EOL> request . assert_called_once_with ( self . url , "<STR_LIT>" ) <EOL> def test_update ( self ) : <EOL> self . patch ( <EOL> self . manager , "<STR_LIT>" ) . return_value = ( <EOL> self . response , { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . assertEqual ( self . manager . _update ( self . url , { } , self . fake_key ) , <EOL> "<STR_LIT>" ) <EOL> def test_request_ok_with_body ( self ) : <EOL> self . request . return_value . status_code = <NUM_LIT:200> <EOL> self . request . return_value . text = '<STR_LIT>' <EOL> kwargs = { "<STR_LIT:body>" : { "<STR_LIT:key>" : "<STR_LIT:value>" } } <EOL> self . assertEqual ( ( <EOL> self . request ( ) , { "<STR_LIT:key>" : "<STR_LIT:value>" } ) , <EOL> self . manager . request ( self . url , "<STR_LIT:POST>" , ** kwargs ) ) <EOL> def test_request_ok_without_body ( self ) : <EOL> self . request . return_value . status_code = <NUM_LIT:200> <EOL> self . request . return_value . text = "<STR_LIT:key>" <EOL> kwargs = { "<STR_LIT:body>" : "<STR_LIT:key>" } <EOL> self . assertEqual ( ( <EOL> self . request ( ) , None ) , <EOL> self . manager . request ( self . url , "<STR_LIT:POST>" , ** kwargs ) ) <EOL> def test_request_fail_with_body ( self ) : <EOL> self . request . return_value . status_code = <NUM_LIT> <EOL> self . request . return_value . text = '<STR_LIT>' <EOL> kwargs = { "<STR_LIT:body>" : { "<STR_LIT:key>" : "<STR_LIT:value>" } } <EOL> self . assertRaises ( exception . ClimateClientException , <EOL> self . manager . request , <EOL> self . url , "<STR_LIT:POST>" , ** kwargs ) <EOL> def test_request_fail_without_body ( self ) : <EOL> self . request . return_value . status_code = <NUM_LIT> <EOL> self . request . return_value . text = "<STR_LIT>" <EOL> kwargs = { "<STR_LIT:body>" : "<STR_LIT:key>" } <EOL> self . assertRaises ( exception . ClimateClientException , <EOL> self . manager . request , <EOL> self . url , "<STR_LIT:POST>" , ** kwargs ) </s>
