@@ -41,27 +41,31 @@ def test_implicit_unset_w_keys(self):
4141 self .assertEqual (self ._callFUT (first_key = _Key (ID )), ID )
4242
4343 def test_implicit_unset_w_existing_batch_wo_keys (self ):
44+ from gcloud .datastore ._testing import _NoCommitBatch
4445 ID = 'DATASET'
4546 with self ._monkey (None ):
4647 with _NoCommitBatch (dataset_id = ID , connection = object ()):
4748 self .assertEqual (self ._callFUT (), ID )
4849
4950 def test_implicit_unset_w_existing_batch_w_keys (self ):
5051 from gcloud .datastore .test_batch import _Key
52+ from gcloud .datastore ._testing import _NoCommitBatch
5153 ID = 'DATASET'
5254 OTHER = 'OTHER'
5355 with self ._monkey (None ):
5456 with _NoCommitBatch (dataset_id = ID , connection = object ()):
5557 self .assertEqual (self ._callFUT (first_key = _Key (OTHER )), ID )
5658
5759 def test_implicit_unset_w_existing_transaction_wo_keys (self ):
60+ from gcloud .datastore ._testing import _NoCommitTransaction
5861 ID = 'DATASET'
5962 with self ._monkey (None ):
6063 with _NoCommitTransaction (dataset_id = ID , connection = object ()):
6164 self .assertEqual (self ._callFUT (), ID )
6265
6366 def test_implicit_unset_w_existing_transaction_w_keys (self ):
6467 from gcloud .datastore .test_batch import _Key
68+ from gcloud .datastore ._testing import _NoCommitTransaction
6569 ID = 'DATASET'
6670 OTHER = 'OTHER'
6771 with self ._monkey (None ):
@@ -108,56 +112,6 @@ def test_id_implicit_set_passed_explicitly_w_keys(self):
108112 self .assertEqual (self ._callFUT (ID , first_key = _Key (OTHER )), ID )
109113
110114
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-
161115class Test_get_function (unittest2 .TestCase ):
162116
163117 def setUp (self ):
@@ -499,6 +453,7 @@ def test_implicit_wo_transaction(self):
499453 def test_w_transaction (self ):
500454 from gcloud .datastore .key import Key
501455 from gcloud .datastore .test_connection import _Connection
456+ from gcloud .datastore ._testing import _NoCommitTransaction
502457
503458 DATASET_ID = 'DATASET'
504459 KIND = 'Kind'
@@ -661,6 +616,7 @@ def test_existing_batch_w_completed_key(self):
661616 from gcloud .datastore .test_batch import _Connection
662617 from gcloud .datastore .test_batch import _Entity
663618 from gcloud .datastore .test_batch import _Key
619+ from gcloud .datastore ._testing import _NoCommitBatch
664620
665621 # Build basic mocks needed to delete.
666622 _DATASET = 'DATASET'
@@ -687,6 +643,7 @@ def test_implicit_connection(self):
687643 from gcloud .datastore .test_batch import _Connection
688644 from gcloud .datastore .test_batch import _Entity
689645 from gcloud .datastore .test_batch import _Key
646+ from gcloud .datastore ._testing import _NoCommitBatch
690647
691648 # Build basic mocks needed to delete.
692649 _DATASET = 'DATASET'
@@ -804,6 +761,7 @@ def test_wo_batch_w_key_different_than_default_dataset_id(self):
804761 def test_w_existing_batch (self ):
805762 from gcloud .datastore .test_batch import _Connection
806763 from gcloud .datastore .test_batch import _Key
764+ from gcloud .datastore ._testing import _NoCommitBatch
807765
808766 # Build basic mocks needed to delete.
809767 _DATASET = 'DATASET'
@@ -825,6 +783,7 @@ def test_w_existing_batch(self):
825783 def test_w_existing_transaction (self ):
826784 from gcloud .datastore .test_batch import _Connection
827785 from gcloud .datastore .test_batch import _Key
786+ from gcloud .datastore ._testing import _NoCommitTransaction
828787
829788 # Build basic mocks needed to delete.
830789 _DATASET = 'DATASET'
@@ -847,6 +806,7 @@ def test_implicit_connection_and_dataset_id(self):
847806 from gcloud .datastore ._testing import _monkey_defaults
848807 from gcloud .datastore .test_batch import _Connection
849808 from gcloud .datastore .test_batch import _Key
809+ from gcloud .datastore ._testing import _NoCommitBatch
850810
851811 # Build basic mocks needed to delete.
852812 _DATASET = 'DATASET'
@@ -918,39 +878,6 @@ def test_with_already_completed_key(self):
918878 COMPLETE_KEY , 2 )
919879
920880
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-
954881class _HttpMultiple (object ):
955882
956883 def __init__ (self , * responses ):
0 commit comments