Skip to content
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions firestore/tests/system/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from google.cloud._helpers import UTC
from google.cloud import firestore_v1 as firestore
from test_utils.system import unique_resource_id
from test_utils.system import EmulatorCreds

from time import sleep

Expand All @@ -40,12 +41,21 @@
MISSING_DOCUMENT = "No document to update: "
DOCUMENT_EXISTS = "Document already exists: "
UNIQUE_RESOURCE_ID = unique_resource_id("-")
FIRESTORE_EMULATOR_HOST = "FIRESTORE_EMULATOR_HOST"

IN_EMULATOR = os.getenv(FIRESTORE_EMULATOR_HOST) is not None


@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 IN_EMULATOR:
credentials = EmulatorCreds()
project = "emulatorproject"
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 @@ -126,6 +136,7 @@ def test_create_document_w_subcollection(client, cleanup):
assert sorted(child.id for child in children) == sorted(child_ids)


@pytest.mark.skipif(IN_EMULATOR, reason="Not supported in emulator.")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this repeats multiple times, I'd suggest defining a constant, something like
REASON_NOT_SUPPORTED="Not supported in emulator."
and using it throughout the file.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have put the internal issue tracking number as a reason for all skipped tests as suggested by Chris.

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 @@ -280,6 +291,7 @@ def test_document_update_w_int_field(client, cleanup):
assert snapshot1.to_dict() == expected


@pytest.mark.skipif(IN_EMULATOR, reason="Not supported in emulator.")
def test_update_document(client, cleanup):
document_id = "for-update" + UNIQUE_RESOURCE_ID
document = client.document("made", document_id)
Expand Down Expand Up @@ -492,6 +504,7 @@ def test_collection_add(client, cleanup):
assert set(collection3.list_documents()) == {document_ref5}


@pytest.mark.skipif(IN_EMULATOR, reason="Not supported in emulator.")
def test_query_stream(client, cleanup):
collection_id = "qs" + UNIQUE_RESOURCE_ID
sub_collection = "child" + UNIQUE_RESOURCE_ID
Expand Down Expand Up @@ -806,6 +819,7 @@ def test_collection_group_queries_filters(client, cleanup):
assert found == set(["cg-doc2"])


@pytest.mark.skipif(IN_EMULATOR, reason="Not supported in emulator.")
def test_get_all(client, cleanup):
collection_name = "get-all" + UNIQUE_RESOURCE_ID

Expand Down Expand Up @@ -857,6 +871,7 @@ def test_get_all(client, cleanup):
check_snapshot(snapshot3, document3, restricted3, write_result3)


@pytest.mark.skipif(IN_EMULATOR, reason="Not supported in emulator.")
def test_batch(client, cleanup):
collection_name = "batch" + UNIQUE_RESOURCE_ID

Expand Down