Skip to content

Commit c506be0

Browse files
committed
Removing Connection.lookup in storage.
1 parent 32b7853 commit c506be0

File tree

2 files changed

+6
-73
lines changed

2 files changed

+6
-73
lines changed

gcloud/storage/connection.py

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ def __iter__(self):
169169
return iter(_BucketIterator(connection=self))
170170

171171
def __contains__(self, bucket_name):
172-
return self.lookup(bucket_name) is not None
172+
try:
173+
self.get_bucket(bucket_name)
174+
return True
175+
except NotFound:
176+
return False
173177

174178
def build_api_url(self, path, query_params=None, api_base_url=None,
175179
api_version=None, upload=False):
@@ -357,10 +361,7 @@ def get_bucket(self, bucket_name):
357361
"""Get a bucket by name.
358362
359363
If the bucket isn't found, this will raise a
360-
:class:`gcloud.exceptions.NotFound`. If you would
361-
rather get a bucket by name, and return ``None`` if the bucket
362-
isn't found (like ``{}.get('...')``) then use
363-
:func:`Connection.lookup`.
364+
:class:`gcloud.storage.exceptions.NotFound`.
364365
365366
For example::
366367
@@ -383,32 +384,6 @@ def get_bucket(self, bucket_name):
383384
response = self.api_request(method='GET', path=bucket.path)
384385
return Bucket(properties=response, connection=self)
385386

386-
def lookup(self, bucket_name):
387-
"""Get a bucket by name, returning None if not found.
388-
389-
You can use this if you would rather checking for a None value
390-
than catching an exception::
391-
392-
>>> from gcloud import storage
393-
>>> connection = storage.get_connection(project)
394-
>>> bucket = connection.get_bucket('doesnt-exist')
395-
>>> print bucket
396-
None
397-
>>> bucket = connection.get_bucket('my-bucket')
398-
>>> print bucket
399-
<Bucket: my-bucket>
400-
401-
:type bucket_name: string
402-
:param bucket_name: The name of the bucket to get.
403-
404-
:rtype: :class:`gcloud.storage.bucket.Bucket`
405-
:returns: The bucket matching the name provided or None if not found.
406-
"""
407-
try:
408-
return self.get_bucket(bucket_name)
409-
except NotFound:
410-
return None
411-
412387
def create_bucket(self, bucket):
413388
"""Create a new bucket.
414389

gcloud/storage/test_connection.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -438,48 +438,6 @@ def test_get_bucket_hit(self):
438438
self.assertEqual(http._called_with['method'], 'GET')
439439
self.assertEqual(http._called_with['uri'], URI)
440440

441-
def test_lookup_miss(self):
442-
PROJECT = 'project'
443-
NONESUCH = 'nonesuch'
444-
conn = self._makeOne(PROJECT)
445-
URI = '/'.join([
446-
conn.API_BASE_URL,
447-
'storage',
448-
conn.API_VERSION,
449-
'b',
450-
'nonesuch?project=%s' % PROJECT,
451-
])
452-
http = conn._http = Http(
453-
{'status': '404', 'content-type': 'application/json'},
454-
'{}',
455-
)
456-
self.assertEqual(conn.lookup(NONESUCH), None)
457-
self.assertEqual(http._called_with['method'], 'GET')
458-
self.assertEqual(http._called_with['uri'], URI)
459-
460-
def test_lookup_hit(self):
461-
from gcloud.storage.bucket import Bucket
462-
PROJECT = 'project'
463-
BLOB_NAME = 'blob-name'
464-
conn = self._makeOne(PROJECT)
465-
URI = '/'.join([
466-
conn.API_BASE_URL,
467-
'storage',
468-
conn.API_VERSION,
469-
'b',
470-
'%s?project=%s' % (BLOB_NAME, PROJECT),
471-
])
472-
http = conn._http = Http(
473-
{'status': '200', 'content-type': 'application/json'},
474-
'{"name": "%s"}' % BLOB_NAME,
475-
)
476-
bucket = conn.lookup(BLOB_NAME)
477-
self.assertTrue(isinstance(bucket, Bucket))
478-
self.assertTrue(bucket.connection is conn)
479-
self.assertEqual(bucket.name, BLOB_NAME)
480-
self.assertEqual(http._called_with['method'], 'GET')
481-
self.assertEqual(http._called_with['uri'], URI)
482-
483441
def test_create_bucket_ok(self):
484442
from gcloud.storage.bucket import Bucket
485443
PROJECT = 'project'

0 commit comments

Comments
 (0)