From d96f7b7be8aed67af28d38c10a7a566218e6b727 Mon Sep 17 00:00:00 2001 From: sumit-ql Date: Wed, 11 Sep 2019 19:09:59 +0530 Subject: [PATCH 1/5] Updated code to run sys tests on emulator. --- firestore/noxfile.py | 5 +++-- firestore/tests/system/test_system.py | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/firestore/noxfile.py b/firestore/noxfile.py index 23026ec11524..3126a4fa8674 100644 --- a/firestore/noxfile.py +++ b/firestore/noxfile.py @@ -98,8 +98,9 @@ def system(session): system_test_path = os.path.join("tests", "system.py") system_test_folder_path = os.path.join("tests", "system") # Sanity check: Only run tests if the environment variable is set. - if not os.environ.get("FIRESTORE_APPLICATION_CREDENTIALS", ""): - session.skip("Credentials must be set via environment variable") + if not os.getenv("FIRESTORE_EMULATOR_HOST"): + if not os.environ.get("FIRESTORE_APPLICATION_CREDENTIALS", ""): + session.skip("Credentials must be set via environment variable") system_test_exists = os.path.exists(system_test_path) system_test_folder_exists = os.path.exists(system_test_folder_path) diff --git a/firestore/tests/system/test_system.py b/firestore/tests/system/test_system.py index f2d30c94a171..f07c7ee32ab0 100644 --- a/firestore/tests/system/test_system.py +++ b/firestore/tests/system/test_system.py @@ -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 @@ -40,12 +41,17 @@ MISSING_DOCUMENT = "No document to update: " DOCUMENT_EXISTS = "Document already exists: " UNIQUE_RESOURCE_ID = unique_resource_id("-") - +FIRESTORE_EMULATOR_HOST = "FIRESTORE_EMULATOR_HOST" @pytest.fixture(scope=u"module") def client(): - credentials = service_account.Credentials.from_service_account_file(FIRESTORE_CREDS) - project = FIRESTORE_PROJECT or credentials.project_id + firestore_emulator = os.getenv(FIRESTORE_EMULATOR_HOST) + if firestore_emulator is not None: + 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) From 83099043a0ddfc455f64e3ed779817028f3d7a10 Mon Sep 17 00:00:00 2001 From: sumit-ql Date: Wed, 11 Sep 2019 21:46:34 +0530 Subject: [PATCH 2/5] lint changes --- firestore/noxfile.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/firestore/noxfile.py b/firestore/noxfile.py index 3126a4fa8674..23026ec11524 100644 --- a/firestore/noxfile.py +++ b/firestore/noxfile.py @@ -98,9 +98,8 @@ def system(session): system_test_path = os.path.join("tests", "system.py") system_test_folder_path = os.path.join("tests", "system") # Sanity check: Only run tests if the environment variable is set. - if not os.getenv("FIRESTORE_EMULATOR_HOST"): - if not os.environ.get("FIRESTORE_APPLICATION_CREDENTIALS", ""): - session.skip("Credentials must be set via environment variable") + if not os.environ.get("FIRESTORE_APPLICATION_CREDENTIALS", ""): + session.skip("Credentials must be set via environment variable") system_test_exists = os.path.exists(system_test_path) system_test_folder_exists = os.path.exists(system_test_folder_path) From baff67bb7319771f96add0ddf6f1ac3b558ada32 Mon Sep 17 00:00:00 2001 From: sumit-ql Date: Wed, 11 Sep 2019 21:47:13 +0530 Subject: [PATCH 3/5] lint changes --- firestore/tests/system/test_system.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/firestore/tests/system/test_system.py b/firestore/tests/system/test_system.py index f07c7ee32ab0..36ea4613f58b 100644 --- a/firestore/tests/system/test_system.py +++ b/firestore/tests/system/test_system.py @@ -43,6 +43,7 @@ UNIQUE_RESOURCE_ID = unique_resource_id("-") FIRESTORE_EMULATOR_HOST = "FIRESTORE_EMULATOR_HOST" + @pytest.fixture(scope=u"module") def client(): firestore_emulator = os.getenv(FIRESTORE_EMULATOR_HOST) @@ -50,7 +51,9 @@ def client(): credentials = EmulatorCreds() project = "emulatorproject" else: - credentials = service_account.Credentials.from_service_account_file(FIRESTORE_CREDS) + credentials = service_account.Credentials.from_service_account_file( + FIRESTORE_CREDS + ) project = FIRESTORE_PROJECT or credentials.project_id yield firestore.Client(project=project, credentials=credentials) From 974954009db360de13cfa00dc5990f1c2ff550d3 Mon Sep 17 00:00:00 2001 From: sumit-ql Date: Thu, 12 Sep 2019 23:36:49 +0530 Subject: [PATCH 4/5] Added pytest.skip for some tests which are not supported on emulator. --- firestore/tests/system/test_system.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/firestore/tests/system/test_system.py b/firestore/tests/system/test_system.py index 36ea4613f58b..9277f5c8246f 100644 --- a/firestore/tests/system/test_system.py +++ b/firestore/tests/system/test_system.py @@ -43,11 +43,12 @@ 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(): - firestore_emulator = os.getenv(FIRESTORE_EMULATOR_HOST) - if firestore_emulator is not None: + if IN_EMULATOR: credentials = EmulatorCreds() project = "emulatorproject" else: @@ -135,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.") def test_cannot_use_foreign_key(client, cleanup): document_id = "cannot" + UNIQUE_RESOURCE_ID document = client.document("foreign-key", document_id) @@ -289,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) @@ -501,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 @@ -815,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 @@ -866,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 From bb870e8e8b9cfcdeb86fb7f55882153f8d9dcae8 Mon Sep 17 00:00:00 2001 From: sumit-ql Date: Fri, 13 Sep 2019 22:41:46 +0530 Subject: [PATCH 5/5] updated internal issue tracking number for skipped tests. --- firestore/tests/system/test_system.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/firestore/tests/system/test_system.py b/firestore/tests/system/test_system.py index 9277f5c8246f..5eed86c81ece 100644 --- a/firestore/tests/system/test_system.py +++ b/firestore/tests/system/test_system.py @@ -136,7 +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.") +@pytest.mark.skipif(IN_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) @@ -291,7 +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.") +@pytest.mark.skipif(IN_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) @@ -504,7 +504,6 @@ 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 @@ -819,7 +818,7 @@ def test_collection_group_queries_filters(client, cleanup): assert found == set(["cg-doc2"]) -@pytest.mark.skipif(IN_EMULATOR, reason="Not supported in emulator.") +@pytest.mark.skipif(IN_EMULATOR, reason="Internal Issue b/137865992") def test_get_all(client, cleanup): collection_name = "get-all" + UNIQUE_RESOURCE_ID @@ -871,7 +870,6 @@ 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