Skip to content

Commit 0353e2a

Browse files
committed
Support 'user_project' in '{Bucket,Blob}.update' (#4075)
Closes #4074.
1 parent 92b1392 commit 0353e2a

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

storage/google/cloud/storage/_helpers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,12 @@ def update(self, client=None):
170170
``client`` stored on the current object.
171171
"""
172172
client = self._require_client(client)
173+
query_params = {'projection': 'full'}
174+
if self.user_project is not None:
175+
query_params['userProject'] = self.user_project
173176
api_response = client._connection.api_request(
174177
method='PUT', path=self.path, data=self._properties,
175-
query_params={'projection': 'full'}, _target_object=self)
178+
query_params=query_params, _target_object=self)
176179
self._set_properties(api_response)
177180

178181

storage/tests/unit/test__helpers.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,31 @@ def test_update(self):
183183
# Make sure changes get reset by patch().
184184
self.assertEqual(derived._changes, set())
185185

186+
def test_update_w_user_project(self):
187+
user_project = 'user-project-123'
188+
connection = _Connection({'foo': 'Foo'})
189+
client = _Client(connection)
190+
derived = self._derivedClass('/path', user_project)()
191+
# Make sure changes is non-empty, so we can observe a change.
192+
BAR = object()
193+
BAZ = object()
194+
derived._properties = {'bar': BAR, 'baz': BAZ}
195+
derived._changes = set(['bar']) # Update sends 'baz' anyway.
196+
derived.update(client=client)
197+
self.assertEqual(derived._properties, {'foo': 'Foo'})
198+
kw = connection._requested
199+
self.assertEqual(len(kw), 1)
200+
self.assertEqual(kw[0]['method'], 'PUT')
201+
self.assertEqual(kw[0]['path'], '/path')
202+
self.assertEqual(
203+
kw[0]['query_params'], {
204+
'projection': 'full',
205+
'userProject': user_project,
206+
})
207+
self.assertEqual(kw[0]['data'], {'bar': BAR, 'baz': BAZ})
208+
# Make sure changes get reset by patch().
209+
self.assertEqual(derived._changes, set())
210+
186211

187212
class Test__scalar_property(unittest.TestCase):
188213

0 commit comments

Comments
 (0)