File tree Expand file tree Collapse file tree 3 files changed +27
-4
lines changed
Expand file tree Collapse file tree 3 files changed +27
-4
lines changed Original file line number Diff line number Diff line change 2626import six
2727
2828from gcloud ._localstack import _LocalStack
29+ from gcloud .storage import _implicit_environ
2930from gcloud .storage .connection import Connection
3031
3132
@@ -78,7 +79,10 @@ class Batch(Connection):
7879 """
7980 _MAX_BATCH_SIZE = 1000
8081
81- def __init__ (self , connection ):
82+ def __init__ (self , connection = None ):
83+ if connection is None :
84+ connection = _implicit_environ .get_default_connection ()
85+
8286 super (Batch , self ).__init__ (project = connection .project )
8387 self ._connection = connection
8488 self ._requests = []
Original file line number Diff line number Diff line change @@ -68,6 +68,14 @@ def test_ctor_body_dict(self):
6868
6969class TestBatch (unittest2 .TestCase ):
7070
71+ def setUp (self ):
72+ from gcloud .storage ._testing import _setup_defaults
73+ _setup_defaults (self )
74+
75+ def tearDown (self ):
76+ from gcloud .storage ._testing import _tear_down_defaults
77+ _tear_down_defaults (self )
78+
7179 def _getTargetClass (self ):
7280 from gcloud .storage .batch import Batch
7381 return Batch
@@ -84,6 +92,19 @@ def test_ctor_w_explicit_connection(self):
8492 self .assertEqual (len (batch ._requests ), 0 )
8593 self .assertEqual (len (batch ._responses ), 0 )
8694
95+ def test_ctor_w_implicit_connection (self ):
96+ from gcloud .storage ._testing import _monkey_defaults
97+
98+ http = _HTTP ()
99+ connection = _Connection (http = http )
100+ with _monkey_defaults (connection = connection ):
101+ batch = self ._makeOne ()
102+
103+ self .assertTrue (batch ._connection is connection )
104+ self .assertEqual (batch .project , connection .project )
105+ self .assertEqual (len (batch ._requests ), 0 )
106+ self .assertEqual (len (batch ._responses ), 0 )
107+
87108 def test__make_request_GET_forwarded_to_connection (self ):
88109 URL = 'http://example.com/api'
89110 expected = _Response ()
Original file line number Diff line number Diff line change 2929storage ._PROJECT_ENV_VAR_NAME = 'GCLOUD_TESTS_PROJECT_ID'
3030storage .set_defaults ()
3131
32- CONNECTION = storage .get_default_connection ()
33-
3432
3533def setUpModule ():
3634 if 'test_bucket' not in SHARED_BUCKETS :
@@ -52,7 +50,7 @@ def setUp(self):
5250 self .case_buckets_to_delete = []
5351
5452 def tearDown (self ):
55- with Batch (CONNECTION ) as batch :
53+ with Batch () as batch :
5654 for bucket_name in self .case_buckets_to_delete :
5755 storage .Bucket (connection = batch , name = bucket_name ).delete ()
5856
You can’t perform that action at this time.
0 commit comments