Skip to content
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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,8 @@ def test_generate_access_token(request_type, transport: str = "grpc"):
# Establish that the underlying gRPC stub method was called.
assert len(call.mock_calls) == 1
_, args, _ = call.mock_calls[0]
assert args[0] == common.GenerateAccessTokenRequest()
request = common.GenerateAccessTokenRequest()
assert args[0] == request

# Establish that the response is the type that we expect.
assert isinstance(response, common.GenerateAccessTokenResponse)
Expand All @@ -1172,6 +1173,58 @@ def test_generate_access_token_empty_call():
assert args[0] == common.GenerateAccessTokenRequest()


def test_generate_access_token_non_empty_request_with_auto_populated_field():
# This test is a coverage failsafe to make sure that UUID4 fields are
# automatically populated, according to AIP-4235, with non-empty requests.
client = IAMCredentialsClient(
credentials=ga_credentials.AnonymousCredentials(),
transport="grpc",
)

# Populate all string fields in the request which are not UUID4
# since we want to check that UUID4 are populated automatically
# if they meet the requirements of AIP 4235.
request = common.GenerateAccessTokenRequest(
name="name_value",
)

# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(
type(client.transport.generate_access_token), "__call__"
) as call:
client.generate_access_token(request=request)
call.assert_called()
_, args, _ = call.mock_calls[0]
assert args[0] == common.GenerateAccessTokenRequest(
name="name_value",
)


@pytest.mark.asyncio
async def test_generate_access_token_empty_call_async():
# This test is a coverage failsafe to make sure that totally empty calls,
# i.e. request == None and no flattened fields passed, work.
client = IAMCredentialsAsyncClient(
credentials=ga_credentials.AnonymousCredentials(),
transport="grpc_asyncio",
)

# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(
type(client.transport.generate_access_token), "__call__"
) as call:
# Designate an appropriate return value for the call.
call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
common.GenerateAccessTokenResponse(
access_token="access_token_value",
)
)
response = await client.generate_access_token()
call.assert_called()
_, args, _ = call.mock_calls[0]
assert args[0] == common.GenerateAccessTokenRequest()


@pytest.mark.asyncio
async def test_generate_access_token_async(
transport: str = "grpc_asyncio", request_type=common.GenerateAccessTokenRequest
Expand Down Expand Up @@ -1200,7 +1253,8 @@ async def test_generate_access_token_async(
# Establish that the underlying gRPC stub method was called.
assert len(call.mock_calls)
_, args, _ = call.mock_calls[0]
assert args[0] == common.GenerateAccessTokenRequest()
request = common.GenerateAccessTokenRequest()
assert args[0] == request

# Establish that the response is the type that we expect.
assert isinstance(response, common.GenerateAccessTokenResponse)
Expand Down Expand Up @@ -1423,7 +1477,8 @@ def test_generate_id_token(request_type, transport: str = "grpc"):
# Establish that the underlying gRPC stub method was called.
assert len(call.mock_calls) == 1
_, args, _ = call.mock_calls[0]
assert args[0] == common.GenerateIdTokenRequest()
request = common.GenerateIdTokenRequest()
assert args[0] == request

# Establish that the response is the type that we expect.
assert isinstance(response, common.GenerateIdTokenResponse)
Expand All @@ -1448,6 +1503,60 @@ def test_generate_id_token_empty_call():
assert args[0] == common.GenerateIdTokenRequest()


def test_generate_id_token_non_empty_request_with_auto_populated_field():
# This test is a coverage failsafe to make sure that UUID4 fields are
# automatically populated, according to AIP-4235, with non-empty requests.
client = IAMCredentialsClient(
credentials=ga_credentials.AnonymousCredentials(),
transport="grpc",
)

# Populate all string fields in the request which are not UUID4
# since we want to check that UUID4 are populated automatically
# if they meet the requirements of AIP 4235.
request = common.GenerateIdTokenRequest(
name="name_value",
audience="audience_value",
)

# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(
type(client.transport.generate_id_token), "__call__"
) as call:
client.generate_id_token(request=request)
call.assert_called()
_, args, _ = call.mock_calls[0]
assert args[0] == common.GenerateIdTokenRequest(
name="name_value",
audience="audience_value",
)


@pytest.mark.asyncio
async def test_generate_id_token_empty_call_async():
# This test is a coverage failsafe to make sure that totally empty calls,
# i.e. request == None and no flattened fields passed, work.
client = IAMCredentialsAsyncClient(
credentials=ga_credentials.AnonymousCredentials(),
transport="grpc_asyncio",
)

# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(
type(client.transport.generate_id_token), "__call__"
) as call:
# Designate an appropriate return value for the call.
call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
common.GenerateIdTokenResponse(
token="token_value",
)
)
response = await client.generate_id_token()
call.assert_called()
_, args, _ = call.mock_calls[0]
assert args[0] == common.GenerateIdTokenRequest()


