diff --git a/regression/regression_utils.py b/regression/regression_utils.py index d0cd1cdd3b0f..5e4605fa006e 100644 --- a/regression/regression_utils.py +++ b/regression/regression_utils.py @@ -16,14 +16,11 @@ import os import sys -from gcloud import storage - # From shell environ. May be None. PROJECT_ID = os.getenv('GCLOUD_TESTS_PROJECT_ID') DATASET_ID = os.getenv('GCLOUD_TESTS_DATASET_ID') CREDENTIALS = os.getenv('GOOGLE_APPLICATION_CREDENTIALS') -CACHED_RETURN_VALS = {} ENVIRON_ERROR_MSG = """\ To run the regression tests, you need to set some environment variables. @@ -46,13 +43,3 @@ def get_environ(require_datastore=False, require_storage=False): 'project_id': PROJECT_ID, 'dataset_id': DATASET_ID, } - - -def get_storage_connection(): - environ = get_environ(require_storage=True) - project_id = environ['project_id'] - key = ('get_storage_connection', project_id) - if key not in CACHED_RETURN_VALS: - # Cache return value for the environment. - CACHED_RETURN_VALS[key] = storage.get_connection(project_id) - return CACHED_RETURN_VALS[key] diff --git a/regression/storage.py b/regression/storage.py index 5ff231fd9b6e..18c25a90a911 100644 --- a/regression/storage.py +++ b/regression/storage.py @@ -20,23 +20,25 @@ import unittest2 from gcloud import storage -# This assumes the command is being run via tox hence the -# repository root is the current directory. -from regression import regression_utils +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: - connection = regression_utils.get_storage_connection() # %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) + SHARED_BUCKETS['test_bucket'] = CONNECTION.create_bucket(bucket_name) def safe_delete(bucket): @@ -55,14 +57,7 @@ def tearDownModule(): safe_delete(bucket) -class TestStorage(unittest2.TestCase): - - @classmethod - def setUpClass(cls): - cls.connection = regression_utils.get_storage_connection() - - -class TestStorageBuckets(TestStorage): +class TestStorageBuckets(unittest2.TestCase): def setUp(self): self.case_buckets_to_delete = [] @@ -74,8 +69,8 @@ def tearDown(self): def test_create_bucket(self): new_bucket_name = 'a-new-bucket' self.assertRaises(storage.exceptions.NotFound, - self.connection.get_bucket, new_bucket_name) - created = self.connection.create_bucket(new_bucket_name) + CONNECTION.get_bucket, new_bucket_name) + created = CONNECTION.create_bucket(new_bucket_name) self.case_buckets_to_delete.append(created) self.assertEqual(created.name, new_bucket_name) @@ -87,17 +82,17 @@ def test_get_buckets(self): ] created_buckets = [] for bucket_name in buckets_to_create: - bucket = self.connection.create_bucket(bucket_name) + bucket = CONNECTION.create_bucket(bucket_name) self.case_buckets_to_delete.append(bucket) # Retrieve the buckets. - all_buckets = self.connection.get_all_buckets() + all_buckets = CONNECTION.get_all_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)) -class TestStorageFiles(TestStorage): +class TestStorageFiles(unittest2.TestCase): FILES = { 'logo': {