Skip to content

Commit

Permalink
Stop uisng a designated tests project ID.
Browse files Browse the repository at this point in the history
This is because the project ID can be determined directly from
the file pointed to by GOOGLE_APPLICATION_CREDENTIALS.

Fixes #2263.
  • Loading branch information
dhermes committed Sep 9, 2016
1 parent 6b42be9 commit e163981
Show file tree
Hide file tree
Showing 14 changed files with 12 additions and 50 deletions.
10 changes: 4 additions & 6 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ Running System Tests
so you'll need to provide some environment variables to facilitate
authentication to your project:

- ``GOOGLE_CLOUD_TESTS_PROJECT_ID``: Developers Console project ID (e.g.
bamboo-shift-455).
- ``GOOGLE_APPLICATION_CREDENTIALS``: The path to a JSON key file;
see ``system_tests/app_credentials.json.sample`` as an example. Such a file
can be downloaded directly from the developer's console by clicking
Expand Down Expand Up @@ -182,12 +180,12 @@ Running System Tests
$ export CLOUDSDK_PYTHON_SITEPACKAGES=1

# Authenticate the gcloud tool with your account.
$ JSON_CREDENTIALS_FILE="path/to/app_credentials.json"
$ gcloud auth activate-service-account --key-file=$JSON_CREDENTIALS_FILE
$ GOOGLE_APPLICATION_CREDENTIALS="path/to/app_credentials.json"
$ gcloud auth activate-service-account \
> --key-file=${GOOGLE_APPLICATION_CREDENTIALS}

# Create the indexes
$ gcloud preview datastore create-indexes system_tests/data/index.yaml \
> --project=$GOOGLE_CLOUD_TESTS_PROJECT_ID
$ gcloud preview datastore create-indexes system_tests/data/index.yaml

# Restore your environment to its previous state.
$ unset CLOUDSDK_PYTHON_SITEPACKAGES
Expand Down
3 changes: 0 additions & 3 deletions google/cloud/environment_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
PROJECT = 'GOOGLE_CLOUD_PROJECT'
"""Environment variable defining default project."""

TESTS_PROJECT = 'GOOGLE_CLOUD_TESTS_PROJECT_ID'
"""Environment variable defining project for tests."""

GCD_DATASET = 'DATASTORE_DATASET'
"""Environment variable defining default dataset ID under GCD."""

Expand Down
2 changes: 0 additions & 2 deletions system_tests/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import unittest

from google.cloud import _helpers
from google.cloud.environment_vars import TESTS_PROJECT
from google.cloud import bigquery
from google.cloud.exceptions import Forbidden

Expand Down Expand Up @@ -52,7 +51,6 @@ class Config(object):


def setUpModule():
_helpers.PROJECT = TESTS_PROJECT
Config.CLIENT = bigquery.Client()


Expand Down
2 changes: 0 additions & 2 deletions system_tests/bigtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from google.cloud.bigtable.row_filters import RowFilterUnion
from google.cloud.bigtable.row_data import Cell
from google.cloud.bigtable.row_data import PartialRowData
from google.cloud.environment_vars import TESTS_PROJECT

from retry import RetryErrors
from retry import RetryResult
Expand Down Expand Up @@ -92,7 +91,6 @@ def _retry_on_unavailable(exc):

def setUpModule():
from grpc._channel import _Rendezvous
_helpers.PROJECT = TESTS_PROJECT
Config.CLIENT = Client(admin=True)
Config.INSTANCE = Config.CLIENT.instance(INSTANCE_ID, LOCATION_ID)
retry = RetryErrors(_Rendezvous, error_predicate=_retry_on_unavailable)
Expand Down
3 changes: 1 addition & 2 deletions system_tests/clear_datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import six

from google.cloud import datastore
from google.cloud.environment_vars import TESTS_PROJECT


FETCH_MAX = 20
Expand Down Expand Up @@ -90,7 +89,7 @@ def remove_kind(kind, client):
def remove_all_entities(client=None):
if client is None:
# Get a client that uses the test dataset.
client = datastore.Client(project=os.getenv(TESTS_PROJECT))
client = datastore.Client()
for kind in ALL_KINDS:
remove_kind(kind, client)

Expand Down
2 changes: 0 additions & 2 deletions system_tests/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from google.cloud import datastore
from google.cloud.datastore.helpers import GeoPoint
from google.cloud.environment_vars import GCD_DATASET
from google.cloud.environment_vars import TESTS_PROJECT
from google.cloud.exceptions import Conflict

import clear_datastore
Expand Down Expand Up @@ -55,7 +54,6 @@ def setUpModule():
# Isolated namespace so concurrent test runs don't collide.
test_namespace = 'ns' + unique_resource_id()
if emulator_dataset is None:
_helpers.PROJECT = TESTS_PROJECT
Config.CLIENT = datastore.Client(namespace=test_namespace)
else:
credentials = EmulatorCreds()
Expand Down
2 changes: 0 additions & 2 deletions system_tests/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import unittest

