Skip to content

Commit

Permalink
fix: skip some system tests for mtls testing (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
arithmetic1728 committed Jan 5, 2021
1 parent bcec3ea commit 89ba292
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions tests/system/v1/conftest.py
Expand Up @@ -33,9 +33,20 @@ def project_id():


@pytest.fixture(scope="session")
def credentials():
def use_mtls():
return "always" == os.environ.get("GOOGLE_API_USE_MTLS_ENDPOINT", "never")


@pytest.fixture(scope="session")
def credentials(use_mtls):
import google.auth
from google.oauth2 import service_account

if use_mtls:
# mTLS test uses user credentials instead of service account credentials
creds, _ = google.auth.default()
return creds

# NOTE: the test config in noxfile checks that the env variable is indeed set
filename = os.environ["GOOGLE_APPLICATION_CREDENTIALS"]
return service_account.Credentials.from_service_account_file(filename)
Expand All @@ -59,7 +70,11 @@ def small_table_reference():


@pytest.fixture(scope="session")
def local_shakespeare_table_reference(project_id):
def local_shakespeare_table_reference(project_id, use_mtls):
if use_mtls:
pytest.skip(
"Skip it for mTLS testing since the table does not exist for mTLS project"
)
return _TABLE_FORMAT.format(project_id, "public_samples_copy", "shakespeare")


Expand Down Expand Up @@ -100,7 +115,9 @@ def table(project_id, dataset, bq_client):


@pytest.fixture(scope="session")
def bq_client(credentials):
def bq_client(credentials, use_mtls):
if use_mtls:
pytest.skip("Skip it for mTLS testing since bigquery does not support mTLS")
from google.cloud import bigquery

return bigquery.Client(credentials=credentials)
Expand Down

0 comments on commit 89ba292

Please sign in to comment.