Skip to content

Commit 2538110

Browse files
committed
Removing Connection.new_bucket.
1 parent 32b7853 commit 2538110

File tree

2 files changed

+11
-76
lines changed

2 files changed

+11
-76
lines changed

gcloud/storage/connection.py

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def get_bucket(self, bucket_name):
379379
:returns: The bucket matching the name provided.
380380
:raises: :class:`gcloud.exceptions.NotFound`
381381
"""
382-
bucket = self.new_bucket(bucket_name)
382+
bucket = Bucket(connection=self, name=bucket_name)
383383
response = self.api_request(method='GET', path=bucket.path)
384384
return Bucket(properties=response, connection=self)
385385

@@ -409,7 +409,7 @@ def lookup(self, bucket_name):
409409
except NotFound:
410410
return None
411411

412-
def create_bucket(self, bucket):
412+
def create_bucket(self, bucket_name):
413413
"""Create a new bucket.
414414
415415
For example::
@@ -420,34 +420,27 @@ def create_bucket(self, bucket):
420420
>>> print bucket
421421
<Bucket: my-bucket>
422422
423-
:type bucket: string or :class:`gcloud.storage.bucket.Bucket`
424-
:param bucket: The bucket name (or bucket object) to create.
423+
:type bucket_name: string
424+
:param bucket_name: The bucket name to create.
425425
426426
:rtype: :class:`gcloud.storage.bucket.Bucket`
427427
:returns: The newly created bucket.
428428
:raises: :class:`gcloud.exceptions.Conflict` if
429429
there is a confict (bucket already exists, invalid name, etc.)
430430
"""
431-
bucket = self.new_bucket(bucket)
432431
response = self.api_request(method='POST', path='/b',
433-
data={'name': bucket.name})
432+
data={'name': bucket_name})
434433
return Bucket(properties=response, connection=self)
435434

436-
def delete_bucket(self, bucket):
435+
def delete_bucket(self, bucket_name):
437436
"""Delete a bucket.
438437
439-
You can use this method to delete a bucket by name, or to delete
440-
a bucket object::
438+
You can use this method to delete a bucket by name.
441439
442440
>>> from gcloud import storage
443441
>>> connection = storage.get_connection(project)
444442
>>> connection.delete_bucket('my-bucket')
445443
446-
You can also delete pass in the bucket object::
447-
448-
>>> bucket = connection.get_bucket('other-bucket')
449-
>>> connection.delete_bucket(bucket)
450-
451444
If the bucket doesn't exist, this will raise a
452445
:class:`gcloud.exceptions.NotFound`::
453446
@@ -466,36 +459,11 @@ def delete_bucket(self, bucket):
466459
>>> except Conflict:
467460
>>> print 'That bucket is not empty!'
468461
469-
:type bucket: string or :class:`gcloud.storage.bucket.Bucket`
470-
:param bucket: The bucket name (or bucket object) to delete.
471-
"""
472-
bucket = self.new_bucket(bucket)
473-
self.api_request(method='DELETE', path=bucket.path)
474-
475-
def new_bucket(self, bucket):
476-
"""Factory method for creating a new (unsaved) bucket object.
477-
478-
This method is really useful when you're not sure whether you
479-
have an actual :class:`gcloud.storage.bucket.Bucket` object or
480-
just a name of a bucket. It always returns the object::
481-
482-
>>> bucket = connection.new_bucket('bucket')
483-
>>> print bucket
484-
<Bucket: bucket>
485-
>>> bucket = connection.new_bucket(bucket)
486-
>>> print bucket
487-
<Bucket: bucket>
488-
489-
:type bucket: string or :class:`gcloud.storage.bucket.Bucket`
490-
:param bucket: A name of a bucket or an existing Bucket object.
462+
:type bucket_name: string
463+
:param bucket_name: The bucket name to delete.
491464
"""
492-
if isinstance(bucket, Bucket):
493-
return bucket
494-
495-
if isinstance(bucket, six.string_types):
496-
return Bucket(connection=self, name=bucket)
497-
498-
raise TypeError('Invalid bucket: %s' % bucket)
465+
bucket_path = '/b/' + bucket_name
466+
self.api_request(method='DELETE', path=bucket_path)
499467

500468
def generate_signed_url(self, resource, expiration,
501469
method='GET', content_md5=None,

gcloud/storage/test_connection.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,6 @@ def test_create_bucket_ok(self):
505505
def test_delete_bucket_defaults_miss(self):
506506
_deleted_blobs = []
507507

508-
class _Bucket(object):
509-
510-
def __init__(self, name):
511-
self._name = name
512-
self.path = '/b/' + name
513-
514508
PROJECT = 'project'
515509
BLOB_NAME = 'blob-name'
516510
conn = self._makeOne(PROJECT)
@@ -526,38 +520,11 @@ def __init__(self, name):
526520
'{}',
527521
)
528522

529-
def _new_bucket(name):
530-
return _Bucket(name)
531-
532-
conn.new_bucket = _new_bucket
533523
self.assertEqual(conn.delete_bucket(BLOB_NAME), None)
534524
self.assertEqual(_deleted_blobs, [])
535525
self.assertEqual(http._called_with['method'], 'DELETE')
536526
self.assertEqual(http._called_with['uri'], URI)
537527

538-
def test_new_bucket_w_existing(self):
539-
from gcloud.storage.bucket import Bucket
540-
PROJECT = 'project'
541-
BLOB_NAME = 'blob-name'
542-
conn = self._makeOne(PROJECT)
543-
existing = Bucket(self, BLOB_NAME)
544-
self.assertTrue(conn.new_bucket(existing) is existing)
545-
546-
def test_new_bucket_w_blob(self):
547-
from gcloud.storage.bucket import Bucket
548-
PROJECT = 'project'
549-
BLOB_NAME = 'blob-name'
550-
conn = self._makeOne(PROJECT)
551-
bucket = conn.new_bucket(BLOB_NAME)
552-
self.assertTrue(isinstance(bucket, Bucket))
553-
self.assertTrue(bucket.connection is conn)
554-
self.assertEqual(bucket.name, BLOB_NAME)
555-
556-
def test_new_bucket_w_invalid(self):
557-
PROJECT = 'project'
558-
conn = self._makeOne(PROJECT)
559-
self.assertRaises(TypeError, conn.new_bucket, object())
560-
561528
def test_generate_signed_url_w_expiration_int(self):
562529
import base64
563530
import urlparse

0 commit comments

Comments
 (0)