Skip to content

Commit

Permalink
Map 'Bucket.location' to a simple, scalar property.
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver committed Nov 7, 2014
1 parent 37046e2 commit 7c7745f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 35 deletions.
28 changes: 8 additions & 20 deletions gcloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os

from gcloud.storage._helpers import _PropertyMixin
from gcloud.storage._helpers import _scalar_property
from gcloud.storage import exceptions
from gcloud.storage.acl import BucketACL
from gcloud.storage.acl import DefaultObjectACL
Expand All @@ -28,7 +29,7 @@ class Bucket(_PropertyMixin):
'etag': 'etag',
'id': 'id',
'lifecycle': 'get_lifecycle()',
'location': 'get_location()',
'location': 'location',
'logging': 'get_logging()',
'metageneration': 'metageneration',
'name': 'name',
Expand Down Expand Up @@ -436,27 +437,14 @@ def update_lifecycle(self, rules):
"""
self._patch_properties({'lifecycle': {'rule': rules}})

def get_location(self):
"""Retrieve location configured for this bucket.
location = _scalar_property('location')
"""Retrieve location configured for this bucket.
See: https://cloud.google.com/storage/docs/json_api/v1/buckets and
https://cloud.google.com/storage/docs/concepts-techniques#specifyinglocations
:rtype: string
:returns: The configured location.
"""
return self.properties.get('location')

def set_location(self, location):
"""Update location configured for this bucket.
See: https://cloud.google.com/storage/docs/json_api/v1/buckets and
https://cloud.google.com/storage/docs/concepts-techniques#specifyinglocations
See: https://cloud.google.com/storage/docs/json_api/v1/buckets and
https://cloud.google.com/storage/docs/concepts-techniques#specifyinglocations
:type location: string
:param location: The new configured location.
"""
self._patch_properties({'location': location})
:rtype: string
"""

def get_logging(self):
"""Return info about access logging for this bucket.
Expand Down
20 changes: 5 additions & 15 deletions gcloud/storage/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,31 +562,21 @@ def test_update_lifecycle(self):
self.assertEqual(entries[0]['action']['type'], 'Delete')
self.assertEqual(entries[0]['condition']['age'], 42)

def test_get_location_eager(self):
def test_location_getter(self):
NAME = 'name'
connection = _Connection()
before = {'location': 'AS'}
bucket = self._makeOne(connection, NAME, before)
self.assertEqual(bucket.get_location(), 'AS')
self.assertEqual(bucket.location, 'AS')
kw = connection._requested
self.assertEqual(len(kw), 0)

def test_get_location_lazy(self):
def test_location_setter(self):
NAME = 'name'
connection = _Connection({'location': 'AS'})
bucket = self._makeOne(connection, NAME)
self.assertEqual(bucket.get_location(), 'AS')
kw = connection._requested
self.assertEqual(len(kw), 1)
self.assertEqual(kw[0]['method'], 'GET')
self.assertEqual(kw[0]['path'], '/b/%s' % NAME)

def test_update_location(self):
NAME = 'name'
connection = _Connection({'location': 'AS'})
bucket = self._makeOne(connection, NAME)
bucket.set_location('AS')
self.assertEqual(bucket.get_location(), 'AS')
bucket.location = 'AS'
self.assertEqual(bucket.location, 'AS')
kw = connection._requested
self.assertEqual(len(kw), 1)
self.assertEqual(kw[0]['method'], 'PATCH')
Expand Down

0 comments on commit 7c7745f

Please sign in to comment.