@pytest.mark.asyncio
async def test_generate_id_token_async(
transport: str = "grpc_asyncio", request_type=common.GenerateIdTokenRequest
Expand Down Expand Up @@ -1476,7 +1585,8 @@ async def test_generate_id_token_async(
# Establish that the underlying gRPC stub method was called.
assert len(call.mock_calls)
_, args, _ = call.mock_calls[0]
assert args[0] == common.GenerateIdTokenRequest()
request = common.GenerateIdTokenRequest()
assert args[0] == request

# Establish that the response is the type that we expect.
assert isinstance(response, common.GenerateIdTokenResponse)
Expand Down Expand Up @@ -1698,7 +1808,8 @@ def test_sign_blob(request_type, transport: str = "grpc"):
# Establish that the underlying gRPC stub method was called.
assert len(call.mock_calls) == 1
_, args, _ = call.mock_calls[0]
assert args[0] == common.SignBlobRequest()
request = common.SignBlobRequest()
assert args[0] == request

# Establish that the response is the type that we expect.
assert isinstance(response, common.SignBlobResponse)
Expand All @@ -1722,6 +1833,55 @@ def test_sign_blob_empty_call():
assert args[0] == common.SignBlobRequest()


def test_sign_blob_non_empty_request_with_auto_populated_field():
# This test is a coverage failsafe to make sure that UUID4 fields are
# automatically populated, according to AIP-4235, with non-empty requests.
client = IAMCredentialsClient(
credentials=ga_credentials.AnonymousCredentials(),
transport="grpc",
)

# Populate all string fields in the request which are not UUID4
# since we want to check that UUID4 are populated automatically
# if they meet the requirements of AIP 4235.
request = common.SignBlobRequest(
name="name_value",
)

# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(type(client.transport.sign_blob), "__call__") as call:
client.sign_blob(request=request)
call.assert_called()
_, args, _ = call.mock_calls[0]
assert args[0] == common.SignBlobRequest(
name="name_value",
)


@pytest.mark.asyncio
async def test_sign_blob_empty_call_async():
# This test is a coverage failsafe to make sure that totally empty calls,
# i.e. request == None and no flattened fields passed, work.
client = IAMCredentialsAsyncClient(
credentials=ga_credentials.AnonymousCredentials(),
transport="grpc_asyncio",
)

# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(type(client.transport.sign_blob), "__call__") as call:
# Designate an appropriate return value for the call.
call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
common.SignBlobResponse(
key_id="key_id_value",
signed_blob=b"signed_blob_blob",
)
)
response = await client.sign_blob()
call.assert_called()
_, args, _ = call.mock_calls[0]
assert args[0] == common.SignBlobRequest()


@pytest.mark.asyncio
async def test_sign_blob_async(
transport: str = "grpc_asyncio", request_type=common.SignBlobRequest
Expand Down Expand Up @@ -1749,7 +1909,8 @@ async def test_sign_blob_async(
# Establish that the underlying gRPC stub method was called.
assert len(call.mock_calls)
_, args, _ = call.mock_calls[0]
assert args[0] == common.SignBlobRequest()
request = common.SignBlobRequest()
assert args[0] == request

# Establish that the response is the type that we expect.
assert isinstance(response, common.SignBlobResponse)
Expand Down Expand Up @@ -1954,7 +2115,8 @@ def test_sign_jwt(request_type, transport: str = "grpc"):
# Establish that the underlying gRPC stub method was called.
assert len(call.mock_calls) == 1
_, args, _ = call.mock_calls[0]
assert args[0] == common.SignJwtRequest()
request = common.SignJwtRequest()
assert args[0] == request

# Establish that the response is the type that we expect.
assert isinstance(response, common.SignJwtResponse)
Expand All @@ -1978,6 +2140,57 @@ def test_sign_jwt_empty_call():
assert args[0] == common.SignJwtRequest()


def test_sign_jwt_non_empty_request_with_auto_populated_field():
# This test is a coverage failsafe to make sure that UUID4 fields are
# automatically populated, according to AIP-4235, with non-empty requests.
client = IAMCredentialsClient(
credentials=ga_credentials.AnonymousCredentials(),
transport="grpc",
)

# Populate all string fields in the request which are not UUID4
# since we want to check that UUID4 are populated automatically
# if they meet the requirements of AIP 4235.
request = common.SignJwtRequest(
name="name_value",
payload="payload_value",
)

# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(type(client.transport.sign_jwt), "__call__") as call:
client.sign_jwt(request=request)
call.assert_called()
_, args, _ = call.mock_calls[0]
assert args[0] == common.SignJwtRequest(
name="name_value",
payload="payload_value",
)


@pytest.mark.asyncio
async def test_sign_jwt_empty_call_async():
# This test is a coverage failsafe to make sure that totally empty calls,
# i.e. request == None and no flattened fields passed, work.
client = IAMCredentialsAsyncClient(
credentials=ga_credentials.AnonymousCredentials(),
transport="grpc_asyncio",
)

# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(type(client.transport.sign_jwt), "__call__") as call:
# Designate an appropriate return value for the call.
call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
common.SignJwtResponse(
key_id="key_id_value",
signed_jwt="signed_jwt_value",
)
)
response = await client.sign_jwt()
call.assert_called()
_, args, _ = call.mock_calls[0]
assert args[0] == common.SignJwtRequest()


@pytest.mark.asyncio
async def test_sign_jwt_async(
transport: str = "grpc_asyncio", request_type=common.SignJwtRequest
Expand Down Expand Up @@ -2005,7 +2218,8 @@ async def test_sign_jwt_async(
# Establish that the underlying gRPC stub method was called.
assert len(call.mock_calls)
_, args, _ = call.mock_calls[0]
assert args[0] == common.SignJwtRequest()
request = common.SignJwtRequest()
assert args[0] == request

# Establish that the response is the type that we expect.
assert isinstance(response, common.SignJwtResponse)
Expand Down
Loading