FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Making _PropertyMixin.patch() and reload() reset the changes. by dhermes · Pull Request #789 · googleapis/google-cloud-python · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 4 additions & 0 deletions gcloud/storage/_helpers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def reload(self):
query_params = {'projection': 'noAcl'}
self._properties = self.connection.api_request(
method='GET', path=self.path, query_params=query_params)
# If the api_request succeeded, we reset changes.
self._changes = set()

def _patch_properties(self, properties):
"""Update particular fields of this object's properties.
Expand Down Expand Up @@ -84,6 +86,8 @@ def patch(self):
self._properties = self.connection.api_request(
method='PATCH', path=self.path, data=update_properties,
query_params={'projection': 'full'})
# If the api_request succeeded, we reset changes.
self._changes = set()


def _scalar_property(fieldname):
Expand Down
24 changes: 24 additions & 0 deletions gcloud/storage/test__helpers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ def test_path_is_abstract(self):
def test_reload(self):
connection = _Connection({'foo': 'Foo'})
derived = self._derivedClass(connection, '/path')()
# Make sure changes is not a set, so we can observe a change.
derived._changes = object()
derived.reload()
self.assertEqual(derived._properties, {'foo': 'Foo'})
kw = connection._requested
self.assertEqual(len(kw), 1)
self.assertEqual(kw[0]['method'], 'GET')
self.assertEqual(kw[0]['path'], '/path')
self.assertEqual(kw[0]['query_params'], {'projection': 'noAcl'})
# Make sure changes get reset by reload.
self.assertEqual(derived._changes, set())

def test__patch_properties(self):
connection = _Connection({'foo': 'Foo'})
Expand All @@ -69,6 +73,26 @@ def test__patch_properties(self):
self.assertEqual(kw[0]['data'], {'foo': 'Foo'})
self.assertEqual(kw[0]['query_params'], {'projection': 'full'})

def test_patch(self):
connection = _Connection({'foo': 'Foo'})
derived = self._derivedClass(connection, '/path')()
# Make sure changes is non-empty, so we can observe a change.
BAR = object()
BAZ = object()
derived._properties = {'bar': BAR, 'baz': BAZ}
derived._changes = set(['bar']) # Ignore baz.
derived.patch()
self.assertEqual(derived._properties, {'foo': 'Foo'})
kw = connection._requested
self.assertEqual(len(kw), 1)
self.assertEqual(kw[0]['method'], 'PATCH')
self.assertEqual(kw[0]['path'], '/path')
self.assertEqual(kw[0]['query_params'], {'projection': 'full'})
# Since changes does not include `baz`, we don't see it sent.
self.assertEqual(kw[0]['data'], {'bar': BAR})
# Make sure changes get reset by patch().
self.assertEqual(derived._changes, set())


class Test__scalar_property(unittest2.TestCase):

Expand Down

Back | FazBrowse Home | New Git URL