Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: allow running systests on emulator #168

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/system/test__helpers.py
@@ -1,10 +1,14 @@
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
15 changes: 13 additions & 2 deletions tests/system/test_system.py
Expand Up @@ -35,13 +35,21 @@
RANDOM_ID_REGEX,
MISSING_DOCUMENT,
UNIQUE_RESOURCE_ID,
EMULATOR_CREDS,
FIRESTORE_EMULATOR,
)


@pytest.fixture(scope=u"module")
def client():
credentials = service_account.Credentials.from_service_account_file(FIRESTORE_CREDS)
project = FIRESTORE_PROJECT or credentials.project_id
if FIRESTORE_EMULATOR:
credentials = EMULATOR_CREDS
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)


Expand Down Expand Up @@ -133,6 +141,7 @@ def test_create_document_w_subcollection(client, cleanup):
assert sorted(child.id for child in children) == sorted(child_ids)


@pytest.mark.skipif(FIRESTORE_EMULATOR, reason="Internal Issue b/137866686")
def test_cannot_use_foreign_key(client, cleanup):
document_id = "cannot" + UNIQUE_RESOURCE_ID
document = client.document("foreign-key", document_id)
Expand Down Expand Up @@ -285,6 +294,7 @@ def test_document_update_w_int_field(client, cleanup):
assert snapshot1.to_dict() == expected


@pytest.mark.skipif(FIRESTORE_EMULATOR, reason="Internal Issue b/137867104")
def test_update_document(client, cleanup):
document_id = "for-update" + UNIQUE_RESOURCE_ID
document = client.document("made", document_id)
Expand Down Expand Up @@ -874,6 +884,7 @@ def test_collection_group_queries_filters(client, cleanup):
assert found == set(["cg-doc2"])


@pytest.mark.skipif(FIRESTORE_EMULATOR, reason="Internal Issue b/137865992")
def test_get_all(client, cleanup):
collection_name = "get-all" + UNIQUE_RESOURCE_ID

Expand Down
15 changes: 13 additions & 2 deletions tests/system/test_system_async.py
Expand Up @@ -34,6 +34,8 @@
RANDOM_ID_REGEX,
MISSING_DOCUMENT,
UNIQUE_RESOURCE_ID,
EMULATOR_CREDS,
FIRESTORE_EMULATOR,
)

_test_event_loop = asyncio.new_event_loop()
Expand All @@ -42,8 +44,14 @@

@pytest.fixture(scope=u"module")
def client():
credentials = service_account.Credentials.from_service_account_file(FIRESTORE_CREDS)
project = FIRESTORE_PROJECT or credentials.project_id
if FIRESTORE_EMULATOR:
credentials = EMULATOR_CREDS
project = FIRESTORE_PROJECT
else:
credentials = service_account.Credentials.from_service_account_file(
FIRESTORE_CREDS
)
project = FIRESTORE_PROJECT or credentials.project_id
yield firestore.AsyncClient(project=project, credentials=credentials)


Expand Down Expand Up @@ -142,6 +150,7 @@ async def test_create_document_w_subcollection(client, cleanup):
assert sorted([child.id async for child in children]) == sorted(child_ids)


@pytest.mark.skipif(FIRESTORE_EMULATOR, reason="Internal Issue b/137866686")
async def test_cannot_use_foreign_key(client, cleanup):
document_id = "cannot" + UNIQUE_RESOURCE_ID
document = client.document("foreign-key", document_id)
Expand Down Expand Up @@ -294,6 +303,7 @@ async def test_document_update_w_int_field(client, cleanup):
assert snapshot1.to_dict() == expected


@pytest.mark.skipif(FIRESTORE_EMULATOR, reason="Internal Issue b/137867104")
async def test_update_document(client, cleanup):
document_id = "for-update" + UNIQUE_RESOURCE_ID
document = client.document("made", document_id)
Expand Down Expand Up @@ -899,6 +909,7 @@ async def test_collection_group_queries_filters(client, cleanup):
assert found == set(["cg-doc2"])


@pytest.mark.skipif(FIRESTORE_EMULATOR, reason="Internal Issue b/137865992")
async def test_get_all(client, cleanup):
collection_name = "get-all" + UNIQUE_RESOURCE_ID

Expand Down