Skip to content

Commit

Permalink
Merge pull request #1579 from tseaver/1575-bucket_location_at_create
Browse files Browse the repository at this point in the history
Pass mutated properties through to 'bucket.create' API call.
  • Loading branch information
tseaver committed Mar 9, 2016
2 parents 793b676 + 9e6dfee commit cf581cb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gcloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,12 @@ def create(self, client=None):
"""
client = self._require_client(client)
query_params = {'project': client.project}
properties = dict(
(key, self._properties[key]) for key in self._changes)
properties['name'] = self.name
api_response = client.connection.api_request(
method='POST', path='/b', query_params=query_params,
data={'name': self.name}, _target_object=self)
data=properties, _target_object=self)
self._set_properties(api_response)

@property
Expand Down
39 changes: 39 additions & 0 deletions gcloud/storage/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,45 @@ def test_create_hit(self):
self.assertEqual(kw['query_params'], {'project': PROJECT})
self.assertEqual(kw['data'], DATA)

def test_create_w_extra_properties(self):
BUCKET_NAME = 'bucket-name'
PROJECT = 'PROJECT'
CORS = [{
'maxAgeSeconds': 60,
'methods': ['*'],
'origin': ['https://example.com/frontend'],
'responseHeader': ['X-Custom-Header'],
}]
LIFECYCLE_RULES = [{
"action": {"type": "Delete"},
"condition": {"age": 365}
}]
LOCATION = 'eu'
STORAGE_CLASS = 'NEARLINE'
DATA = {
'name': BUCKET_NAME,
'cors': CORS,
'lifecycle': {'rule': LIFECYCLE_RULES},
'location': LOCATION,
'storageClass': STORAGE_CLASS,
'versioning': {'enabled': True},
}
connection = _Connection(DATA)
client = _Client(connection, project=PROJECT)
bucket = self._makeOne(client=client, name=BUCKET_NAME)
bucket.cors = CORS
bucket.lifecycle_rules = LIFECYCLE_RULES
bucket.location = LOCATION
bucket.storage_class = STORAGE_CLASS
bucket.versioning_enabled = True
bucket.create()

kw, = connection._requested
self.assertEqual(kw['method'], 'POST')
self.assertEqual(kw['path'], '/b')
self.assertEqual(kw['query_params'], {'project': PROJECT})
self.assertEqual(kw['data'], DATA)

def test_acl_property(self):
from gcloud.storage.acl import BucketACL
bucket = self._makeOne()
Expand Down

0 comments on commit cf581cb

Please sign in to comment.