diff options
author | Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> | 2020-07-20 13:43:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-20 13:43:47 -0700 |
commit | e2d9a7b209b7dfab300dc848fabbae8f42a2ab19 (patch) | |
tree | 239526d467c4335829c1bdc0aecade4f4afb98f4 /tests | |
parent | 8595f620e7d8295b6a379d6fd7979af3bef717e2 (diff) | |
download | python-api-core-e2d9a7b209b7dfab300dc848fabbae8f42a2ab19.tar.gz |
feat: allow quota project to be passed to create_channel (#58)
* feat: allow quota project to be passed to create_channel
* chore: update test name
* chore: lint and increase auth lib version
* chore: fix lint
* Update setup.py
Diffstat (limited to 'tests')
-rw-r--r-- | tests/asyncio/test_grpc_helpers_async.py | 17 | ||||
-rw-r--r-- | tests/unit/test_grpc_helpers.py | 23 |
2 files changed, 40 insertions, 0 deletions
diff --git a/tests/asyncio/test_grpc_helpers_async.py b/tests/asyncio/test_grpc_helpers_async.py index d56c4c6..924a74c 100644 --- a/tests/asyncio/test_grpc_helpers_async.py +++ b/tests/asyncio/test_grpc_helpers_async.py @@ -365,6 +365,23 @@ def test_create_channel_explicit_scoped(grpc_secure_channel, composite_creds_cal @mock.patch("grpc.composite_channel_credentials") @mock.patch("grpc.experimental.aio.secure_channel") +def test_create_channel_explicit_with_quota_project(grpc_secure_channel, composite_creds_call): + target = "example.com:443" + composite_creds = composite_creds_call.return_value + + credentials = mock.create_autospec(google.auth.credentials.Credentials, instance=True) + + channel = grpc_helpers_async.create_channel( + target, credentials=credentials, quota_project_id="project-foo" + ) + + credentials.with_quota_project.assert_called_once_with("project-foo") + assert channel is grpc_secure_channel.return_value + grpc_secure_channel.assert_called_once_with(target, composite_creds) + + +@mock.patch("grpc.composite_channel_credentials") +@mock.patch("grpc.experimental.aio.secure_channel") @mock.patch( "google.auth.load_credentials_from_file", return_value=(mock.sentinel.credentials, mock.sentinel.project) diff --git a/tests/unit/test_grpc_helpers.py b/tests/unit/test_grpc_helpers.py index e2f3666..f8fed40 100644 --- a/tests/unit/test_grpc_helpers.py +++ b/tests/unit/test_grpc_helpers.py @@ -337,6 +337,29 @@ def test_create_channel_explicit_scoped(grpc_secure_channel, composite_creds_cal @mock.patch("grpc.composite_channel_credentials") @mock.patch("grpc.secure_channel") +def test_create_channel_explicit_with_quota_project(grpc_secure_channel, composite_creds_call): + target = "example.com:443" + composite_creds = composite_creds_call.return_value + + credentials = mock.create_autospec(google.auth.credentials.Credentials, instance=True) + + channel = grpc_helpers.create_channel( + target, + credentials=credentials, + quota_project_id="project-foo" + ) + + credentials.with_quota_project.assert_called_once_with("project-foo") + + assert channel is grpc_secure_channel.return_value + if grpc_helpers.HAS_GRPC_GCP: + grpc_secure_channel.assert_called_once_with(target, composite_creds, None) + else: + grpc_secure_channel.assert_called_once_with(target, composite_creds) + + +@mock.patch("grpc.composite_channel_credentials") +@mock.patch("grpc.secure_channel") @mock.patch( "google.auth.load_credentials_from_file", return_value=(mock.sentinel.credentials, mock.sentinel.project) |