from google.cloud import _helpers
from google.cloud.environment_vars import TESTS_PROJECT
from google.cloud import exceptions
from google.cloud import language
from google.cloud import storage
Expand All @@ -39,7 +38,6 @@ class Config(object):


def setUpModule():
_helpers.PROJECT = TESTS_PROJECT
Config.CLIENT = language.Client()
# Now create a bucket for GCS stored content.
storage_client = storage.Client()
Expand Down
1 change: 0 additions & 1 deletion system_tests/local_test_setup.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export GOOGLE_APPLICATION_CREDENTIALS="app_credentials.json.sample"
export GOOGLE_CLOUD_TESTS_PROJECT_ID="my-project"
export GOOGLE_CLOUD_REMOTE_FOR_LINT="upstream"
export GOOGLE_CLOUD_BRANCH_FOR_LINT="master"
2 changes: 0 additions & 2 deletions system_tests/logging_.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from google.cloud.logging.handlers.transports import SyncTransport
from google.cloud.logging import client
from google.cloud import _helpers
from google.cloud.environment_vars import TESTS_PROJECT

from retry import RetryErrors
from retry import RetryResult
Expand Down Expand Up @@ -52,7 +51,6 @@ class Config(object):


def setUpModule():
_helpers.PROJECT = TESTS_PROJECT
Config.CLIENT = client.Client()


Expand Down
5 changes: 0 additions & 5 deletions system_tests/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import unittest

from google.cloud import _helpers
from google.cloud.environment_vars import TESTS_PROJECT
from google.cloud.exceptions import InternalServerError
from google.cloud.exceptions import NotFound
from google.cloud.exceptions import ServiceUnavailable
Expand All @@ -30,10 +29,6 @@
retry_503 = RetryErrors(ServiceUnavailable)


def setUpModule():
_helpers.PROJECT = TESTS_PROJECT


class TestMonitoring(unittest.TestCase):

def test_fetch_metric_descriptor(self):
Expand Down
3 changes: 1 addition & 2 deletions system_tests/populate_datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import six

from google.cloud import datastore
from google.cloud.environment_vars import TESTS_PROJECT


ANCESTOR = ('Book', 'GoT')
Expand Down Expand Up @@ -91,7 +90,7 @@ def print_func(message):
def add_characters(client=None):
if client is None:
# Get a client that uses the test dataset.
client = datastore.Client(project=os.getenv(TESTS_PROJECT))
client = datastore.Client()
with client.transaction() as xact:
for key_path, character in six.moves.zip(KEY_PATHS, CHARACTERS):
if key_path[-1] != character['name']:
Expand Down
2 changes: 0 additions & 2 deletions system_tests/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
# pylint: disable=ungrouped-imports
from google.cloud import _helpers
from google.cloud.environment_vars import PUBSUB_EMULATOR
from google.cloud.environment_vars import TESTS_PROJECT
from google.cloud.pubsub import client
# pylint: enable=ungrouped-imports

Expand Down Expand Up @@ -51,7 +50,6 @@ class Config(object):


def setUpModule():
_helpers.PROJECT = TESTS_PROJECT
if os.getenv(PUBSUB_EMULATOR) is None:
Config.CLIENT = client.Client()
else:
Expand Down
2 changes: 0 additions & 2 deletions system_tests/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import six

from google.cloud import _helpers
from google.cloud.environment_vars import TESTS_PROJECT
from google.cloud import exceptions
from google.cloud import storage
from google.cloud.storage._helpers import _base64_md5hash
Expand All @@ -33,7 +32,6 @@

retry_429 = RetryErrors(exceptions.TooManyRequests)
HTTP = httplib2.Http()
_helpers.PROJECT = TESTS_PROJECT


class Config(object):
Expand Down
23 changes: 6 additions & 17 deletions system_tests/system_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
import time

from google.cloud.environment_vars import CREDENTIALS as TEST_CREDENTIALS
from google.cloud.environment_vars import TESTS_PROJECT


# From shell environ. May be None.
PROJECT_ID = os.getenv(TESTS_PROJECT)
CREDENTIALS = os.getenv(TEST_CREDENTIALS)

ENVIRON_ERROR_MSG = """\
Expand All @@ -44,24 +42,15 @@ def create_scoped_required():


def check_environ():
missing = []
extra = ''

if PROJECT_ID is None:
missing.append(TESTS_PROJECT)

err_msg = None
if CREDENTIALS is None:
missing.append(TEST_CREDENTIALS)
err_msg = '\nMissing variables: ' + TEST_CREDENTIALS
elif not os.path.isfile(CREDENTIALS):
extra = '\nThe %s path %r is not a file.' % (TEST_CREDENTIALS,
CREDENTIALS)
err_msg = '\nThe %s path %r is not a file.' % (TEST_CREDENTIALS,
CREDENTIALS)

if missing or extra:
msg = ENVIRON_ERROR_MSG
if missing:
msg += '\nMissing variables: ' + ', '.join(missing)
if extra:
msg += extra
if err_msg is not None:
msg = ENVIRON_ERROR_MSG + err_msg
print(msg, file=sys.stderr)
sys.exit(1)

Expand Down

0 comments on commit e163981

Please sign in to comment.