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

fix: pass client options to publisher and subscriber clients (#166) #190

Merged
merged 2 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion google/cloud/pubsub_v1/publisher/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __init__(self, batch_settings=(), publisher_options=(), **kwargs):
target=os.environ.get("PUBSUB_EMULATOR_HOST")
)

client_options = kwargs.pop("client_options", None)
client_options = kwargs.get("client_options", None)
if (
client_options
and "api_endpoint" in client_options
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/pubsub_v1/subscriber/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(self, **kwargs):
)

# api_endpoint wont be applied if 'transport' is passed in.
client_options = kwargs.pop("client_options", None)
client_options = kwargs.get("client_options", None)
if (
client_options
and "api_endpoint" in client_options
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/pubsub_v1/publisher/test_publisher_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,24 @@ def test_init_w_empty_client_options():
) == publisher_client.PublisherClient.SERVICE_ADDRESS


def test_init_client_options_pass_through():
def init(self, *args, **kwargs):
self.kwargs = kwargs

with mock.patch.object(publisher_client.PublisherClient, "__init__", init):
client = publisher.Client(
client_options={
"quota_project_id": "42",
"scopes": [],
"credentials_file": "file.json",
}
)
client_options = client.api.kwargs["client_options"]
assert client_options.get("quota_project_id") == "42"
assert client_options.get("scopes") == []
assert client_options.get("credentials_file") == "file.json"


def test_init_emulator(monkeypatch):
monkeypatch.setenv("PUBSUB_EMULATOR_HOST", "/foo/bar/")
# NOTE: When the emulator host is set, a custom channel will be used, so
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/pubsub_v1/subscriber/test_subscriber_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ def test_init_w_empty_client_options():
) == subscriber_client.SubscriberClient.SERVICE_ADDRESS


def test_init_client_options_pass_through():
def init(self, *args, **kwargs):
self.kwargs = kwargs

with mock.patch.object(subscriber_client.SubscriberClient, "__init__", init):
client = subscriber.Client(
client_options={
"quota_project_id": "42",
"scopes": [],
"credentials_file": "file.json",
}
)
client_options = client._api.kwargs["client_options"]
assert client_options.get("quota_project_id") == "42"
assert client_options.get("scopes") == []
assert client_options.get("credentials_file") == "file.json"


def test_init_emulator(monkeypatch):
monkeypatch.setenv("PUBSUB_EMULATOR_HOST", "/baz/bacon/")
# NOTE: When the emulator host is set, a custom channel will be used, so
Expand Down