Skip to content

Commit 41223d0

Browse files
committed
Removing Connection.new_bucket.
1 parent e80958a commit 41223d0

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
@@ -296,7 +296,7 @@ def get_bucket(self, bucket_name):
296296
:returns: The bucket matching the name provided.
297297
:raises: :class:`gcloud.exceptions.NotFound`
298298
"""
299-
bucket = self.new_bucket(bucket_name)
299+
bucket = Bucket(connection=self, name=bucket_name)
300300
response = self.api_request(method='GET', path=bucket.path)
301301
return Bucket(properties=response, connection=self)
302302

@@ -326,7 +326,7 @@ def lookup(self, bucket_name):
326326
except NotFound:
327327
return None
328328

329-
def create_bucket(self, bucket):
329+
def create_bucket(self, bucket_name):
330330
"""Create a new bucket.
331331
332332
For example::
@@ -337,34 +337,27 @@ def create_bucket(self, bucket):
337337
>>> print bucket
338338
<Bucket: my-bucket>
339339
340-
:type bucket: string or :class:`gcloud.storage.bucket.Bucket`
341-
:param bucket: The bucket name (or bucket object) to create.
340+
:type bucket_name: string
341+
:param bucket_name: The bucket name to create.
342342
343343
:rtype: :class:`gcloud.storage.bucket.Bucket`
344344
:returns: The newly created bucket.
345345
:raises: :class:`gcloud.exceptions.Conflict` if
346346
there is a confict (bucket already exists, invalid name, etc.)
347347
"""
348-
bucket = self.new_bucket(bucket)
349348
response = self.api_request(method='POST', path='/b',
350-
data={'name': bucket.name})
349+
data={'name': bucket_name})
351350
return Bucket(properties=response, connection=self)
352351

353-
def delete_bucket(self, bucket):
352+
def delete_bucket(self, bucket_name):
354353
"""Delete a bucket.
355354
356-
You can use this method to delete a bucket by name, or to delete
357-
a bucket object::
355+
You can use this method to delete a bucket by name.
358356
359357
>>> from gcloud import storage
360358
>>> connection = storage.get_connection(project)
361359
>>> connection.delete_bucket('my-bucket')
362360
363-
You can also delete pass in the bucket object::
364-
365-
>>> bucket = connection.get_bucket('other-bucket')
366-
>>> connection.delete_bucket(bucket)
367-
368361
If the bucket doesn't exist, this will raise a
369362
:class:`gcloud.exceptions.NotFound`::
370363
@@ -383,36 +376,11 @@ def delete_bucket(self, bucket):
383376
>>> except Conflict:
384377
>>> print 'That bucket is not empty!'
385378
386-
:type bucket: string or :class:`gcloud.storage.bucket.Bucket`
387-
:param bucket: The bucket name (or bucket object) to delete.
388-
"""
389-
bucket = self.new_bucket(bucket)
390-
self.api_request(method='DELETE', path=bucket.path)
391-
392-
def new_bucket(self, bucket):
393-
"""Factory method for creating a new (unsaved) bucket object.
394-
395-
This method is really useful when you're not sure whether you
396-
have an actual :class:`gcloud.storage.bucket.Bucket` object or
397-
just a name of a bucket. It always returns the object::
398-
399-
>>> bucket = connection.new_bucket('bucket')
400-
>>> print bucket
401-
<Bucket: bucket>
402-
>>> bucket = connection.new_bucket(bucket)
403-
>>> print bucket
404-
<Bucket: bucket>
405-
406-
:type bucket: string or :class:`gcloud.storage.bucket.Bucket`
407-
:param bucket: A name of a bucket or an existing Bucket object.
379+
:type bucket_name: string
380+
:param bucket_name: The bucket name to delete.
408381
"""
409-
if isinstance(bucket, Bucket):
410-
return bucket
411-
412-
if isinstance(bucket, six.string_types):
413-
return Bucket(connection=self, name=bucket)
414-
415-
raise TypeError('Invalid bucket: %s' % bucket)
382+
bucket_path = '/b/' + bucket_name
383+
self.api_request(method='DELETE', path=bucket_path)
416384

417385

418386
class _BucketIterator(Iterator):

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

562529
class Test__BucketIterator(unittest2.TestCase):
563530

0 commit comments

Comments
 (0)