Skip to content

Commit

Permalink
tests: run systests on Kokoro (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver committed Aug 20, 2020
1 parent 43eafa3 commit 45cac3a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .kokoro/build.sh
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions synth.py
Expand Up @@ -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."""
)
12 changes: 9 additions & 3 deletions tests/system/test_system.py
Expand Up @@ -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)


Expand All @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions tests/system/test_system_async.py
Expand Up @@ -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)


Expand All @@ -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)
Expand Down

0 comments on commit 45cac3a

Please sign in to comment.