Skip to content

Commit

Permalink
Updating docs, demo and system tests after storage.api deletion.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Jul 7, 2015
1 parent 1550100 commit 1b1fb11
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 47 deletions.
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ how to create a bucket.
.. code:: python
from gcloud import storage
bucket = storage.get_bucket('bucket-id-here')
client = storage.Client()
bucket = client.get_bucket('bucket-id-here')
# Then do other things...
blob = bucket.get_blob('/remote/path/to/file.txt')
print blob.download_as_string()
Expand Down
6 changes: 3 additions & 3 deletions docs/_components/storage-getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bucket.

Let's create a bucket:

>>> bucket = storage.create_bucket('test', project_name, connection=connection)
>>> bucket = client.create_bucket('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "gcloud/storage/connection.py", line 340, in create_bucket
Expand Down Expand Up @@ -184,8 +184,8 @@ If you have a full bucket, you can delete it this way::
Listing available buckets
-------------------------

>>> for bucket in storage.list_buckets(connection):
... print bucket.name
>>> for bucket in client.list_buckets():
... print bucket.name

Managing access control
-----------------------
Expand Down
4 changes: 2 additions & 2 deletions docs/_components/storage-quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ Once you have the connection,
you can create buckets and blobs::

>>> from gcloud import storage
>>> storage.list_buckets(connection)
>>> client.list_buckets()
[<Bucket: ...>, ...]
>>> bucket = storage.create_bucket('my-new-bucket', connection=connection)
>>> bucket = client.create_bucket('my-new-bucket')
>>> print bucket
<Bucket: my-new-bucket>
>>> blob = storage.Blob('my-test-file.txt', bucket=bucket)
Expand Down
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Cloud Storage
.. code-block:: python
from gcloud import storage
bucket = storage.get_bucket('<your-bucket-name>')
client = storage.Client()
bucket = client.get_bucket('<your-bucket-name>')
blob = storage.Blob('my-test-file.txt', bucket=bucket)
blob = blob.upload_contents_from_string('this is test content!')
4 changes: 3 additions & 1 deletion gcloud/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
You'll typically use these to get started with the API:
>>> from gcloud import storage
>>> bucket = storage.get_bucket('bucket-id-here')
>>> client = storage.Client()
>>> bucket = client.get_bucket('bucket-id-here')
>>> # Then do other things...
>>> blob = bucket.get_blob('/remote/path/to/file.txt')
>>> print blob.download_as_string()
Expand Down Expand Up @@ -50,6 +51,7 @@
from gcloud.storage.batch import Batch
from gcloud.storage.blob import Blob
from gcloud.storage.bucket import Bucket
from gcloud.storage.client import Client
from gcloud.storage.connection import SCOPE
from gcloud.storage.connection import Connection

Expand Down
4 changes: 2 additions & 2 deletions gcloud/storage/acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
:func:`gcloud.storage.bucket.Bucket.acl`::
>>> from gcloud import storage
>>> connection = storage.get_connection()
>>> bucket = storage.get_bucket(bucket_name, connection=connection)
>>> client = storage.Client()
>>> bucket = client.get_bucket(bucket_name)
>>> acl = bucket.acl
Adding and removing permissions can be done with the following methods
Expand Down
28 changes: 14 additions & 14 deletions gcloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ def get_blob(self, blob_name, connection=None):
This will return None if the blob doesn't exist::
>>> from gcloud import storage
>>> connection = storage.get_connection()
>>> bucket = storage.get_bucket('my-bucket', connection=connection)
>>> client = storage.Client()
>>> bucket = client.get_bucket('my-bucket')
>>> print bucket.get_blob('/path/to/blob.txt')
<Blob: my-bucket, /path/to/blob.txt>
>>> print bucket.get_blob('/does-not-exist.txt')
Expand Down Expand Up @@ -356,8 +356,8 @@ def delete_blob(self, blob_name, connection=None):
>>> from gcloud.exceptions import NotFound
>>> from gcloud import storage
>>> connection = storage.get_connection()
>>> bucket = storage.get_bucket('my-bucket', connection=connection)
>>> client = storage.Client()
>>> bucket = client.get_bucket('my-bucket')
>>> print bucket.list_blobs()
[<Blob: my-bucket, my-file.txt>]
>>> bucket.delete_blob('my-file.txt')
Expand Down Expand Up @@ -463,8 +463,8 @@ def upload_file(self, filename, blob_name=None, connection=None):
For example::
>>> from gcloud import storage
>>> connection = storage.get_connection()
>>> bucket = storage.get_bucket('my-bucket', connection=connection)
>>> client = storage.Client()
>>> bucket = client.get_bucket('my-bucket')
>>> bucket.upload_file('~/my-file.txt', 'remote-text-file.txt')
>>> print bucket.list_blobs()
[<Blob: my-bucket, remote-text-file.txt>]
Expand All @@ -473,8 +473,8 @@ def upload_file(self, filename, blob_name=None, connection=None):
using the local filename (**not** the complete path)::
>>> from gcloud import storage
>>> connection = storage.get_connection()
>>> bucket = storage.get_bucket('my-bucket', connection=connection)
>>> client = storage.Client()
>>> bucket = client.get_bucket('my-bucket')
>>> bucket.upload_file('~/my-file.txt')
>>> print bucket.list_blobs()
[<Blob: my-bucket, my-file.txt>]
Expand Down Expand Up @@ -510,8 +510,8 @@ def upload_file_object(self, file_obj, blob_name=None, connection=None):
For example::
>>> from gcloud import storage
>>> connection = storage.get_connection()
>>> bucket = storage.get_bucket('my-bucket', connection=connection)
>>> client = storage.Client()
>>> bucket = client.get_bucket('my-bucket')
>>> bucket.upload_file(open('~/my-file.txt'), 'remote-text-file.txt')
>>> print bucket.list_blobs()
[<Blob: my-bucket, remote-text-file.txt>]
Expand All @@ -520,8 +520,8 @@ def upload_file_object(self, file_obj, blob_name=None, connection=None):
using the local filename (**not** the complete path)::
>>> from gcloud import storage
>>> connection = storage.get_connection()
>>> bucket = storage.get_bucket('my-bucket', connection=connection)
>>> client = storage.Client()
>>> bucket = client.get_bucket('my-bucket')
>>> bucket.upload_file(open('~/my-file.txt'))
>>> print bucket.list_blobs()
[<Blob: my-bucket, my-file.txt>]
Expand Down Expand Up @@ -788,8 +788,8 @@ def configure_website(self, main_page_suffix=None, not_found_page=None):
of an index page and a page to use when a blob isn't found::
>>> from gcloud import storage
>>> connection = storage.get_connection()
>>> bucket = storage.get_bucket(bucket_name, connection=connection)
>>> client = storage.Client()
>>> bucket = client.get_bucket(bucket_name)
>>> bucket.configure_website('index.html', '404.html')
You probably should also make the whole bucket public::
Expand Down
13 changes: 1 addition & 12 deletions gcloud/storage/demo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,7 @@
# limitations under the License.

import os
from gcloud import storage

__all__ = ['create_bucket', 'list_buckets', 'PROJECT_ID']
__all__ = ['PROJECT_ID']

PROJECT_ID = os.getenv('GCLOUD_TESTS_PROJECT_ID')


def list_buckets(connection):
return list(storage.list_buckets(project=PROJECT_ID,
connection=connection))


def create_bucket(bucket_name, connection):
return storage.create_bucket(bucket_name, PROJECT_ID,
connection=connection)
10 changes: 5 additions & 5 deletions gcloud/storage/demo/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Let's start by importing the demo module and getting a connection:
# Let's start by importing the demo module and getting a client:
import time

from gcloud import storage
from gcloud.storage import demo

connection = storage.get_connection()
client = storage.Client(project=demo.PROJECT_ID)

# OK, now let's look at all of the buckets...
print(list(demo.list_buckets(connection))) # This might take a second...
print(list(client.list_buckets())) # This might take a second...

# Now let's create a new bucket...
bucket_name = ("bucket-%s" % time.time()).replace(".", "") # Get rid of dots.
print(bucket_name)
bucket = demo.create_bucket(bucket_name, connection)
bucket = client.create_bucket(bucket_name)
print(bucket)

# Let's look at all of the buckets again...
print(list(demo.list_buckets(connection)))
print(list(client.list_buckets()))

# How about we create a new blob inside this bucket.
blob = storage.Blob("my-new-file.txt", bucket=bucket)
Expand Down
13 changes: 7 additions & 6 deletions system_tests/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
SHARED_BUCKETS = {}

_helpers._PROJECT_ENV_VAR_NAME = 'GCLOUD_TESTS_PROJECT_ID'
CLIENT = storage.Client()


def setUpModule():
Expand All @@ -36,7 +37,7 @@ def setUpModule():
bucket_name = 'new%d' % (1000 * time.time(),)
# In the **very** rare case the bucket name is reserved, this
# fails with a ConnectionError.
SHARED_BUCKETS['test_bucket'] = storage.create_bucket(bucket_name)
SHARED_BUCKETS['test_bucket'] = CLIENT.create_bucket(bucket_name)


def tearDownModule():
Expand All @@ -57,24 +58,24 @@ def tearDown(self):
def test_create_bucket(self):
new_bucket_name = 'a-new-bucket'
self.assertRaises(exceptions.NotFound,
storage.get_bucket, new_bucket_name)
created = storage.create_bucket(new_bucket_name)
CLIENT.get_bucket, new_bucket_name)
created = CLIENT.create_bucket(new_bucket_name)
self.case_buckets_to_delete.append(new_bucket_name)
self.assertEqual(created.name, new_bucket_name)

def test_get_buckets(self):
def test_list_buckets(self):
buckets_to_create = [
'new%d' % (1000 * time.time(),),
'newer%d' % (1000 * time.time(),),
'newest%d' % (1000 * time.time(),),
]
created_buckets = []
for bucket_name in buckets_to_create:
bucket = storage.create_bucket(bucket_name)
bucket = CLIENT.create_bucket(bucket_name)
self.case_buckets_to_delete.append(bucket_name)

# Retrieve the buckets.
all_buckets = storage.list_buckets()
all_buckets = CLIENT.list_buckets()
created_buckets = [bucket for bucket in all_buckets
if bucket.name in buckets_to_create]
self.assertEqual(len(created_buckets), len(buckets_to_create))
Expand Down

1 comment on commit 1b1fb11

@tseaver
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1b1fb11 LGTM overall.

FWIW, the redundant doctest-snippet changes confirm my sense that those snippets don't belong in method docstrings.

Please sign in to comment.