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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

properties['name'] = self.name

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

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