Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit cbcbc15

Browse files
committed
Added anonymous credentials to client tests
1 parent b66553f commit cbcbc15

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

tests/unit/admin_overlay/test_async_client.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from google.api_core import exceptions
2424
from google.api_core import gapic_v1
2525
from google.api_core import retry as retries
26+
from google.auth.credentials import AnonymousCredentials
2627
from google.cloud.bigtable_admin_v2.services.bigtable_table_admin import transports
2728
from google.cloud.bigtable_admin_v2.types import bigtable_table_admin
2829
from google.cloud.bigtable_admin_v2.overlay.services.bigtable_table_admin.async_client import (
@@ -49,6 +50,11 @@
4950
CONSISTENCY_TOKEN = "abcdefg"
5051

5152

53+
def _make_client(**kwargs):
54+
kwargs["credentials"] = kwargs.get("credentials", AnonymousCredentials())
55+
return BigtableTableAdminAsyncClient(**kwargs)
56+
57+
5258
@pytest.mark.parametrize(
5359
"transport_class,transport_name",
5460
[
@@ -63,7 +69,7 @@ def test_bigtable_table_admin_async_client_client_version(
6369
):
6470
with mock.patch.object(transport_class, "__init__") as patched:
6571
patched.return_value = None
66-
BigtableTableAdminAsyncClient(transport=transport_name)
72+
_make_client(transport=transport_name)
6773

6874
# call_args.kwargs is not supported in Python 3.7, so find them from the tuple
6975
# instead. It's always the last item in the call_args tuple.
@@ -104,7 +110,7 @@ def test_bigtable_table_admin_async_client_client_version(
104110
],
105111
)
106112
async def test_bigtable_table_admin_async_client_restore_table(kwargs):
107-
client = BigtableTableAdminAsyncClient()
113+
client = _make_client()
108114

109115
with mock.patch.object(
110116
async_restore_table, "AsyncRestoreTableOperation", new_callable=mock.AsyncMock
@@ -197,7 +203,7 @@ async def test_bigtable_table_admin_async_client_restore_table(kwargs):
197203
async def test_bigtable_table_admin_async_client_wait_for_consistency(
198204
kwargs, check_consistency_request_extras
199205
):
200-
client = BigtableTableAdminAsyncClient()
206+
client = _make_client()
201207
poll_count = 3
202208
check_mock_side_effect = [FALSE_CONSISTENCY_RESPONSE] * (poll_count - 1)
203209
check_mock_side_effect.append(TRUE_CONSISTENCY_RESPONSE)
@@ -246,7 +252,7 @@ async def test_bigtable_table_admin_async_client_wait_for_consistency(
246252

247253
@pytest.mark.asyncio
248254
async def test_bigtable_table_admin_async_client_wait_for_consistency_error_in_call():
249-
client = BigtableTableAdminAsyncClient()
255+
client = _make_client()
250256
request = wait_for_consistency_request.WaitForConsistencyRequest(
251257
name=TABLE_NAME,
252258
)
@@ -281,7 +287,7 @@ async def test_bigtable_table_admin_async_client_wait_for_consistency_error_in_c
281287

282288
@pytest.mark.asyncio
283289
async def test_bigtable_table_admin_async_client_wait_for_consistency_user_error():
284-
client = BigtableTableAdminAsyncClient()
290+
client = _make_client()
285291
with pytest.raises(ValueError):
286292
await client.wait_for_consistency(
287293
{

tests/unit/admin_overlay/test_client.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from google.api_core import exceptions
2323
from google.api_core import gapic_v1
2424
from google.api_core import retry as retries
25+
from google.auth.credentials import AnonymousCredentials
2526
from google.cloud.bigtable_admin_v2.services.bigtable_table_admin import transports
2627
from google.cloud.bigtable_admin_v2.types import bigtable_table_admin
2728
from google.cloud.bigtable_admin_v2.overlay.services.bigtable_table_admin.client import (
@@ -48,6 +49,11 @@
4849
CONSISTENCY_TOKEN = "abcdefg"
4950

5051

52+
def _make_client(**kwargs):
53+
kwargs["credentials"] = kwargs.get("credentials", AnonymousCredentials())
54+
return BigtableTableAdminClient(**kwargs)
55+
56+
5157
@pytest.mark.parametrize(
5258
"transport_class,transport_name",
5359
[
@@ -64,7 +70,7 @@
6470
def test_bigtable_table_admin_client_client_version(transport_class, transport_name):
6571
with mock.patch.object(transport_class, "__init__") as patched:
6672
patched.return_value = None
67-
BigtableTableAdminClient(transport=transport_name)
73+
_make_client(transport=transport_name)
6874

6975
# call_args.kwargs is not supported in Python 3.7, so find them from the tuple
7076
# instead. It's always the last item in the call_args tuple.
@@ -104,7 +110,7 @@ def test_bigtable_table_admin_client_client_version(transport_class, transport_n
104110
],
105111
)
106112
def test_bigtable_table_admin_client_restore_table(kwargs):
107-
client = BigtableTableAdminClient()
113+
client = _make_client()
108114

109115
with mock.patch.object(restore_table, "RestoreTableOperation") as future_mock:
110116
with mock.patch.object(client, "_transport") as transport_mock:
@@ -190,7 +196,7 @@ def test_bigtable_table_admin_client_restore_table(kwargs):
190196
def test_bigtable_table_admin_client_wait_for_consistency(
191197
kwargs, check_consistency_request_extras
192198
):
193-
client = BigtableTableAdminClient()
199+
client = _make_client()
194200
poll_count = 3
195201
check_mock_side_effect = [FALSE_CONSISTENCY_RESPONSE] * (poll_count - 1)
196202
check_mock_side_effect.append(TRUE_CONSISTENCY_RESPONSE)
@@ -234,7 +240,7 @@ def test_bigtable_table_admin_client_wait_for_consistency(
234240

235241

236242
def test_bigtable_table_admin_client_wait_for_consistency_error_in_call():
237-
client = BigtableTableAdminClient()
243+
client = _make_client()
238244
request = wait_for_consistency_request.WaitForConsistencyRequest(
239245
name=TABLE_NAME,
240246
)
@@ -262,7 +268,7 @@ def test_bigtable_table_admin_client_wait_for_consistency_error_in_call():
262268

263269

264270
def test_bigtable_table_admin_client_wait_for_consistency_user_error():
265-
client = BigtableTableAdminClient()
271+
client = _make_client()
266272
with pytest.raises(ValueError):
267273
client.wait_for_consistency(
268274
{

0 commit comments

Comments
 (0)