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 26
26
import six
27
27
28
28
from gcloud ._localstack import _LocalStack
29
+ from gcloud .storage import _implicit_environ
29
30
from gcloud .storage .connection import Connection
30
31
31
32
@@ -78,7 +79,10 @@ class Batch(Connection):
78
79
"""
79
80
_MAX_BATCH_SIZE = 1000
80
81
81
- def __init__ (self , connection ):
82
+ def __init__ (self , connection = None ):
83
+ if connection is None :
84
+ connection = _implicit_environ .get_default_connection ()
85
+
82
86
super (Batch , self ).__init__ (project = connection .project )
83
87
self ._connection = connection
84
88
self ._requests = []
Original file line number Diff line number Diff line change @@ -68,6 +68,14 @@ def test_ctor_body_dict(self):
68
68
69
69
class TestBatch (unittest2 .TestCase ):
70
70
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
+
71
79
def _getTargetClass (self ):
72
80
from gcloud .storage .batch import Batch
73
81
return Batch
@@ -84,6 +92,19 @@ def test_ctor_w_explicit_connection(self):
84
92
self .assertEqual (len (batch ._requests ), 0 )
85
93
self .assertEqual (len (batch ._responses ), 0 )
86
94
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
+
87
108
def test__make_request_GET_forwarded_to_connection (self ):
88
109
URL = 'http://example.com/api'
89
110
expected = _Response ()
Original file line number Diff line number Diff line change 29
29
storage ._PROJECT_ENV_VAR_NAME = 'GCLOUD_TESTS_PROJECT_ID'
30
30
storage .set_defaults ()
31
31
32
- CONNECTION = storage .get_default_connection ()
33
-
34
32
35
33
def setUpModule ():
36
34
if 'test_bucket' not in SHARED_BUCKETS :
@@ -52,7 +50,7 @@ def setUp(self):
52
50
self .case_buckets_to_delete = []
53
51
54
52
def tearDown (self ):
55
- with Batch (CONNECTION ) as batch :
53
+ with Batch () as batch :
56
54
for bucket_name in self .case_buckets_to_delete :
57
55
storage .Bucket (connection = batch , name = bucket_name ).delete ()
58
56
You can’t perform that action at this time.
0 commit comments