<s> import unittest2 <EOL> class Test_GCloudError ( unittest2 . TestCase ) : <EOL> def _getTargetClass ( self ) : <EOL> from gcloud . exceptions import GCloudError <EOL> return GCloudError <EOL> def _makeOne ( self , message , errors = ( ) ) : <EOL> return self . _getTargetClass ( ) ( message , errors = errors ) <EOL> def test_ctor_defaults ( self ) : <EOL> e = self . _makeOne ( '<STR_LIT>' ) <EOL> e . code = <NUM_LIT> <EOL> self . assertEqual ( str ( e ) , '<STR_LIT>' ) <EOL> self . assertEqual ( e . message , '<STR_LIT>' ) <EOL> self . assertEqual ( list ( e . errors ) , [ ] ) <EOL> def test_ctor_explicit ( self ) : <EOL> ERROR = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:location>' : '<STR_LIT:test>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:message>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:test>' , <EOL> } <EOL> e = self . _makeOne ( '<STR_LIT>' , [ ERROR ] ) <EOL> e . code = <NUM_LIT> <EOL> self . assertEqual ( str ( e ) , '<STR_LIT>' ) <EOL> self . assertEqual ( e . message , '<STR_LIT>' ) <EOL> self . assertEqual ( list ( e . errors ) , [ ERROR ] ) <EOL> class Test_make_exception ( unittest2 . TestCase ) : <EOL> def _callFUT ( self , response , content , error_info = None , use_json = True ) : <EOL> from gcloud . exceptions import make_exception <EOL> return make_exception ( response , content , error_info = error_info , <EOL> use_json = use_json ) <EOL> def test_hit_w_content_as_str ( self ) : <EOL> from gcloud . exceptions import NotFound <EOL> response = _Response ( <NUM_LIT> ) <EOL> content = b'<STR_LIT>' <EOL> exception = self . _callFUT ( response , content ) <EOL> self . assertTrue ( isinstance ( exception , NotFound ) ) <EOL> self . assertEqual ( exception . message , '<STR_LIT>' ) <EOL> self . assertEqual ( list ( exception . errors ) , [ ] ) <EOL> def test_miss_w_content_as_dict ( self ) : <EOL> from gcloud . exceptions import GCloudError <EOL> ERROR = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:location>' : '<STR_LIT:test>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:message>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:test>' , <EOL> } <EOL> response = _Response ( <NUM_LIT> ) <EOL> content = { "<STR_LIT:error>" : { "<STR_LIT:message>" : "<STR_LIT>" , "<STR_LIT>" : [ ERROR ] } } <EOL> exception = self . _callFUT ( response , content ) <EOL> self . assertTrue ( isinstance ( exception , GCloudError ) ) <EOL> self . assertEqual ( exception . message , '<STR_LIT>' ) <EOL> self . assertEqual ( list ( exception . errors ) , [ ERROR ] ) <EOL> def test_html_when_json_expected ( self ) : <EOL> from gcloud . exceptions import NotFound <EOL> response = _Response ( NotFound . code ) <EOL> content = '<STR_LIT>' <EOL> exception = self . _callFUT ( response , content , use_json = True ) <EOL> self . assertTrue ( isinstance ( exception , NotFound ) ) <EOL> self . assertEqual ( exception . message , content ) <EOL> self . assertEqual ( list ( exception . errors ) , [ ] ) <EOL> class _Response ( object ) : <EOL> def __init__ ( self , status ) : <EOL> self . status = status </s>
