def get_gcs_connection():
    '''
    Checks if there is a GCS connection and, if not, creates one
    :return: True once the connection is established
    '''
    #TODO returning True doesn't seem right here but gets the job done
    # Does not account for no connectivity, api issues...
    if storage.get_default_connection() and storage.get_default_bucket():
        return True
    else:
        connect = storage.get_connection().from_service_account_json(
            SRV_ACCT_CREDS)
        bucket = storage.bucket.Bucket(name=BUCKET_NAME)
        storage.set_defaults(bucket, PROJECT_ID, connect)
        return True
Esempio n. 2
0
import six
import tempfile
import time
import unittest2

from gcloud import exceptions
from gcloud import storage
from gcloud import _helpers
from gcloud.storage._helpers import _base64_md5hash


HTTP = httplib2.Http()
SHARED_BUCKETS = {}

_helpers._PROJECT_ENV_VAR_NAME = 'GCLOUD_TESTS_PROJECT_ID'
storage.set_defaults()


def setUpModule():
    if 'test_bucket' not in SHARED_BUCKETS:
        # %d rounds milliseconds to nearest integer.
        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)


def tearDownModule():
    for bucket in SHARED_BUCKETS.values():
        bucket.delete(force=True)
Esempio n. 3
0
 def _callFUT(self, bucket=None, project=None, connection=None):
     from gcloud.storage import set_defaults
     return set_defaults(bucket=bucket, project=project,
                         connection=connection)
Esempio n. 4
0
 def _callFUT(self, bucket=None, project=None, connection=None):
     from gcloud.storage import set_defaults
     return set_defaults(bucket=bucket,
                         project=project,
                         connection=connection)
Esempio n. 5
0
def initialize_gcloud():
    datastore.set_defaults()
    storage.set_defaults()
Esempio n. 6
0
import httplib2
import tempfile
import time
import unittest2

from gcloud import exceptions
from gcloud import storage
from gcloud.storage._helpers import _base64_md5hash
from gcloud.storage import _implicit_environ

HTTP = httplib2.Http()
SHARED_BUCKETS = {}

storage._PROJECT_ENV_VAR_NAME = 'GCLOUD_TESTS_PROJECT_ID'
storage.set_defaults()

CONNECTION = _implicit_environ.CONNECTION


def setUpModule():
    if 'test_bucket' not in SHARED_BUCKETS:
        # %d rounds milliseconds to nearest integer.
        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'] = CONNECTION.create_bucket(bucket_name)


def tearDownModule():
    for bucket in SHARED_BUCKETS.values():