@@ -71,68 +71,87 @@ def get_connection(*args, **kw):
7171 self .assertEqual (connection ._called_with , BUCKET )
7272
7373
74- class Test_set_default_bucket_name (unittest2 .TestCase ):
74+ class Test_set_default_bucket (unittest2 .TestCase ):
7575
7676 def setUp (self ):
7777 from gcloud .storage import _implicit_environ
78- self ._replaced_bucket_name = _implicit_environ .BUCKET_NAME
79- _implicit_environ .BUCKET_NAME = None
78+ self ._replaced_bucket = _implicit_environ .BUCKET
79+ _implicit_environ .BUCKET = None
8080
8181 def tearDown (self ):
8282 from gcloud .storage import _implicit_environ
83- _implicit_environ .BUCKET_NAME = self ._replaced_bucket_name
83+ _implicit_environ .BUCKET = self ._replaced_bucket
8484
85- def _callFUT (self , bucket_name = None ):
86- from gcloud .storage import set_default_bucket_name
87- return set_default_bucket_name ( bucket_name = bucket_name )
85+ def _callFUT (self , bucket = None ):
86+ from gcloud .storage import set_default_bucket
87+ return set_default_bucket ( bucket = bucket )
8888
89- def _monkey (self , implicit_bucket_name ):
89+ def _monkey (self , implicit_bucket_name , connection = None ):
90+ from contextlib import nested
9091 import os
91- from gcloud . storage import _BUCKET_ENV_VAR_NAME
92+
9293 from gcloud ._testing import _Monkey
94+ from gcloud .storage import _BUCKET_ENV_VAR_NAME
95+ from gcloud .storage import _implicit_environ
96+
9397 environ = {_BUCKET_ENV_VAR_NAME : implicit_bucket_name }
94- return _Monkey (os , getenv = environ .get )
98+ return nested (_Monkey (os , getenv = environ .get ),
99+ _Monkey (_implicit_environ , CONNECTION = connection ))
95100
96101 def test_no_env_var_set (self ):
97102 from gcloud .storage import _implicit_environ
98103 with self ._monkey (None ):
99104 self ._callFUT ()
100- self .assertEqual (_implicit_environ .BUCKET_NAME , None )
105+ self .assertEqual (_implicit_environ .BUCKET , None )
101106
102107 def test_set_from_env_var (self ):
103108 from gcloud .storage import _implicit_environ
104109 IMPLICIT_BUCKET_NAME = 'IMPLICIT'
105- with self ._monkey (IMPLICIT_BUCKET_NAME ):
110+ CONNECTION = object ()
111+ with self ._monkey (IMPLICIT_BUCKET_NAME , connection = CONNECTION ):
106112 self ._callFUT ()
107- self .assertEqual (_implicit_environ .BUCKET_NAME , IMPLICIT_BUCKET_NAME )
113+
114+ self .assertEqual (_implicit_environ .BUCKET .name , IMPLICIT_BUCKET_NAME )
115+ self .assertEqual (_implicit_environ .BUCKET .connection , CONNECTION )
108116
109117 def test_set_explicit_w_env_var_set (self ):
110118 from gcloud .storage import _implicit_environ
111- EXPLICIT_BUCKET_NAME = 'EXPLICIT'
119+ EXPLICIT_BUCKET = object ()
112120 with self ._monkey (None ):
113- self ._callFUT (EXPLICIT_BUCKET_NAME )
114- self .assertEqual (_implicit_environ .BUCKET_NAME , EXPLICIT_BUCKET_NAME )
121+ self ._callFUT (EXPLICIT_BUCKET )
122+ self .assertEqual (_implicit_environ .BUCKET , EXPLICIT_BUCKET )
115123
116124 def test_set_explicit_no_env_var_set (self ):
117125 from gcloud .storage import _implicit_environ
118126 IMPLICIT_BUCKET_NAME = 'IMPLICIT'
119- EXPLICIT_BUCKET_NAME = 'EXPLICIT'
120- with self ._monkey (IMPLICIT_BUCKET_NAME ):
121- self ._callFUT (EXPLICIT_BUCKET_NAME )
122- self .assertEqual (_implicit_environ .BUCKET_NAME , EXPLICIT_BUCKET_NAME )
127+ CONNECTION = object ()
128+ EXPLICIT_BUCKET = object ()
129+ with self ._monkey (IMPLICIT_BUCKET_NAME , connection = CONNECTION ):
130+ self ._callFUT (EXPLICIT_BUCKET )
131+ self .assertEqual (_implicit_environ .BUCKET , EXPLICIT_BUCKET )
123132
124133 def test_set_explicit_None_wo_env_var_set (self ):
125134 from gcloud .storage import _implicit_environ
126- with self ._monkey (None ):
135+ CONNECTION = object ()
136+ with self ._monkey (None , connection = CONNECTION ):
137+ self ._callFUT (None )
138+ self .assertEqual (_implicit_environ .BUCKET , None )
139+
140+ def test_set_explicit_None_wo_connection_set (self ):
141+ from gcloud .storage import _implicit_environ
142+ IMPLICIT_BUCKET_NAME = 'IMPLICIT'
143+ with self ._monkey (IMPLICIT_BUCKET_NAME , connection = None ):
127144 self ._callFUT (None )
128- self .assertEqual (_implicit_environ .BUCKET_NAME , None )
145+ self .assertEqual (_implicit_environ .BUCKET , None )
129146
130147 def test_set_explicit_None_w_env_var_set (self ):
131148 from gcloud .storage import _implicit_environ
132149 IMPLICIT_BUCKET_NAME = 'IMPLICIT'
133- with self ._monkey (IMPLICIT_BUCKET_NAME ):
150+ CONNECTION = object ()
151+ with self ._monkey (IMPLICIT_BUCKET_NAME , connection = CONNECTION ):
134152 self ._callFUT (None )
135- self .assertEqual (_implicit_environ .BUCKET_NAME , IMPLICIT_BUCKET_NAME )
153+ self .assertEqual (_implicit_environ .BUCKET .name , IMPLICIT_BUCKET_NAME )
154+ self .assertEqual (_implicit_environ .BUCKET .connection , CONNECTION )
136155
137156
138157class Test_set_default_project (unittest2 .TestCase ):
@@ -299,23 +318,23 @@ def mock_get_connection(*args, **kwargs):
299318
300319class Test_set_defaults (unittest2 .TestCase ):
301320
302- def _callFUT (self , bucket_name = None , project = None , connection = None ):
321+ def _callFUT (self , bucket = None , project = None , connection = None ):
303322 from gcloud .storage import set_defaults
304- return set_defaults (bucket_name = bucket_name , project = project ,
323+ return set_defaults (bucket = bucket , project = project ,
305324 connection = connection )
306325
307326 def test_it (self ):
308327 from gcloud ._testing import _Monkey
309328 from gcloud import storage
310329
311- BUCKET_NAME = object ()
330+ BUCKET = object ()
312331 PROJECT = object ()
313332 CONNECTION = object ()
314333
315- SET_BUCKET_NAME_CALLED = []
334+ SET_BUCKET_CALLED = []
316335
317- def call_set_bucket_name ( bucket_name = None ):
318- SET_BUCKET_NAME_CALLED .append (bucket_name )
336+ def call_set_bucket ( bucket = None ):
337+ SET_BUCKET_CALLED .append (bucket )
319338
320339 SET_PROJECT_CALLED = []
321340
@@ -327,12 +346,12 @@ def call_set_project(project=None):
327346 def call_set_connection (project = None , connection = None ):
328347 SET_CONNECTION_CALLED .append ((project , connection ))
329348
330- with _Monkey (storage , set_default_bucket_name = call_set_bucket_name ,
349+ with _Monkey (storage , set_default_bucket = call_set_bucket ,
331350 set_default_connection = call_set_connection ,
332351 set_default_project = call_set_project ):
333- self ._callFUT (bucket_name = BUCKET_NAME , project = PROJECT ,
352+ self ._callFUT (bucket = BUCKET , project = PROJECT ,
334353 connection = CONNECTION )
335354
336- self .assertEqual (SET_BUCKET_NAME_CALLED , [BUCKET_NAME ])
337355 self .assertEqual (SET_PROJECT_CALLED , [PROJECT ])
338356 self .assertEqual (SET_CONNECTION_CALLED , [(PROJECT , CONNECTION )])
357+ self .assertEqual (SET_BUCKET_CALLED , [BUCKET ])
0 commit comments