Skip to content

Commit 7c7745f

Browse files
committed
Map 'Bucket.location' to a simple, scalar property.
1 parent 37046e2 commit 7c7745f

File tree

2 files changed

+13
-35
lines changed

2 files changed

+13
-35
lines changed

gcloud/storage/bucket.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44

55
from gcloud.storage._helpers import _PropertyMixin
6+
from gcloud.storage._helpers import _scalar_property
67
from gcloud.storage import exceptions
78
from gcloud.storage.acl import BucketACL
89
from gcloud.storage.acl import DefaultObjectACL
@@ -28,7 +29,7 @@ class Bucket(_PropertyMixin):
2829
'etag': 'etag',
2930
'id': 'id',
3031
'lifecycle': 'get_lifecycle()',
31-
'location': 'get_location()',
32+
'location': 'location',
3233
'logging': 'get_logging()',
3334
'metageneration': 'metageneration',
3435
'name': 'name',
@@ -436,27 +437,14 @@ def update_lifecycle(self, rules):
436437
"""
437438
self._patch_properties({'lifecycle': {'rule': rules}})
438439

439-
def get_location(self):
440-
"""Retrieve location configured for this bucket.
440+
location = _scalar_property('location')
441+
"""Retrieve location configured for this bucket.
441442
442-
See: https://cloud.google.com/storage/docs/json_api/v1/buckets and
443-
https://cloud.google.com/storage/docs/concepts-techniques#specifyinglocations
444-
445-
:rtype: string
446-
:returns: The configured location.
447-
"""
448-
return self.properties.get('location')
449-
450-
def set_location(self, location):
451-
"""Update location configured for this bucket.
443+
See: https://cloud.google.com/storage/docs/json_api/v1/buckets and
444+
https://cloud.google.com/storage/docs/concepts-techniques#specifyinglocations
452445
453-
See: https://cloud.google.com/storage/docs/json_api/v1/buckets and
454-
https://cloud.google.com/storage/docs/concepts-techniques#specifyinglocations
455-
456-
:type location: string
457-
:param location: The new configured location.
458-
"""
459-
self._patch_properties({'location': location})
446+
:rtype: string
447+
"""
460448

461449
def get_logging(self):
462450
"""Return info about access logging for this bucket.

gcloud/storage/test_bucket.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -562,31 +562,21 @@ def test_update_lifecycle(self):
562562
self.assertEqual(entries[0]['action']['type'], 'Delete')
563563
self.assertEqual(entries[0]['condition']['age'], 42)
564564

565-
def test_get_location_eager(self):
565+
def test_location_getter(self):
566566
NAME = 'name'
567567
connection = _Connection()
568568
before = {'location': 'AS'}
569569
bucket = self._makeOne(connection, NAME, before)
570-
self.assertEqual(bucket.get_location(), 'AS')
570+
self.assertEqual(bucket.location, 'AS')
571571
kw = connection._requested
572572
self.assertEqual(len(kw), 0)
573573

574-
def test_get_location_lazy(self):
574+
def test_location_setter(self):
575575
NAME = 'name'
576576
connection = _Connection({'location': 'AS'})
577577
bucket = self._makeOne(connection, NAME)
578-
self.assertEqual(bucket.get_location(), 'AS')
579-
kw = connection._requested
580-
self.assertEqual(len(kw), 1)
581-
self.assertEqual(kw[0]['method'], 'GET')
582-
self.assertEqual(kw[0]['path'], '/b/%s' % NAME)
583-
584-
def test_update_location(self):
585-
NAME = 'name'
586-
connection = _Connection({'location': 'AS'})
587-
bucket = self._makeOne(connection, NAME)
588-
bucket.set_location('AS')
589-
self.assertEqual(bucket.get_location(), 'AS')
578+
bucket.location = 'AS'
579+
self.assertEqual(bucket.location, 'AS')
590580
kw = connection._requested
591581
self.assertEqual(len(kw), 1)
592582
self.assertEqual(kw[0]['method'], 'PATCH')

0 commit comments

Comments
 (0)