Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Avoid sharing mock between testcase modules.
Addresses:
#978 (comment)
  • Loading branch information
tseaver committed Jul 10, 2015
commit 0c411dc839cd1d7b283aeebbcf92386b69062baf
4 changes: 0 additions & 4 deletions gcloud/datastore/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,3 @@ def _pop_batch(self):
def current_batch(self):
if self._batches:
return self._batches[0]

@property
def current_transaction(self):
pass
14 changes: 12 additions & 2 deletions gcloud/datastore/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def _makeOne(self, *args, **kw):
return self._getTargetClass()(*args, **kw)

def _makeClient(self, connection=None):
from gcloud.datastore.test_batch import _Client
if connection is None:
connection = _Connection()
return _Client(self._DATASET, connection)
Expand Down Expand Up @@ -358,7 +357,6 @@ def _addQueryResults(self, connection, cursor=_END, more=False):
([entity_pb], cursor, MORE if more else NO_MORE))

def _makeClient(self, connection=None):
from gcloud.datastore.test_batch import _Client
if connection is None:
connection = _Connection()
return _Client(self._DATASET, connection)
Expand Down Expand Up @@ -671,3 +669,15 @@ def run_query(self, **kw):
self._called_with.append(kw)
result, self._results = self._results[0], self._results[1:]
return result


class _Client(object):

def __init__(self, dataset_id, connection, namespace=None):
self.dataset_id = dataset_id
self.connection = connection
self.namespace = namespace

@property
def current_transaction(self):
pass
29 changes: 20 additions & 9 deletions gcloud/datastore/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def _makeOne(self, client):

def test_ctor(self):
from gcloud.datastore._datastore_v1_pb2 import Mutation
from gcloud.datastore.test_batch import _Client

_DATASET = 'DATASET'
connection = _Connection()
Expand All @@ -41,7 +40,6 @@ def test_ctor(self):

def test_current(self):
from gcloud.datastore.test_client import _NoCommitBatch
from gcloud.datastore.test_batch import _Client
_DATASET = 'DATASET'
connection = _Connection()
client = _Client(_DATASET, connection)
Expand All @@ -67,7 +65,6 @@ def test_current(self):
self.assertTrue(xact2.current() is None)

def test_begin(self):
from gcloud.datastore.test_batch import _Client
_DATASET = 'DATASET'
connection = _Connection(234)
client = _Client(_DATASET, connection)
Expand All @@ -77,7 +74,6 @@ def test_begin(self):
self.assertEqual(connection._begun, _DATASET)

def test_begin_tombstoned(self):
from gcloud.datastore.test_batch import _Client
_DATASET = 'DATASET'
connection = _Connection(234)
client = _Client(_DATASET, connection)
Expand All @@ -92,7 +88,6 @@ def test_begin_tombstoned(self):
self.assertRaises(ValueError, xact.begin)

def test_rollback(self):
from gcloud.datastore.test_batch import _Client
_DATASET = 'DATASET'
connection = _Connection(234)
client = _Client(_DATASET, connection)
Expand All @@ -103,7 +98,6 @@ def test_rollback(self):
self.assertEqual(connection._rolled_back, (_DATASET, 234))

def test_commit_no_auto_ids(self):
from gcloud.datastore.test_batch import _Client
_DATASET = 'DATASET'
connection = _Connection(234)
client = _Client(_DATASET, connection)
Expand All @@ -115,7 +109,6 @@ def test_commit_no_auto_ids(self):
self.assertEqual(xact.id, None)

def test_commit_w_auto_ids(self):
from gcloud.datastore.test_batch import _Client
_DATASET = 'DATASET'
_KIND = 'KIND'
_ID = 123
Expand All @@ -134,7 +127,6 @@ def test_commit_w_auto_ids(self):
self.assertEqual(entity.key.path, [{'kind': _KIND, 'id': _ID}])

def test_context_manager_no_raise(self):
from gcloud.datastore.test_batch import _Client
_DATASET = 'DATASET'
connection = _Connection(234)
client = _Client(_DATASET, connection)
Expand All @@ -147,7 +139,6 @@ def test_context_manager_no_raise(self):
self.assertEqual(xact.id, None)

def test_context_manager_w_raise(self):
from gcloud.datastore.test_batch import _Client

class Foo(Exception):
pass
Expand Down Expand Up @@ -211,3 +202,23 @@ class _Entity(object):
def __init__(self):
from gcloud.datastore.key import Key
self.key = Key('KIND', dataset_id='DATASET')


class _Client(object):

def __init__(self, dataset_id, connection, namespace=None):
self.dataset_id = dataset_id
self.connection = connection
self.namespace = namespace
self._batches = []

def _push_batch(self, batch):
self._batches.insert(0, batch)

def _pop_batch(self):
return self._batches.pop(0)

@property
def current_batch(self):
if self._batches:
return self._batches[0]