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

feat: find emulator project id from environment variable #843

Merged
merged 4 commits into from
Feb 16, 2024
Merged
Prev Previous commit
Next Next commit
added test
  • Loading branch information
daniel-sanche committed Feb 16, 2024
commit 01bb84d34f40b7eb20cc79360304af8728dfac52
33 changes: 32 additions & 1 deletion tests/unit/v1/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
import mock
import pytest

from google.cloud.firestore_v1.base_client import DEFAULT_DATABASE
from google.cloud.firestore_v1.base_client import (
DEFAULT_DATABASE,
_DEFAULT_EMULATOR_PROJECT,
)

PROJECT = "my-prahjekt"

Expand Down Expand Up @@ -100,6 +103,34 @@ def test_client_constructor_explicit(database, expected):
assert client._client_options is client_options


@pytest.mark.parametrize(
"extra_env,project_expected",
[
({}, _DEFAULT_EMULATOR_PROJECT),
({"GCLOUD_PROJECT": "gcloud"}, "gcloud"),
({"GOOGLE_CLOUD_PROJECT": "google"}, "google"),
({"GCLOUD_PROJECT": "gcloud", "GOOGLE_CLOUD_PROJECT": "google"}, "google"),
],
)
def test_client_constructor_emulator(extra_env, project_expected):
"""
Ensure client can be configured with FIRESOTRE_EMULATOR_HOST environment variable

If project is not set, should be detected from GCLOUD_PROJECT or GOOGLE_CLOUD_PROJECT
"""
from google.cloud.firestore_v1.client import _CLIENT_INFO

expected_host = "localhost:8080"
environment = {"FIRESTORE_EMULATOR_HOST": expected_host}
if extra_env:
environment.update(extra_env)

with mock.patch("os.environ", environment):
client = _make_client()
assert client._emulator_host == expected_host
assert client.project == project_expected


@pytest.mark.parametrize("database", [None, DEFAULT_DATABASE, "somedb"])
def test_client__firestore_api_property(database):
credentials = _make_credentials()
Expand Down
Loading