From 968ed0d4e9101087968eff68738407423fb8bba2 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Mon, 30 Mar 2015 19:05:16 -0700 Subject: [PATCH] Removing _PropertyBatch from storage. --- gcloud/storage/_helpers.py | 42 ----------------- gcloud/storage/test__helpers.py | 83 --------------------------------- 2 files changed, 125 deletions(-) diff --git a/gcloud/storage/_helpers.py b/gcloud/storage/_helpers.py index c65f4ecf02bd..cb3fc566a6a8 100644 --- a/gcloud/storage/_helpers.py +++ b/gcloud/storage/_helpers.py @@ -49,30 +49,6 @@ def __init__(self, name=None): self._properties = {} self._changes = set() - @property - def batch(self): - """Return a context manager which defers/batches updates. - - E.g., to batch multiple updates to a bucket:: - - >>> with bucket.batch: - ... bucket.enable_versioning() - ... bucket.disable_website() - - or for a blob:: - - >>> with blob.batch: - ... blob.content_type = 'image/jpeg' - ... blob.content_encoding = 'gzip' - - Updates will be aggregated and sent as a single call to - :meth:`_patch_properties` IFF the ``with`` block exits without - an exception. - - :rtype: :class:`_PropertyBatch` - """ - return _PropertyBatch(self) - def reload(self): """Reload properties from Cloud Storage. @@ -123,24 +99,6 @@ def patch(self): return self -class _PropertyBatch(object): - """Context manager: Batch updates to object. - - :type wrapped: class derived from :class:`_PropertyMixin`. - :param wrapped: the instance whose property updates to batch. - """ - def __init__(self, wrapped): - self._wrapped = wrapped - - def __enter__(self): - """Do nothing method. Needed to be a context manager.""" - - def __exit__(self, exc_type, value, traceback): - """Patch deferred property updates if no error.""" - if exc_type is None: - self._wrapped.patch() - - def _scalar_property(fieldname): """Create a property descriptor around the :class:`_PropertyMixin` helpers. """ diff --git a/gcloud/storage/test__helpers.py b/gcloud/storage/test__helpers.py index 52fab616b149..eaa3ca678319 100644 --- a/gcloud/storage/test__helpers.py +++ b/gcloud/storage/test__helpers.py @@ -46,20 +46,6 @@ def test_path_is_abstract(self): mixin = self._makeOne() self.assertRaises(NotImplementedError, lambda: mixin.path) - def test_batch(self): - connection = _Connection({'foo': 'Qux', 'bar': 'Baz'}) - derived = self._derivedClass(connection, '/path')() - with derived.batch: - derived._patch_properties({'foo': 'Foo'}) - derived._patch_properties({'bar': 'Baz'}) - derived._patch_properties({'foo': 'Qux'}) - kw = connection._requested - self.assertEqual(len(kw), 1) - self.assertEqual(kw[0]['method'], 'PATCH') - self.assertEqual(kw[0]['path'], '/path') - self.assertEqual(kw[0]['data'], {'foo': 'Qux', 'bar': 'Baz'}) - self.assertEqual(kw[0]['query_params'], {'projection': 'full'}) - def test_reload(self): connection = _Connection({'foo': 'Foo'}) derived = self._derivedClass(connection, '/path')() @@ -84,75 +70,6 @@ def test__patch_properties(self): self.assertEqual(kw[0]['query_params'], {'projection': 'full'}) -class Test_PropertyBatch(unittest2.TestCase): - - def _getTargetClass(self): - from gcloud.storage._helpers import _PropertyBatch - return _PropertyBatch - - def _makeOne(self, wrapped): - return self._getTargetClass()(wrapped) - - def _makeWrapped(self, connection=None, path=None): - from gcloud.storage._helpers import _PropertyMixin - - class Wrapped(_PropertyMixin): - - @property - def connection(self): - return connection - - @property - def path(self): - return path - - return Wrapped() - - def test_ctor_does_not_intercept__patch_properties(self): - wrapped = self._makeWrapped() - before = wrapped._patch_properties - batch = self._makeOne(wrapped) - after = wrapped._patch_properties - self.assertEqual(before, after) - self.assertTrue(batch._wrapped is wrapped) - - def test___exit___w_error_skips_patch(self): - class Testing(Exception): - pass - connection = _Connection() - wrapped = self._makeWrapped(connection) - batch = self._makeOne(wrapped) - try: - with batch: - # deferred patching - wrapped._patch_properties({'foo': 'Foo'}) - # but error -> no call to the real '_patch_properties' - raise Testing('testing') - except Testing: - pass - - kw = connection._requested - self.assertEqual(len(kw), 0) - - def test___exit___no_error_calls_patch(self): - connection = _Connection({'foo': 'Foo'}) - wrapped = self._makeWrapped(connection, '/path') - batch = self._makeOne(wrapped) - kw = connection._requested - with batch: - # deferred patching - wrapped._patch_properties({'foo': 'Foo'}) - wrapped._patch_properties({'bar': 'Baz'}) - wrapped._patch_properties({'foo': 'Qux'}) - self.assertEqual(len(kw), 0) - # exited w/o error -> call to the real '_patch_properties' - self.assertEqual(len(kw), 1) - self.assertEqual(kw[0]['method'], 'PATCH') - self.assertEqual(kw[0]['path'], '/path') - self.assertEqual(kw[0]['data'], {'foo': 'Qux', 'bar': 'Baz'}) - self.assertEqual(kw[0]['query_params'], {'projection': 'full'}) - - class Test__scalar_property(unittest2.TestCase): def _callFUT(self, fieldName):