Skip to content

Commit c4eb080

Browse files
committed
Removing Connection.lookup in storage.
1 parent 9518db7 commit c4eb080

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
@@ -86,7 +86,11 @@ def __iter__(self):
8686
return iter(_BucketIterator(connection=self))
8787

8888
def __contains__(self, bucket_name):
89-
return self.lookup(bucket_name) is not None
89+
try:
90+
self.get_bucket(bucket_name)
91+
return True
92+
except NotFound:
93+
return False
9094

9195
def build_api_url(self, path, query_params=None, api_base_url=None,
9296
api_version=None, upload=False):
@@ -274,10 +278,7 @@ def get_bucket(self, bucket_name):
274278
"""Get a bucket by name.
275279
276280
If the bucket isn't found, this will raise a
277-
:class:`gcloud.exceptions.NotFound`. If you would
278-
rather get a bucket by name, and return ``None`` if the bucket
279-
isn't found (like ``{}.get('...')``) then use
280-
:func:`Connection.lookup`.
281+
:class:`gcloud.storage.exceptions.NotFound`.
281282
282283
For example::
283284
@@ -300,32 +301,6 @@ def get_bucket(self, bucket_name):
300301
response = self.api_request(method='GET', path=bucket.path)
301302
return Bucket(properties=response, connection=self)
302303

303-
def lookup(self, bucket_name):
304-
"""Get a bucket by name, returning None if not found.
305-
306-
You can use this if you would rather checking for a None value
307-
than catching an exception::
308-
309-
>>> from gcloud import storage
310-
>>> connection = storage.get_connection(project)
311-
>>> bucket = connection.get_bucket('doesnt-exist')
312-
>>> print bucket
313-
None
314-
>>> bucket = connection.get_bucket('my-bucket')
315-
>>> print bucket
316-
<Bucket: my-bucket>
317-
318-
:type bucket_name: string
319-
:param bucket_name: The name of the bucket to get.
320-
321-
:rtype: :class:`gcloud.storage.bucket.Bucket`
322-
:returns: The bucket matching the name provided or None if not found.
323-
"""
324-
try:
325-
return self.get_bucket(bucket_name)
326-
except NotFound:
327-
return None
328-
329304
def create_bucket(self, bucket_name):
330305
"""Create a new bucket.
331306

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)