@@ -71,68 +71,87 @@ def get_connection(*args, **kw):
71
71
self .assertEqual (connection ._called_with , BUCKET )
72
72
73
73
74
- class Test_set_default_bucket_name (unittest2 .TestCase ):
74
+ class Test_set_default_bucket (unittest2 .TestCase ):
75
75
76
76
def setUp (self ):
77
77
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
80
80
81
81
def tearDown (self ):
82
82
from gcloud .storage import _implicit_environ
83
- _implicit_environ .BUCKET_NAME = self ._replaced_bucket_name
83
+ _implicit_environ .BUCKET = self ._replaced_bucket
84
84
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 )
88
88
89
- def _monkey (self , implicit_bucket_name ):
89
+ def _monkey (self , implicit_bucket_name , connection = None ):
90
+ from contextlib import nested
90
91
import os
91
- from gcloud . storage import _BUCKET_ENV_VAR_NAME
92
+
92
93
from gcloud ._testing import _Monkey
94
+ from gcloud .storage import _BUCKET_ENV_VAR_NAME
95
+ from gcloud .storage import _implicit_environ
96
+
93
97
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 ))
95
100
96
101
def test_no_env_var_set (self ):
97
102
from gcloud .storage import _implicit_environ
98
103
with self ._monkey (None ):
99
104
self ._callFUT ()
100
- self .assertEqual (_implicit_environ .BUCKET_NAME , None )
105
+ self .assertEqual (_implicit_environ .BUCKET , None )
101
106
102
107
def test_set_from_env_var (self ):
103
108
from gcloud .storage import _implicit_environ
104
109
IMPLICIT_BUCKET_NAME = 'IMPLICIT'
105
- with self ._monkey (IMPLICIT_BUCKET_NAME ):
110
+ CONNECTION = object ()
111
+ with self ._monkey (IMPLICIT_BUCKET_NAME , connection = CONNECTION ):
106
112
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 )
108
116
109
117
def test_set_explicit_w_env_var_set (self ):
110
118
from gcloud .storage import _implicit_environ
111
- EXPLICIT_BUCKET_NAME = 'EXPLICIT'
119
+ EXPLICIT_BUCKET = object ()
112
120
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 )
115
123
116
124
def test_set_explicit_no_env_var_set (self ):
117
125
from gcloud .storage import _implicit_environ
118
126
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 )
123
132
124
133
def test_set_explicit_None_wo_env_var_set (self ):
125
134
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 ):
127
144
self ._callFUT (None )
128
- self .assertEqual (_implicit_environ .BUCKET_NAME , None )
145
+ self .assertEqual (_implicit_environ .BUCKET , None )
129
146
130
147
def test_set_explicit_None_w_env_var_set (self ):
131
148
from gcloud .storage import _implicit_environ
132
149
IMPLICIT_BUCKET_NAME = 'IMPLICIT'
133
- with self ._monkey (IMPLICIT_BUCKET_NAME ):
150
+ CONNECTION = object ()
151
+ with self ._monkey (IMPLICIT_BUCKET_NAME , connection = CONNECTION ):
134
152
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 )
136
155
137
156
138
157
class Test_set_default_project (unittest2 .TestCase ):
@@ -299,23 +318,23 @@ def mock_get_connection(*args, **kwargs):
299
318
300
319
class Test_set_defaults (unittest2 .TestCase ):
301
320
302
- def _callFUT (self , bucket_name = None , project = None , connection = None ):
321
+ def _callFUT (self , bucket = None , project = None , connection = None ):
303
322
from gcloud .storage import set_defaults
304
- return set_defaults (bucket_name = bucket_name , project = project ,
323
+ return set_defaults (bucket = bucket , project = project ,
305
324
connection = connection )
306
325
307
326
def test_it (self ):
308
327
from gcloud ._testing import _Monkey
309
328
from gcloud import storage
310
329
311
- BUCKET_NAME = object ()
330
+ BUCKET = object ()
312
331
PROJECT = object ()
313
332
CONNECTION = object ()
314
333
315
- SET_BUCKET_NAME_CALLED = []
334
+ SET_BUCKET_CALLED = []
316
335
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 )
319
338
320
339
SET_PROJECT_CALLED = []
321
340
@@ -327,12 +346,12 @@ def call_set_project(project=None):
327
346
def call_set_connection (project = None , connection = None ):
328
347
SET_CONNECTION_CALLED .append ((project , connection ))
329
348
330
- with _Monkey (storage , set_default_bucket_name = call_set_bucket_name ,
349
+ with _Monkey (storage , set_default_bucket = call_set_bucket ,
331
350
set_default_connection = call_set_connection ,
332
351
set_default_project = call_set_project ):
333
- self ._callFUT (bucket_name = BUCKET_NAME , project = PROJECT ,
352
+ self ._callFUT (bucket = BUCKET , project = PROJECT ,
334
353
connection = CONNECTION )
335
354
336
- self .assertEqual (SET_BUCKET_NAME_CALLED , [BUCKET_NAME ])
337
355
self .assertEqual (SET_PROJECT_CALLED , [PROJECT ])
338
356
self .assertEqual (SET_CONNECTION_CALLED , [(PROJECT , CONNECTION )])
357
+ self .assertEqual (SET_BUCKET_CALLED , [BUCKET ])
0 commit comments