@@ -23,16 +23,22 @@ def _getTargetClass(self):
2323 from gcloud .datastore .dataset import Dataset
2424 return Dataset
2525
26- def _makeOne (self , dataset_id = DATASET_ID ):
27- return self ._getTargetClass ()(dataset_id = dataset_id )
26+ def _makeOne (self , dataset_id = DATASET_ID , connection = None ):
27+ return self ._getTargetClass ()(dataset_id , connection )
2828
29- def test_ctor_w_None (self ):
29+ def test_ctor_w_dataset_id_None (self ):
3030 self .assertRaises (ValueError , self ._makeOne , None )
3131
32- def test_ctor_w_dataset_id (self ):
32+ def test_ctor_w_dataset_id_no_connection (self ):
3333 dataset = self ._makeOne ()
3434 self .assertEqual (dataset .dataset_id , self .DATASET_ID )
3535
36+ def test_ctor_w_dataset_id_w_connection (self ):
37+ conn = object ()
38+ dataset = self ._makeOne (connection = conn )
39+ self .assertEqual (dataset .dataset_id , self .DATASET_ID )
40+ self .assertTrue (dataset .connection is conn )
41+
3642 def test_get_defaults (self ):
3743 from gcloud .datastore import dataset as MUT
3844 from gcloud ._testing import _Monkey
@@ -60,11 +66,12 @@ def test_get_explicit(self):
6066 def _get (* args , ** kw ):
6167 _called_with .append ((args , kw ))
6268
63- dataset = self ._makeOne ()
64- key , missing , deferred , conn = object (), [], [], object ()
69+ conn = object ()
70+ dataset = self ._makeOne (connection = conn )
71+ key , missing , deferred = object (), [], []
6572
6673 with _Monkey (MUT , get = _get ):
67- dataset .get ([key ], missing , deferred , conn )
74+ dataset .get ([key ], missing , deferred )
6875
6976 args = ([key ], missing , deferred , conn , self .DATASET_ID )
7077 self .assertEqual (_called_with , [(args , {})])
@@ -96,11 +103,11 @@ def test_put_w_connection(self):
96103 def _put (* args , ** kw ):
97104 _called_with .append ((args , kw ))
98105
99- dataset = self ._makeOne ()
100106 entity , conn = object (), object ()
107+ dataset = self ._makeOne (connection = conn )
101108
102109 with _Monkey (MUT , put = _put ):
103- dataset .put ([entity ], conn )
110+ dataset .put ([entity ])
104111
105112 self .assertEqual (_called_with ,
106113 [(([entity ], conn ), {'dataset_id' : self .DATASET_ID })])
@@ -132,10 +139,10 @@ def test_delete_w_connection(self):
132139 def _delete (* args , ** kw ):
133140 _called_with .append ((args , kw ))
134141
135- dataset = self ._makeOne ()
136142 key , conn = object (), object ()
143+ dataset = self ._makeOne (connection = conn )
137144 with _Monkey (MUT , delete = _delete ):
138- dataset .delete ([key ], conn )
145+ dataset .delete ([key ])
139146
140147 self .assertEqual (_called_with ,
141148 [(([key ], conn ), {'dataset_id' : self .DATASET_ID })])
@@ -191,11 +198,11 @@ def test_batch_wo_connection(self):
191198 def test_batch_w_connection (self ):
192199 from gcloud .datastore import dataset as MUT
193200 from gcloud ._testing import _Monkey
194- dataset = self ._makeOne ()
195201 conn = object ()
202+ dataset = self ._makeOne (connection = conn )
196203
197204 with _Monkey (MUT , Batch = _Dummy ):
198- batch = dataset .batch (conn )
205+ batch = dataset .batch ()
199206
200207 self .assertTrue (isinstance (batch , _Dummy ))
201208 self .assertEqual (batch .args , ())
@@ -218,11 +225,11 @@ def test_transaction_wo_connection(self):
218225 def test_transaction_w_connection (self ):
219226 from gcloud .datastore import dataset as MUT
220227 from gcloud ._testing import _Monkey
221- dataset = self ._makeOne ()
222228 conn = object ()
229+ dataset = self ._makeOne (connection = conn )
223230
224231 with _Monkey (MUT , Transaction = _Dummy ):
225- xact = dataset .transaction (conn )
232+ xact = dataset .transaction ()
226233
227234 self .assertTrue (isinstance (xact , _Dummy ))
228235 self .assertEqual (xact .args , ())
0 commit comments