Skip to content

Commit

Permalink
Removing HTTP requests from Bucket logging methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Mar 28, 2015
1 parent 4d69bb3 commit 74cb2b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
3 changes: 0 additions & 3 deletions gcloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,6 @@ def get_logging(self):
:returns: a dict w/ keys, ``logBucket`` and ``logObjectPrefix``
(if logging is enabled), or None (if not).
"""
self._reload_properties()
info = self.properties.get('logging')
if info is not None:
return info.copy()
Expand All @@ -573,15 +572,13 @@ def enable_logging(self, bucket_name, object_prefix=''):
"""
info = {'logBucket': bucket_name, 'logObjectPrefix': object_prefix}
self._patch_properties({'logging': info})
self.patch()

def disable_logging(self):
"""Disable access logging for this bucket.
See: https://cloud.google.com/storage/docs/accesslogs#disabling
"""
self._patch_properties({'logging': None})
self.patch()

@property
def metageneration(self):
Expand Down
22 changes: 10 additions & 12 deletions gcloud/storage/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ def test_get_logging_w_prefix(self):
resp_to_reload = before
connection = _Connection(resp_to_reload)
bucket = self._makeOne(NAME, connection)
bucket._reload_properties()
info = bucket.get_logging()
self.assertEqual(info['logBucket'], LOG_BUCKET)
self.assertEqual(info['logObjectPrefix'], LOG_PREFIX)
Expand All @@ -778,23 +779,22 @@ def test_enable_logging_defaults(self):
connection = _Connection(resp_to_reload, resp_to_enable_logging,
resp_to_enable_logging)
bucket = self._makeOne(NAME, connection, properties=before)
bucket._reload_properties()
self.assertTrue(bucket.get_logging() is None)
bucket.enable_logging(LOG_BUCKET)
info = bucket.get_logging()
bucket.patch()
self.assertEqual(info['logBucket'], LOG_BUCKET)
self.assertEqual(info['logObjectPrefix'], '')
kw = connection._requested
self.assertEqual(len(kw), 3)
self.assertEqual(len(kw), 2)
self.assertEqual(kw[0]['method'], 'GET')
self.assertEqual(kw[0]['path'], '/b/%s' % NAME)
self.assertEqual(kw[0]['query_params'], {'projection': 'noAcl'})
self.assertEqual(kw[1]['method'], 'PATCH')
self.assertEqual(kw[1]['path'], '/b/%s' % NAME)
self.assertEqual(kw[1]['data'], resp_to_enable_logging)
self.assertEqual(kw[1]['query_params'], {'projection': 'full'})
self.assertEqual(kw[2]['method'], 'GET')
self.assertEqual(kw[2]['path'], '/b/%s' % NAME)
self.assertEqual(kw[2]['query_params'], {'projection': 'noAcl'})

def test_enable_logging_explicit(self):
NAME = 'name'
Expand All @@ -809,23 +809,22 @@ def test_enable_logging_explicit(self):
resp_to_enable_logging,
resp_to_enable_logging)
bucket = self._makeOne(NAME, connection, properties=before)
bucket._reload_properties()
self.assertTrue(bucket.get_logging() is None)
bucket.enable_logging(LOG_BUCKET, LOG_PFX)
bucket.patch()
info = bucket.get_logging()
self.assertEqual(info['logBucket'], LOG_BUCKET)
self.assertEqual(info['logObjectPrefix'], LOG_PFX)
kw = connection._requested
self.assertEqual(len(kw), 3)
self.assertEqual(len(kw), 2)
self.assertEqual(kw[0]['method'], 'GET')
self.assertEqual(kw[0]['path'], '/b/%s' % NAME)
self.assertEqual(kw[0]['query_params'], {'projection': 'noAcl'})
self.assertEqual(kw[1]['method'], 'PATCH')
self.assertEqual(kw[1]['path'], '/b/%s' % NAME)
self.assertEqual(kw[1]['data'], resp_to_enable_logging)
self.assertEqual(kw[1]['query_params'], {'projection': 'full'})
self.assertEqual(kw[2]['method'], 'GET')
self.assertEqual(kw[2]['path'], '/b/%s' % NAME)
self.assertEqual(kw[2]['query_params'], {'projection': 'noAcl'})

def test_disable_logging(self):
NAME = 'name'
Expand All @@ -835,21 +834,20 @@ def test_disable_logging(self):
connection = _Connection(resp_to_reload, resp_to_disable_logging,
resp_to_disable_logging)
bucket = self._makeOne(NAME, connection, properties=before)
bucket._reload_properties()
self.assertTrue(bucket.get_logging() is not None)
bucket.disable_logging()
bucket.patch()
self.assertTrue(bucket.get_logging() is None)
kw = connection._requested
self.assertEqual(len(kw), 3)
self.assertEqual(len(kw), 2)
self.assertEqual(kw[0]['method'], 'GET')
self.assertEqual(kw[0]['path'], '/b/%s' % NAME)
self.assertEqual(kw[0]['query_params'], {'projection': 'noAcl'})
self.assertEqual(kw[1]['method'], 'PATCH')
self.assertEqual(kw[1]['path'], '/b/%s' % NAME)
self.assertEqual(kw[1]['data'], {'logging': None})
self.assertEqual(kw[1]['query_params'], {'projection': 'full'})
self.assertEqual(kw[2]['method'], 'GET')
self.assertEqual(kw[2]['path'], '/b/%s' % NAME)
self.assertEqual(kw[2]['query_params'], {'projection': 'noAcl'})

def test_metageneration(self):
METAGENERATION = 42
Expand Down

0 comments on commit 74cb2b0

Please sign in to comment.