diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 660f5a204..707c02440 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -23,6 +23,9 @@ export PYTHONUNBUFFERED=1 # Debug: show build environment env | grep KOKORO +# Setup firestore account credentials +export FIRESTORE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/firebase-credentials.json + # Setup service account credentials. export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/service-account.json diff --git a/synth.py b/synth.py index 9b4f8d047..8a7f8167d 100644 --- a/synth.py +++ b/synth.py @@ -137,3 +137,13 @@ s.shell.run(["nox", "-s", "blacken"], hide_output=False) + +s.replace( + ".kokoro/build.sh", + "# Setup service account credentials.", + """\ +# Setup firestore account credentials +export FIRESTORE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/firebase-credentials.json + +# Setup service account credentials.""" +) diff --git a/tests/system/test_system.py b/tests/system/test_system.py index 15efa81e6..e9dd7523f 100644 --- a/tests/system/test_system.py +++ b/tests/system/test_system.py @@ -38,10 +38,15 @@ ) -@pytest.fixture(scope=u"module") -def client(): +def _get_credentials_and_project(): credentials = service_account.Credentials.from_service_account_file(FIRESTORE_CREDS) project = FIRESTORE_PROJECT or credentials.project_id + return credentials, project + + +@pytest.fixture(scope=u"module") +def client(): + credentials, project = _get_credentials_and_project() yield firestore.Client(project=project, credentials=credentials) @@ -62,7 +67,8 @@ def test_collections(client): def test_collections_w_import(): from google.cloud import firestore - client = firestore.Client() + credentials, project = _get_credentials_and_project() + client = firestore.Client(project=project, credentials=credentials) collections = list(client.collections()) assert isinstance(collections, list) diff --git a/tests/system/test_system_async.py b/tests/system/test_system_async.py index 4dfe36a87..42817892d 100644 --- a/tests/system/test_system_async.py +++ b/tests/system/test_system_async.py @@ -40,10 +40,15 @@ pytestmark = pytest.mark.asyncio -@pytest.fixture(scope=u"module") -def client(): +def _get_credentials_and_project(): credentials = service_account.Credentials.from_service_account_file(FIRESTORE_CREDS) project = FIRESTORE_PROJECT or credentials.project_id + return credentials, project + + +@pytest.fixture(scope=u"module") +def client(): + credentials, project = _get_credentials_and_project() yield firestore.AsyncClient(project=project, credentials=credentials) @@ -70,7 +75,8 @@ async def test_collections(client): async def test_collections_w_import(): from google.cloud import firestore - client = firestore.AsyncClient() + credentials, project = _get_credentials_and_project() + client = firestore.AsyncClient(project=project, credentials=credentials) collections = [x async for x in client.collections()] assert isinstance(collections, list)