From 891edc7a9fd576cf0b61286502b0ba02223f89c6 Mon Sep 17 00:00:00 2001 From: HemangChothani <50404902+HemangChothani@users.noreply.github.com> Date: Tue, 30 Jun 2020 21:36:24 +0530 Subject: [PATCH] feat(firestore): add support of emulator to run system tests on emulator (#31) * feat(firestore): add support of emulator to run system tests on emulator * feat(firestore): add test_utils folder for support * docs(firestore): remove test_utils folder as added in nox file Co-authored-by: Christopher Wilcox --- tests/system/test_system.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/system/test_system.py b/tests/system/test_system.py index 71ac07fce..5a5184aca 100644 --- a/tests/system/test_system.py +++ b/tests/system/test_system.py @@ -30,7 +30,9 @@ from google.cloud._helpers import _pb_timestamp_to_datetime from google.cloud._helpers import UTC from google.cloud import firestore_v1 as firestore +from google.cloud.firestore_v1.client import _FIRESTORE_EMULATOR_HOST from test_utils.system import unique_resource_id +from test_utils.system import EmulatorCreds from time import sleep @@ -41,11 +43,19 @@ DOCUMENT_EXISTS = "Document already exists: " UNIQUE_RESOURCE_ID = unique_resource_id("-") +FIRESTORE_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 FIRESTORE_EMULATOR: + credentials = EmulatorCreds() + 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) @@ -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(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) @@ -280,6 +291,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) @@ -861,6 +873,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