<s> import unittest2 <EOL> class TestProject ( unittest2 . TestCase ) : <EOL> def _getTargetClass ( self ) : <EOL> from gcloud . resource_manager . project import Project <EOL> return Project <EOL> def _makeOne ( self , * args , ** kw ) : <EOL> return self . _getTargetClass ( ) ( * args , ** kw ) <EOL> def test_constructor_defaults ( self ) : <EOL> client = object ( ) <EOL> PROJECT_ID = '<STR_LIT>' <EOL> project = self . _makeOne ( PROJECT_ID , client ) <EOL> self . assertEqual ( project . project_id , PROJECT_ID ) <EOL> self . assertEqual ( project . _client , client ) <EOL> self . assertEqual ( project . name , None ) <EOL> self . assertEqual ( project . number , None ) <EOL> self . assertEqual ( project . labels , { } ) <EOL> self . assertEqual ( project . status , None ) <EOL> def test_constructor_explicit ( self ) : <EOL> client = object ( ) <EOL> PROJECT_ID = '<STR_LIT>' <EOL> DISPLAY_NAME = '<STR_LIT:name>' <EOL> LABELS = { '<STR_LIT:foo>' : '<STR_LIT:bar>' } <EOL> project = self . _makeOne ( PROJECT_ID , client , <EOL> name = DISPLAY_NAME , labels = LABELS ) <EOL> self . assertEqual ( project . project_id , PROJECT_ID ) <EOL> self . assertEqual ( project . _client , client ) <EOL> self . assertEqual ( project . name , DISPLAY_NAME ) <EOL> self . assertEqual ( project . number , None ) <EOL> self . assertEqual ( project . labels , LABELS ) <EOL> self . assertEqual ( project . status , None ) <EOL> def test_from_api_repr ( self ) : <EOL> client = object ( ) <EOL> PROJECT_ID = '<STR_LIT>' <EOL> PROJECT_NAME = '<STR_LIT>' <EOL> PROJECT_NUMBER = <NUM_LIT> <EOL> PROJECT_LABELS = { '<STR_LIT>' : '<STR_LIT>' } <EOL> PROJECT_LIFECYCLE_STATE = '<STR_LIT>' <EOL> resource = { '<STR_LIT>' : PROJECT_ID , <EOL> '<STR_LIT:name>' : PROJECT_NAME , <EOL> '<STR_LIT>' : PROJECT_NUMBER , <EOL> '<STR_LIT>' : PROJECT_LABELS , <EOL> '<STR_LIT>' : PROJECT_LIFECYCLE_STATE } <EOL> project = self . _getTargetClass ( ) . from_api_repr ( resource , client ) <EOL> self . assertEqual ( project . project_id , PROJECT_ID ) <EOL> self . assertEqual ( project . _client , client ) <EOL> self . assertEqual ( project . name , PROJECT_NAME ) <EOL> self . assertEqual ( project . number , PROJECT_NUMBER ) <EOL> self . assertEqual ( project . labels , PROJECT_LABELS ) <EOL> self . assertEqual ( project . status , PROJECT_LIFECYCLE_STATE ) <EOL> def test_full_name ( self ) : <EOL> PROJECT_ID = '<STR_LIT>' <EOL> project = self . _makeOne ( PROJECT_ID , None ) <EOL> self . assertEqual ( '<STR_LIT>' % PROJECT_ID , project . full_name ) <EOL> def test_full_name_missing_id ( self ) : <EOL> project = self . _makeOne ( None , None ) <EOL> with self . assertRaises ( ValueError ) : <EOL> self . assertIsNone ( project . full_name ) <EOL> def test_path ( self ) : <EOL> PROJECT_ID = '<STR_LIT>' <EOL> project = self . _makeOne ( PROJECT_ID , None ) <EOL> self . assertEqual ( '<STR_LIT>' % PROJECT_ID , project . path ) <EOL> def test_create ( self ) : <EOL> PROJECT_ID = '<STR_LIT>' <EOL> PROJECT_NUMBER = <NUM_LIT> <EOL> PROJECT_RESOURCE = { <EOL> '<STR_LIT>' : PROJECT_ID , <EOL> '<STR_LIT>' : PROJECT_NUMBER , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> connection = _Connection ( PROJECT_RESOURCE ) <EOL> client = _Client ( connection = connection ) <EOL> project = self . _makeOne ( PROJECT_ID , client ) <EOL> self . assertEqual ( project . number , None ) <EOL> project . create ( ) <EOL> self . assertEqual ( project . number , PROJECT_NUMBER ) <EOL> request , = connection . _requested <EOL> expected_request = { <EOL> '<STR_LIT>' : '<STR_LIT:POST>' , <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT>' : PROJECT_ID , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:name>' : None , <EOL> } , <EOL> '<STR_LIT:path>' : '<STR_LIT>' , <EOL> } <EOL> self . assertEqual ( request , expected_request ) <EOL> def test_reload ( self ) : <EOL> PROJECT_ID = '<STR_LIT>' <EOL> PROJECT_NUMBER = <NUM_LIT> <EOL> PROJECT_RESOURCE = { <EOL> '<STR_LIT>' : PROJECT_ID , <EOL> '<STR_LIT>' : PROJECT_NUMBER , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> connection = _Connection ( PROJECT_RESOURCE ) <EOL> client = _Client ( connection = connection ) <EOL> project = self . _makeOne ( PROJECT_ID , client ) <EOL> self . assertEqual ( project . number , None ) <EOL> self . assertEqual ( project . name , None ) <EOL> self . assertEqual ( project . labels , { } ) <EOL> self . assertEqual ( project . status , None ) <EOL> project . reload ( ) <EOL> self . assertEqual ( project . name , PROJECT_RESOURCE [ '<STR_LIT:name>' ] ) <EOL> self . assertEqual ( project . number , PROJECT_NUMBER ) <EOL> self . assertEqual ( project . labels , PROJECT_RESOURCE [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( project . status , PROJECT_RESOURCE [ '<STR_LIT>' ] ) <EOL> request , = connection . _requested <EOL> expected_request = { <EOL> '<STR_LIT>' : '<STR_LIT:GET>' , <EOL> '<STR_LIT:path>' : project . path , <EOL> } <EOL> self . assertEqual ( request , expected_request ) <EOL> def test_exists ( self ) : <EOL> PROJECT_ID = '<STR_LIT>' <EOL> connection = _Connection ( { '<STR_LIT>' : PROJECT_ID } ) <EOL> client = _Client ( connection = connection ) <EOL> project = self . _makeOne ( PROJECT_ID , client ) <EOL> self . assertTrue ( project . exists ( ) ) <EOL> def test_exists_with_explicitly_passed_client ( self ) : <EOL> PROJECT_ID = '<STR_LIT>' <EOL> connection = _Connection ( { '<STR_LIT>' : PROJECT_ID } ) <EOL> client = _Client ( connection = connection ) <EOL> project = self . _makeOne ( PROJECT_ID , None ) <EOL> self . assertTrue ( project . exists ( client = client ) ) <EOL> def test_exists_with_missing_client ( self ) : <EOL> PROJECT_ID = '<STR_LIT>' <EOL> project = self . _makeOne ( PROJECT_ID , None ) <EOL> with self . assertRaises ( AttributeError ) : <EOL> project . exists ( ) <EOL> def test_exists_not_found ( self ) : <EOL> PROJECT_ID = '<STR_LIT>' <EOL> connection = _Connection ( ) <EOL> client = _Client ( connection = connection ) <EOL> project = self . _makeOne ( PROJECT_ID , client ) <EOL> self . assertFalse ( project . exists ( ) ) <EOL> def test_update ( self ) : <EOL> PROJECT_ID = '<STR_LIT>' <EOL> PROJECT_NUMBER = <NUM_LIT> <EOL> PROJECT_NAME = '<STR_LIT>' <EOL> LABELS = { '<STR_LIT>' : '<STR_LIT>' } <EOL> PROJECT_RESOURCE = { <EOL> '<STR_LIT>' : PROJECT_ID , <EOL> '<STR_LIT>' : PROJECT_NUMBER , <EOL> '<STR_LIT:name>' : PROJECT_NAME , <EOL> '<STR_LIT>' : LABELS , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> connection = _Connection ( PROJECT_RESOURCE ) <EOL> client = _Client ( connection = connection ) <EOL> project = self . _makeOne ( PROJECT_ID , client ) <EOL> project . name = PROJECT_NAME <EOL> project . labels = LABELS <EOL> project . update ( ) <EOL> request , = connection . _requested <EOL> expected_request = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:data>' : { <EOL> '<STR_LIT:name>' : PROJECT_NAME , <EOL> '<STR_LIT>' : LABELS , <EOL> } , <EOL> '<STR_LIT:path>' : project . path , <EOL> } <EOL> self . assertEqual ( request , expected_request ) <EOL> def test_delete_without_reload_data ( self ) : <EOL> PROJECT_ID = '<STR_LIT>' <EOL> PROJECT_NUMBER = <NUM_LIT> <EOL> PROJECT_RESOURCE = { <EOL> '<STR_LIT>' : PROJECT_ID , <EOL> '<STR_LIT>' : PROJECT_NUMBER , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> connection = _Connection ( PROJECT_RESOURCE ) <EOL> client = _Client ( connection = connection ) <EOL> project = self . _makeOne ( PROJECT_ID , client ) <EOL> project . delete ( reload_data = False ) <EOL> request , = connection . _requested <EOL> expected_request = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:path>' : project . path , <EOL> } <EOL> self . assertEqual ( request , expected_request ) <EOL> def test_delete_with_reload_data ( self ) : <EOL> PROJECT_ID = '<STR_LIT>' <EOL> PROJECT_NUMBER = <NUM_LIT> <EOL> PROJECT_RESOURCE = { <EOL> '<STR_LIT>' : PROJECT_ID , <EOL> '<STR_LIT>' : PROJECT_NUMBER , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> DELETING_PROJECT = PROJECT_RESOURCE . copy ( ) <EOL> DELETING_PROJECT [ '<STR_LIT>' ] = NEW_STATE = '<STR_LIT>' <EOL> connection = _Connection ( PROJECT_RESOURCE , DELETING_PROJECT ) <EOL> client = _Client ( connection = connection ) <EOL> project = self . _makeOne ( PROJECT_ID , client ) <EOL> project . delete ( reload_data = True ) <EOL> self . assertEqual ( project . status , NEW_STATE ) <EOL> delete_request , get_request = connection . _requested <EOL> expected_delete_request = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:path>' : project . path , <EOL> } <EOL> self . assertEqual ( delete_request , expected_delete_request ) <EOL> expected_get_request = { <EOL> '<STR_LIT>' : '<STR_LIT:GET>' , <EOL> '<STR_LIT:path>' : project . path , <EOL> } <EOL> self . assertEqual ( get_request , expected_get_request ) <EOL> def test_undelete_without_reload_data ( self ) : <EOL> PROJECT_ID = '<STR_LIT>' <EOL> PROJECT_NUMBER = <NUM_LIT> <EOL> PROJECT_RESOURCE = { <EOL> '<STR_LIT>' : PROJECT_ID , <EOL> '<STR_LIT>' : PROJECT_NUMBER , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> connection = _Connection ( PROJECT_RESOURCE ) <EOL> client = _Client ( connection = connection ) <EOL> project = self . _makeOne ( PROJECT_ID , client ) <EOL> project . undelete ( reload_data = False ) <EOL> request , = connection . _requested <EOL> expected_request = { <EOL> '<STR_LIT>' : '<STR_LIT:POST>' , <EOL> '<STR_LIT:path>' : project . path + '<STR_LIT>' , <EOL> } <EOL> self . assertEqual ( request , expected_request ) <EOL> def test_undelete_with_reload_data ( self ) : <EOL> PROJECT_ID = '<STR_LIT>' <EOL> PROJECT_NUMBER = <NUM_LIT> <EOL> PROJECT_RESOURCE = { <EOL> '<STR_LIT>' : PROJECT_ID , <EOL> '<STR_LIT>' : PROJECT_NUMBER , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> UNDELETED_PROJECT = PROJECT_RESOURCE . copy ( ) <EOL> UNDELETED_PROJECT [ '<STR_LIT>' ] = NEW_STATE = '<STR_LIT>' <EOL> connection = _Connection ( PROJECT_RESOURCE , UNDELETED_PROJECT ) <EOL> client = _Client ( connection = connection ) <EOL> project = self . _makeOne ( PROJECT_ID , client ) <EOL> project . undelete ( reload_data = True ) <EOL> self . assertEqual ( project . status , NEW_STATE ) <EOL> undelete_request , get_request = connection . _requested <EOL> expected_undelete_request = { <EOL> '<STR_LIT>' : '<STR_LIT:POST>' , <EOL> '<STR_LIT:path>' : project . path + '<STR_LIT>' , <EOL> } <EOL> self . assertEqual ( undelete_request , expected_undelete_request ) <EOL> expected_get_request = { <EOL> '<STR_LIT>' : '<STR_LIT:GET>' , <EOL> '<STR_LIT:path>' : project . path , <EOL> } <EOL> self . assertEqual ( get_request , expected_get_request ) <EOL> class _Connection ( object ) : <EOL> def __init__ ( self , * responses ) : <EOL> self . _responses = responses <EOL> self . _requested = [ ] <EOL> def api_request ( self , ** kw ) : <EOL> from gcloud . exceptions import NotFound <EOL> self . _requested . append ( kw ) <EOL> try : <EOL> response , self . _responses = self . _responses [ <NUM_LIT:0> ] , self . _responses [ <NUM_LIT:1> : ] <EOL> except : <EOL> raise NotFound ( '<STR_LIT>' ) <EOL> else : <EOL> return response <EOL> class _Client ( object ) : <EOL> def __init__ ( self , connection = None ) : <EOL> self . connection = connection </s>
