def setUpModule(): from google.cloud.exceptions import GrpcRendezvous Config.IN_EMULATOR = os.getenv(BIGTABLE_EMULATOR) is not None if Config.IN_EMULATOR: credentials = EmulatorCreds() Config.CLIENT = Client(admin=True, credentials=credentials) else: Config.CLIENT = Client(admin=True) Config.INSTANCE = Config.CLIENT.instance(INSTANCE_ID, LOCATION_ID) if not Config.IN_EMULATOR: retry = RetryErrors(GrpcRendezvous, error_predicate=_retry_on_unavailable) instances_response = retry(Config.CLIENT.list_instances)() if len(instances_response.failed_locations) != 0: raise ValueError('List instances failed in module set up.') EXISTING_INSTANCES[:] = instances_response.instances # After listing, create the test instance. created_op = Config.INSTANCE.create() created_op.result(timeout=10)
def setUpModule(): from google.cloud.exceptions import GrpcRendezvous Config.IN_EMULATOR = os.getenv(BIGTABLE_EMULATOR) is not None if Config.IN_EMULATOR: credentials = EmulatorCreds() Config.CLIENT = Client(admin=True, credentials=credentials) else: Config.CLIENT = Client(admin=True) Config.INSTANCE = Config.CLIENT.instance(INSTANCE_ID, labels=LABELS) Config.CLUSTER = Config.INSTANCE.cluster(CLUSTER_ID, location_id=LOCATION_ID, serve_nodes=SERVE_NODES) if not Config.IN_EMULATOR: retry = RetryErrors(GrpcRendezvous, error_predicate=_retry_on_unavailable) instances, failed_locations = retry(Config.CLIENT.list_instances)() if len(failed_locations) != 0: raise ValueError("List instances failed in module set up.") EXISTING_INSTANCES[:] = instances # After listing, create the test instance. created_op = Config.INSTANCE.create(clusters=[Config.CLUSTER]) created_op.result(timeout=10)
def setUpModule(): Config.IN_EMULATOR = os.getenv(PUBSUB_EMULATOR) is not None if Config.IN_EMULATOR: credentials = EmulatorCreds() http = httplib2.Http() # Un-authorized. Config.CLIENT = client.Client(credentials=credentials, _http=http) else: Config.CLIENT = client.Client()
def client(): if FIRESTORE_EMULATOR: credentials = EmulatorCreds() project = FIRESTORE_PROJECT else: credentials = service_account.Credentials.from_service_account_file( FIRESTORE_CREDS) project = FIRESTORE_PROJECT or credentials.project_id yield firestore.Client(project=project, credentials=credentials)
def setUpModule(): emulator_dataset = os.getenv(GCD_DATASET) # Isolated namespace so concurrent test runs don't collide. test_namespace = 'ns' + unique_resource_id() if emulator_dataset is None: Config.CLIENT = datastore.Client(namespace=test_namespace) else: credentials = EmulatorCreds() http = requests.Session() # Un-authorized. Config.CLIENT = datastore.Client(project=emulator_dataset, namespace=test_namespace, credentials=credentials, _http=http)
def setUpModule(): from google.cloud.exceptions import GrpcRendezvous from google.cloud.bigtable.enums import Instance # See: https://github.com/googleapis/google-cloud-python/issues/5928 interfaces = table_admin_config.config["interfaces"] iface_config = interfaces["google.bigtable.admin.v2.BigtableTableAdmin"] methods = iface_config["methods"] create_table = methods["CreateTable"] create_table["timeout_millis"] = 90000 Config.IN_EMULATOR = os.getenv(BIGTABLE_EMULATOR) is not None if Config.IN_EMULATOR: credentials = EmulatorCreds() Config.CLIENT = Client(admin=True, credentials=credentials) else: Config.CLIENT = Client(admin=True) Config.INSTANCE = Config.CLIENT.instance(INSTANCE_ID, labels=LABELS) Config.CLUSTER = Config.INSTANCE.cluster(CLUSTER_ID, location_id=LOCATION_ID, serve_nodes=SERVE_NODES) Config.INSTANCE_DATA = Config.CLIENT.instance( INSTANCE_ID_DATA, instance_type=Instance.Type.DEVELOPMENT, labels=LABELS) Config.CLUSTER_DATA = Config.INSTANCE_DATA.cluster(CLUSTER_ID_DATA, location_id=LOCATION_ID) if not Config.IN_EMULATOR: retry = RetryErrors(GrpcRendezvous, error_predicate=_retry_on_unavailable) instances, failed_locations = retry(Config.CLIENT.list_instances)() if len(failed_locations) != 0: raise ValueError("List instances failed in module set up.") EXISTING_INSTANCES[:] = instances # After listing, create the test instances. admin_op = Config.INSTANCE.create(clusters=[Config.CLUSTER]) admin_op.result(timeout=10) data_op = Config.INSTANCE_DATA.create(clusters=[Config.CLUSTER_DATA]) data_op.result(timeout=10)
import os import re from google.cloud.firestore_v1.base_client import _FIRESTORE_EMULATOR_HOST from test_utils.system import unique_resource_id from test_utils.system import EmulatorCreds FIRESTORE_CREDS = os.environ.get("FIRESTORE_APPLICATION_CREDENTIALS") FIRESTORE_PROJECT = os.environ.get("GCLOUD_PROJECT") RANDOM_ID_REGEX = re.compile("^[a-zA-Z0-9]{20}$") MISSING_DOCUMENT = "No document to update: " DOCUMENT_EXISTS = "Document already exists: " UNIQUE_RESOURCE_ID = unique_resource_id("-") EMULATOR_CREDS = EmulatorCreds() FIRESTORE_EMULATOR = os.environ.get(_FIRESTORE_EMULATOR_HOST) is not None