Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8955180

Browse files
committed
Merge pull request googleapis#782 from dhermes/remove-property-batch
Removing _PropertyBatch from storage.
2 parents 65341ae + 968ed0d commit 8955180

File tree

2 files changed

+0
-125
lines changed

2 files changed

+0
-125
lines changed

gcloud/storage/_helpers.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,6 @@ def __init__(self, name=None):
4949
self._properties = {}
5050
self._changes = set()
5151

52-
@property
53-
def batch(self):
54-
"""Return a context manager which defers/batches updates.
55-
56-
E.g., to batch multiple updates to a bucket::
57-
58-
>>> with bucket.batch:
59-
... bucket.enable_versioning()
60-
... bucket.disable_website()
61-
62-
or for a blob::
63-
64-
>>> with blob.batch:
65-
... blob.content_type = 'image/jpeg'
66-
... blob.content_encoding = 'gzip'
67-
68-
Updates will be aggregated and sent as a single call to
69-
:meth:`_patch_properties` IFF the ``with`` block exits without
70-
an exception.
71-
72-
:rtype: :class:`_PropertyBatch`
73-
"""
74-
return _PropertyBatch(self)
75-
7652
def reload(self):
7753
"""Reload properties from Cloud Storage.
7854
@@ -123,24 +99,6 @@ def patch(self):
12399
return self
124100

125101

126-
class _PropertyBatch(object):
127-
"""Context manager: Batch updates to object.
128-
129-
:type wrapped: class derived from :class:`_PropertyMixin`.
130-
:param wrapped: the instance whose property updates to batch.
131-
"""
132-
def __init__(self, wrapped):
133-
self._wrapped = wrapped
134-
135-
def __enter__(self):
136-
"""Do nothing method. Needed to be a context manager."""
137-
138-
def __exit__(self, exc_type, value, traceback):
139-
"""Patch deferred property updates if no error."""
140-
if exc_type is None:
141-
self._wrapped.patch()
142-
143-
144102
def _scalar_property(fieldname):
145103
"""Create a property descriptor around the :class:`_PropertyMixin` helpers.
146104
"""

gcloud/storage/test__helpers.py

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,6 @@ def test_path_is_abstract(self):
4646
mixin = self._makeOne()
4747
self.assertRaises(NotImplementedError, lambda: mixin.path)
4848

49-
def test_batch(self):
50-
connection = _Connection({'foo': 'Qux', 'bar': 'Baz'})
51-
derived = self._derivedClass(connection, '/path')()
52-
with derived.batch:
53-
derived._patch_properties({'foo': 'Foo'})
54-
derived._patch_properties({'bar': 'Baz'})
55-
derived._patch_properties({'foo': 'Qux'})
56-
kw = connection._requested
57-
self.assertEqual(len(kw), 1)
58-
self.assertEqual(kw[0]['method'], 'PATCH')
59-
self.assertEqual(kw[0]['path'], '/path')
60-
self.assertEqual(kw[0]['data'], {'foo': 'Qux', 'bar': 'Baz'})
61-
self.assertEqual(kw[0]['query_params'], {'projection': 'full'})
62-
6349
def test_reload(self):
6450
connection = _Connection({'foo': 'Foo'})
6551
derived = self._derivedClass(connection, '/path')()
@@ -84,75 +70,6 @@ def test__patch_properties(self):
8470
self.assertEqual(kw[0]['query_params'], {'projection': 'full'})
8571

8672

87-
class Test_PropertyBatch(unittest2.TestCase):
88-
89-
def _getTargetClass(self):
90-
from gcloud.storage._helpers import _PropertyBatch
91-
return _PropertyBatch
92-
93-
def _makeOne(self, wrapped):
94-
return self._getTargetClass()(wrapped)
95-
96-
def _makeWrapped(self, connection=None, path=None):
97-
from gcloud.storage._helpers import _PropertyMixin
98-
99-
class Wrapped(_PropertyMixin):
100-
101-
@property
102-
def connection(self):
103-
return connection
104-
105-
@property
106-
def path(self):
107-
return path
108-
109-
return Wrapped()
110-
111-
def test_ctor_does_not_intercept__patch_properties(self):
112-
wrapped = self._makeWrapped()
113-
before = wrapped._patch_properties
114-
batch = self._makeOne(wrapped)
115-
after = wrapped._patch_properties
116-
self.assertEqual(before, after)
117-
self.assertTrue(batch._wrapped is wrapped)
118-
119-
def test___exit___w_error_skips_patch(self):
120-
class Testing(Exception):
121-
pass
122-
connection = _Connection()
123-
wrapped = self._makeWrapped(connection)
124-
batch = self._makeOne(wrapped)
125-
try:
126-
with batch:
127-
# deferred patching
128-
wrapped._patch_properties({'foo': 'Foo'})
129-
# but error -> no call to the real '_patch_properties'
130-
raise Testing('testing')
131-
except Testing:
132-
pass
133-
134-
kw = connection._requested
135-
self.assertEqual(len(kw), 0)
136-
137-
def test___exit___no_error_calls_patch(self):
138-
connection = _Connection({'foo': 'Foo'})
139-
wrapped = self._makeWrapped(connection, '/path')
140-
batch = self._makeOne(wrapped)
141-
kw = connection._requested
142-
with batch:
143-
# deferred patching
144-
wrapped._patch_properties({'foo': 'Foo'})
145-
wrapped._patch_properties({'bar': 'Baz'})
146-
wrapped._patch_properties({'foo': 'Qux'})
147-
self.assertEqual(len(kw), 0)
148-
# exited w/o error -> call to the real '_patch_properties'
149-
self.assertEqual(len(kw), 1)
150-
self.assertEqual(kw[0]['method'], 'PATCH')
151-
self.assertEqual(kw[0]['path'], '/path')
152-
self.assertEqual(kw[0]['data'], {'foo': 'Qux', 'bar': 'Baz'})
153-
self.assertEqual(kw[0]['query_params'], {'projection': 'full'})
154-
155-
15673
class Test__scalar_property(unittest2.TestCase):
15774

15875
def _callFUT(self, fieldName):

0 commit comments

Comments
 (0)