@@ -41,27 +41,31 @@ def test_implicit_unset_w_keys(self):
41
41
self .assertEqual (self ._callFUT (first_key = _Key (ID )), ID )
42
42
43
43
def test_implicit_unset_w_existing_batch_wo_keys (self ):
44
+ from gcloud .datastore ._testing import _NoCommitBatch
44
45
ID = 'DATASET'
45
46
with self ._monkey (None ):
46
47
with _NoCommitBatch (dataset_id = ID , connection = object ()):
47
48
self .assertEqual (self ._callFUT (), ID )
48
49
49
50
def test_implicit_unset_w_existing_batch_w_keys (self ):
50
51
from gcloud .datastore .test_batch import _Key
52
+ from gcloud .datastore ._testing import _NoCommitBatch
51
53
ID = 'DATASET'
52
54
OTHER = 'OTHER'
53
55
with self ._monkey (None ):
54
56
with _NoCommitBatch (dataset_id = ID , connection = object ()):
55
57
self .assertEqual (self ._callFUT (first_key = _Key (OTHER )), ID )
56
58
57
59
def test_implicit_unset_w_existing_transaction_wo_keys (self ):
60
+ from gcloud .datastore ._testing import _NoCommitTransaction
58
61
ID = 'DATASET'
59
62
with self ._monkey (None ):
60
63
with _NoCommitTransaction (dataset_id = ID , connection = object ()):
61
64
self .assertEqual (self ._callFUT (), ID )
62
65
63
66
def test_implicit_unset_w_existing_transaction_w_keys (self ):
64
67
from gcloud .datastore .test_batch import _Key
68
+ from gcloud .datastore ._testing import _NoCommitTransaction
65
69
ID = 'DATASET'
66
70
OTHER = 'OTHER'
67
71
with self ._monkey (None ):
@@ -108,56 +112,6 @@ def test_id_implicit_set_passed_explicitly_w_keys(self):
108
112
self .assertEqual (self ._callFUT (ID , first_key = _Key (OTHER )), ID )
109
113
110
114
111
- class Test__require_connection (unittest2 .TestCase ):
112
-
113
- _MARKER = object ()
114
-
115
- def _callFUT (self , passed = _MARKER ):
116
- from gcloud .datastore .api import _require_connection
117
- if passed is self ._MARKER :
118
- return _require_connection ()
119
- return _require_connection (passed )
120
-
121
- def _monkey (self , connection ):
122
- from gcloud .datastore ._testing import _monkey_defaults
123
- return _monkey_defaults (connection = connection )
124
-
125
- def test_implicit_unset (self ):
126
- with self ._monkey (None ):
127
- with self .assertRaises (EnvironmentError ):
128
- self ._callFUT ()
129
-
130
- def test_implicit_unset_w_existing_batch (self ):
131
- ID = 'DATASET'
132
- CONNECTION = object ()
133
- with self ._monkey (None ):
134
- with _NoCommitBatch (dataset_id = ID , connection = CONNECTION ):
135
- self .assertEqual (self ._callFUT (), CONNECTION )
136
-
137
- def test_implicit_unset_w_existing_transaction (self ):
138
- ID = 'DATASET'
139
- CONNECTION = object ()
140
- with self ._monkey (None ):
141
- with _NoCommitTransaction (dataset_id = ID , connection = CONNECTION ):
142
- self .assertEqual (self ._callFUT (), CONNECTION )
143
-
144
- def test_implicit_unset_passed_explicitly (self ):
145
- CONNECTION = object ()
146
- with self ._monkey (None ):
147
- self .assertTrue (self ._callFUT (CONNECTION ) is CONNECTION )
148
-
149
- def test_implicit_set (self ):
150
- IMPLICIT_CONNECTION = object ()
151
- with self ._monkey (IMPLICIT_CONNECTION ):
152
- self .assertTrue (self ._callFUT () is IMPLICIT_CONNECTION )
153
-
154
- def test_implicit_set_passed_explicitly (self ):
155
- IMPLICIT_CONNECTION = object ()
156
- CONNECTION = object ()
157
- with self ._monkey (IMPLICIT_CONNECTION ):
158
- self .assertTrue (self ._callFUT (CONNECTION ) is CONNECTION )
159
-
160
-
161
115
class Test_get_function (unittest2 .TestCase ):
162
116
163
117
def setUp (self ):
@@ -499,6 +453,7 @@ def test_implicit_wo_transaction(self):
499
453
def test_w_transaction (self ):
500
454
from gcloud .datastore .key import Key
501
455
from gcloud .datastore .test_connection import _Connection
456
+ from gcloud .datastore ._testing import _NoCommitTransaction
502
457
503
458
DATASET_ID = 'DATASET'
504
459
KIND = 'Kind'
@@ -661,6 +616,7 @@ def test_existing_batch_w_completed_key(self):
661
616
from gcloud .datastore .test_batch import _Connection
662
617
from gcloud .datastore .test_batch import _Entity
663
618
from gcloud .datastore .test_batch import _Key
619
+ from gcloud .datastore ._testing import _NoCommitBatch
664
620
665
621
# Build basic mocks needed to delete.
666
622
_DATASET = 'DATASET'
@@ -687,6 +643,7 @@ def test_implicit_connection(self):
687
643
from gcloud .datastore .test_batch import _Connection
688
644
from gcloud .datastore .test_batch import _Entity
689
645
from gcloud .datastore .test_batch import _Key
646
+ from gcloud .datastore ._testing import _NoCommitBatch
690
647
691
648
# Build basic mocks needed to delete.
692
649
_DATASET = 'DATASET'
@@ -804,6 +761,7 @@ def test_wo_batch_w_key_different_than_default_dataset_id(self):
804
761
def test_w_existing_batch (self ):
805
762
from gcloud .datastore .test_batch import _Connection
806
763
from gcloud .datastore .test_batch import _Key
764
+ from gcloud .datastore ._testing import _NoCommitBatch
807
765
808
766
# Build basic mocks needed to delete.
809
767
_DATASET = 'DATASET'
@@ -825,6 +783,7 @@ def test_w_existing_batch(self):
825
783
def test_w_existing_transaction (self ):
826
784
from gcloud .datastore .test_batch import _Connection
827
785
from gcloud .datastore .test_batch import _Key
786
+ from gcloud .datastore ._testing import _NoCommitTransaction
828
787
829
788
# Build basic mocks needed to delete.
830
789
_DATASET = 'DATASET'
@@ -847,6 +806,7 @@ def test_implicit_connection_and_dataset_id(self):
847
806
from gcloud .datastore ._testing import _monkey_defaults
848
807
from gcloud .datastore .test_batch import _Connection
849
808
from gcloud .datastore .test_batch import _Key
809
+ from gcloud .datastore ._testing import _NoCommitBatch
850
810
851
811
# Build basic mocks needed to delete.
852
812
_DATASET = 'DATASET'
@@ -918,39 +878,6 @@ def test_with_already_completed_key(self):
918
878
COMPLETE_KEY , 2 )
919
879
920
880
921
- class _NoCommitBatch (object ):
922
-
923
- def __init__ (self , dataset_id , connection ):
924
- from gcloud .datastore .batch import Batch
925
- self ._batch = Batch (dataset_id , connection )
926
-
927
- def __enter__ (self ):
928
- from gcloud .datastore .connection import _CONNECTIONS
929
- _CONNECTIONS .push (self ._batch )
930
- return self ._batch
931
-
932
- def __exit__ (self , * args ):
933
- from gcloud .datastore .connection import _CONNECTIONS
934
- _CONNECTIONS .pop ()
935
-
936
-
937
- class _NoCommitTransaction (object ):
938
-
939
- def __init__ (self , dataset_id , connection , transaction_id = 'TRANSACTION' ):
940
- from gcloud .datastore .transaction import Transaction
941
- xact = self ._transaction = Transaction (dataset_id , connection )
942
- xact ._id = transaction_id
943
-
944
- def __enter__ (self ):
945
- from gcloud .datastore .connection import _CONNECTIONS
946
- _CONNECTIONS .push (self ._transaction )
947
- return self ._transaction
948
-
949
- def __exit__ (self , * args ):
950
- from gcloud .datastore .connection import _CONNECTIONS
951
- _CONNECTIONS .pop ()
952
-
953
-
954
881
class _HttpMultiple (object ):
955
882
956
883
def __init__ (self , * responses ):
0 commit comments