@@ -23,16 +23,22 @@ def _getTargetClass(self):
23
23
from gcloud .datastore .dataset import Dataset
24
24
return Dataset
25
25
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 )
28
28
29
- def test_ctor_w_None (self ):
29
+ def test_ctor_w_dataset_id_None (self ):
30
30
self .assertRaises (ValueError , self ._makeOne , None )
31
31
32
- def test_ctor_w_dataset_id (self ):
32
+ def test_ctor_w_dataset_id_no_connection (self ):
33
33
dataset = self ._makeOne ()
34
34
self .assertEqual (dataset .dataset_id , self .DATASET_ID )
35
35
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
+
36
42
def test_get_defaults (self ):
37
43
from gcloud .datastore import dataset as MUT
38
44
from gcloud ._testing import _Monkey
@@ -60,11 +66,12 @@ def test_get_explicit(self):
60
66
def _get (* args , ** kw ):
61
67
_called_with .append ((args , kw ))
62
68
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 (), [], []
65
72
66
73
with _Monkey (MUT , get = _get ):
67
- dataset .get ([key ], missing , deferred , conn )
74
+ dataset .get ([key ], missing , deferred )
68
75
69
76
args = ([key ], missing , deferred , conn , self .DATASET_ID )
70
77
self .assertEqual (_called_with , [(args , {})])
@@ -96,11 +103,11 @@ def test_put_w_connection(self):
96
103
def _put (* args , ** kw ):
97
104
_called_with .append ((args , kw ))
98
105
99
- dataset = self ._makeOne ()
100
106
entity , conn = object (), object ()
107
+ dataset = self ._makeOne (connection = conn )
101
108
102
109
with _Monkey (MUT , put = _put ):
103
- dataset .put ([entity ], conn )
110
+ dataset .put ([entity ])
104
111
105
112
self .assertEqual (_called_with ,
106
113
[(([entity ], conn ), {'dataset_id' : self .DATASET_ID })])
@@ -132,10 +139,10 @@ def test_delete_w_connection(self):
132
139
def _delete (* args , ** kw ):
133
140
_called_with .append ((args , kw ))
134
141
135
- dataset = self ._makeOne ()
136
142
key , conn = object (), object ()
143
+ dataset = self ._makeOne (connection = conn )
137
144
with _Monkey (MUT , delete = _delete ):
138
- dataset .delete ([key ], conn )
145
+ dataset .delete ([key ])
139
146
140
147
self .assertEqual (_called_with ,
141
148
[(([key ], conn ), {'dataset_id' : self .DATASET_ID })])
@@ -191,11 +198,11 @@ def test_batch_wo_connection(self):
191
198
def test_batch_w_connection (self ):
192
199
from gcloud .datastore import dataset as MUT
193
200
from gcloud ._testing import _Monkey
194
- dataset = self ._makeOne ()
195
201
conn = object ()
202
+ dataset = self ._makeOne (connection = conn )
196
203
197
204
with _Monkey (MUT , Batch = _Dummy ):
198
- batch = dataset .batch (conn )
205
+ batch = dataset .batch ()
199
206
200
207
self .assertTrue (isinstance (batch , _Dummy ))
201
208
self .assertEqual (batch .args , ())
@@ -218,11 +225,11 @@ def test_transaction_wo_connection(self):
218
225
def test_transaction_w_connection (self ):
219
226
from gcloud .datastore import dataset as MUT
220
227
from gcloud ._testing import _Monkey
221
- dataset = self ._makeOne ()
222
228
conn = object ()
229
+ dataset = self ._makeOne (connection = conn )
223
230
224
231
with _Monkey (MUT , Transaction = _Dummy ):
225
- xact = dataset .transaction (conn )
232
+ xact = dataset .transaction ()
226
233
227
234
self .assertTrue (isinstance (xact , _Dummy ))
228
235
self .assertEqual (xact .args , ())
0 commit comments