From 31b19da422a0c3bd7851439c28f6b7625efd78a4 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 26 Mar 2024 07:14:27 -0400 Subject: [PATCH] chore: Update gapic-generator-python to v1.16.1 (#279) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: Update gapic-generator-python to v1.16.1 PiperOrigin-RevId: 618243632 Source-Link: https://github.com/googleapis/googleapis/commit/078a38bd240827be8e69a5b62993380d1b047994 Source-Link: https://github.com/googleapis/googleapis-gen/commit/7af768c3f8ce58994482350f7401173329950a31 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiN2FmNzY4YzNmOGNlNTg5OTQ0ODIzNTBmNzQwMTE3MzMyOTk1MGEzMSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> --- .../gapic/orgpolicy_v2/test_org_policy.py | 686 +++++++++++++++++- 1 file changed, 662 insertions(+), 24 deletions(-) diff --git a/packages/google-cloud-org-policy/tests/unit/gapic/orgpolicy_v2/test_org_policy.py b/packages/google-cloud-org-policy/tests/unit/gapic/orgpolicy_v2/test_org_policy.py index 70220da3b1c4..cf2cf893184f 100644 --- a/packages/google-cloud-org-policy/tests/unit/gapic/orgpolicy_v2/test_org_policy.py +++ b/packages/google-cloud-org-policy/tests/unit/gapic/orgpolicy_v2/test_org_policy.py @@ -1108,7 +1108,8 @@ def test_list_constraints(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] == orgpolicy.ListConstraintsRequest() + request = orgpolicy.ListConstraintsRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListConstraintsPager) @@ -1131,6 +1132,56 @@ def test_list_constraints_empty_call(): assert args[0] == orgpolicy.ListConstraintsRequest() +def test_list_constraints_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 = OrgPolicyClient( + 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 = orgpolicy.ListConstraintsRequest( + parent="parent_value", + page_token="page_token_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_constraints), "__call__") as call: + client.list_constraints(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.ListConstraintsRequest( + parent="parent_value", + page_token="page_token_value", + ) + + +@pytest.mark.asyncio +async def test_list_constraints_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 = OrgPolicyAsyncClient( + 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.list_constraints), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + orgpolicy.ListConstraintsResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_constraints() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.ListConstraintsRequest() + + @pytest.mark.asyncio async def test_list_constraints_async( transport: str = "grpc_asyncio", request_type=orgpolicy.ListConstraintsRequest @@ -1157,7 +1208,8 @@ async def test_list_constraints_async( # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == orgpolicy.ListConstraintsRequest() + request = orgpolicy.ListConstraintsRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListConstraintsAsyncPager) @@ -1530,7 +1582,8 @@ def test_list_policies(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] == orgpolicy.ListPoliciesRequest() + request = orgpolicy.ListPoliciesRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListPoliciesPager) @@ -1553,6 +1606,56 @@ def test_list_policies_empty_call(): assert args[0] == orgpolicy.ListPoliciesRequest() +def test_list_policies_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 = OrgPolicyClient( + 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 = orgpolicy.ListPoliciesRequest( + parent="parent_value", + page_token="page_token_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_policies), "__call__") as call: + client.list_policies(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.ListPoliciesRequest( + parent="parent_value", + page_token="page_token_value", + ) + + +@pytest.mark.asyncio +async def test_list_policies_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 = OrgPolicyAsyncClient( + 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.list_policies), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + orgpolicy.ListPoliciesResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_policies() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.ListPoliciesRequest() + + @pytest.mark.asyncio async def test_list_policies_async( transport: str = "grpc_asyncio", request_type=orgpolicy.ListPoliciesRequest @@ -1579,7 +1682,8 @@ async def test_list_policies_async( # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == orgpolicy.ListPoliciesRequest() + request = orgpolicy.ListPoliciesRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListPoliciesAsyncPager) @@ -1953,7 +2057,8 @@ def test_get_policy(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] == orgpolicy.GetPolicyRequest() + request = orgpolicy.GetPolicyRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, orgpolicy.Policy) @@ -1977,6 +2082,55 @@ def test_get_policy_empty_call(): assert args[0] == orgpolicy.GetPolicyRequest() +def test_get_policy_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 = OrgPolicyClient( + 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 = orgpolicy.GetPolicyRequest( + name="name_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_policy), "__call__") as call: + client.get_policy(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.GetPolicyRequest( + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_policy_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 = OrgPolicyAsyncClient( + 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.get_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + orgpolicy.Policy( + name="name_value", + etag="etag_value", + ) + ) + response = await client.get_policy() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.GetPolicyRequest() + + @pytest.mark.asyncio async def test_get_policy_async( transport: str = "grpc_asyncio", request_type=orgpolicy.GetPolicyRequest @@ -2004,7 +2158,8 @@ async def test_get_policy_async( # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == orgpolicy.GetPolicyRequest() + request = orgpolicy.GetPolicyRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, orgpolicy.Policy) @@ -2187,7 +2342,8 @@ def test_get_effective_policy(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] == orgpolicy.GetEffectivePolicyRequest() + request = orgpolicy.GetEffectivePolicyRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, orgpolicy.Policy) @@ -2213,6 +2369,59 @@ def test_get_effective_policy_empty_call(): assert args[0] == orgpolicy.GetEffectivePolicyRequest() +def test_get_effective_policy_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 = OrgPolicyClient( + 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 = orgpolicy.GetEffectivePolicyRequest( + name="name_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_effective_policy), "__call__" + ) as call: + client.get_effective_policy(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.GetEffectivePolicyRequest( + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_effective_policy_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 = OrgPolicyAsyncClient( + 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.get_effective_policy), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + orgpolicy.Policy( + name="name_value", + etag="etag_value", + ) + ) + response = await client.get_effective_policy() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.GetEffectivePolicyRequest() + + @pytest.mark.asyncio async def test_get_effective_policy_async( transport: str = "grpc_asyncio", request_type=orgpolicy.GetEffectivePolicyRequest @@ -2242,7 +2451,8 @@ async def test_get_effective_policy_async( # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == orgpolicy.GetEffectivePolicyRequest() + request = orgpolicy.GetEffectivePolicyRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, orgpolicy.Policy) @@ -2431,7 +2641,8 @@ def test_create_policy(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] == orgpolicy.CreatePolicyRequest() + request = orgpolicy.CreatePolicyRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, orgpolicy.Policy) @@ -2455,6 +2666,55 @@ def test_create_policy_empty_call(): assert args[0] == orgpolicy.CreatePolicyRequest() +def test_create_policy_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 = OrgPolicyClient( + 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 = orgpolicy.CreatePolicyRequest( + parent="parent_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_policy), "__call__") as call: + client.create_policy(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.CreatePolicyRequest( + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_create_policy_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 = OrgPolicyAsyncClient( + 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.create_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + orgpolicy.Policy( + name="name_value", + etag="etag_value", + ) + ) + response = await client.create_policy() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.CreatePolicyRequest() + + @pytest.mark.asyncio async def test_create_policy_async( transport: str = "grpc_asyncio", request_type=orgpolicy.CreatePolicyRequest @@ -2482,7 +2742,8 @@ async def test_create_policy_async( # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == orgpolicy.CreatePolicyRequest() + request = orgpolicy.CreatePolicyRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, orgpolicy.Policy) @@ -2673,7 +2934,8 @@ def test_update_policy(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] == orgpolicy.UpdatePolicyRequest() + request = orgpolicy.UpdatePolicyRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, orgpolicy.Policy) @@ -2697,6 +2959,51 @@ def test_update_policy_empty_call(): assert args[0] == orgpolicy.UpdatePolicyRequest() +def test_update_policy_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 = OrgPolicyClient( + 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 = orgpolicy.UpdatePolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_policy), "__call__") as call: + client.update_policy(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.UpdatePolicyRequest() + + +@pytest.mark.asyncio +async def test_update_policy_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 = OrgPolicyAsyncClient( + 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.update_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + orgpolicy.Policy( + name="name_value", + etag="etag_value", + ) + ) + response = await client.update_policy() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.UpdatePolicyRequest() + + @pytest.mark.asyncio async def test_update_policy_async( transport: str = "grpc_asyncio", request_type=orgpolicy.UpdatePolicyRequest @@ -2724,7 +3031,8 @@ async def test_update_policy_async( # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == orgpolicy.UpdatePolicyRequest() + request = orgpolicy.UpdatePolicyRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, orgpolicy.Policy) @@ -2902,7 +3210,8 @@ def test_delete_policy(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] == orgpolicy.DeletePolicyRequest() + request = orgpolicy.DeletePolicyRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert response is None @@ -2924,6 +3233,52 @@ def test_delete_policy_empty_call(): assert args[0] == orgpolicy.DeletePolicyRequest() +def test_delete_policy_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 = OrgPolicyClient( + 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 = orgpolicy.DeletePolicyRequest( + name="name_value", + etag="etag_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_policy), "__call__") as call: + client.delete_policy(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.DeletePolicyRequest( + name="name_value", + etag="etag_value", + ) + + +@pytest.mark.asyncio +async def test_delete_policy_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 = OrgPolicyAsyncClient( + 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.delete_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_policy() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.DeletePolicyRequest() + + @pytest.mark.asyncio async def test_delete_policy_async( transport: str = "grpc_asyncio", request_type=orgpolicy.DeletePolicyRequest @@ -2946,7 +3301,8 @@ async def test_delete_policy_async( # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == orgpolicy.DeletePolicyRequest() + request = orgpolicy.DeletePolicyRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert response is None @@ -3132,7 +3488,8 @@ def test_create_custom_constraint(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] == orgpolicy.CreateCustomConstraintRequest() + request = orgpolicy.CreateCustomConstraintRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, constraint.CustomConstraint) @@ -3163,6 +3520,64 @@ def test_create_custom_constraint_empty_call(): assert args[0] == orgpolicy.CreateCustomConstraintRequest() +def test_create_custom_constraint_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 = OrgPolicyClient( + 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 = orgpolicy.CreateCustomConstraintRequest( + parent="parent_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_custom_constraint), "__call__" + ) as call: + client.create_custom_constraint(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.CreateCustomConstraintRequest( + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_create_custom_constraint_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 = OrgPolicyAsyncClient( + 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.create_custom_constraint), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + constraint.CustomConstraint( + name="name_value", + resource_types=["resource_types_value"], + method_types=[constraint.CustomConstraint.MethodType.CREATE], + condition="condition_value", + action_type=constraint.CustomConstraint.ActionType.ALLOW, + display_name="display_name_value", + description="description_value", + ) + ) + response = await client.create_custom_constraint() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.CreateCustomConstraintRequest() + + @pytest.mark.asyncio async def test_create_custom_constraint_async( transport: str = "grpc_asyncio", @@ -3198,7 +3613,8 @@ async def test_create_custom_constraint_async( # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == orgpolicy.CreateCustomConstraintRequest() + request = orgpolicy.CreateCustomConstraintRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, constraint.CustomConstraint) @@ -3413,7 +3829,8 @@ def test_update_custom_constraint(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] == orgpolicy.UpdateCustomConstraintRequest() + request = orgpolicy.UpdateCustomConstraintRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, constraint.CustomConstraint) @@ -3444,6 +3861,60 @@ def test_update_custom_constraint_empty_call(): assert args[0] == orgpolicy.UpdateCustomConstraintRequest() +def test_update_custom_constraint_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 = OrgPolicyClient( + 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 = orgpolicy.UpdateCustomConstraintRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_custom_constraint), "__call__" + ) as call: + client.update_custom_constraint(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.UpdateCustomConstraintRequest() + + +@pytest.mark.asyncio +async def test_update_custom_constraint_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 = OrgPolicyAsyncClient( + 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.update_custom_constraint), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + constraint.CustomConstraint( + name="name_value", + resource_types=["resource_types_value"], + method_types=[constraint.CustomConstraint.MethodType.CREATE], + condition="condition_value", + action_type=constraint.CustomConstraint.ActionType.ALLOW, + display_name="display_name_value", + description="description_value", + ) + ) + response = await client.update_custom_constraint() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.UpdateCustomConstraintRequest() + + @pytest.mark.asyncio async def test_update_custom_constraint_async( transport: str = "grpc_asyncio", @@ -3479,7 +3950,8 @@ async def test_update_custom_constraint_async( # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == orgpolicy.UpdateCustomConstraintRequest() + request = orgpolicy.UpdateCustomConstraintRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, constraint.CustomConstraint) @@ -3684,7 +4156,8 @@ def test_get_custom_constraint(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] == orgpolicy.GetCustomConstraintRequest() + request = orgpolicy.GetCustomConstraintRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, constraint.CustomConstraint) @@ -3715,6 +4188,64 @@ def test_get_custom_constraint_empty_call(): assert args[0] == orgpolicy.GetCustomConstraintRequest() +def test_get_custom_constraint_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 = OrgPolicyClient( + 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 = orgpolicy.GetCustomConstraintRequest( + name="name_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_custom_constraint), "__call__" + ) as call: + client.get_custom_constraint(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.GetCustomConstraintRequest( + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_custom_constraint_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 = OrgPolicyAsyncClient( + 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.get_custom_constraint), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + constraint.CustomConstraint( + name="name_value", + resource_types=["resource_types_value"], + method_types=[constraint.CustomConstraint.MethodType.CREATE], + condition="condition_value", + action_type=constraint.CustomConstraint.ActionType.ALLOW, + display_name="display_name_value", + description="description_value", + ) + ) + response = await client.get_custom_constraint() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.GetCustomConstraintRequest() + + @pytest.mark.asyncio async def test_get_custom_constraint_async( transport: str = "grpc_asyncio", request_type=orgpolicy.GetCustomConstraintRequest @@ -3749,7 +4280,8 @@ async def test_get_custom_constraint_async( # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == orgpolicy.GetCustomConstraintRequest() + request = orgpolicy.GetCustomConstraintRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, constraint.CustomConstraint) @@ -3948,7 +4480,8 @@ def test_list_custom_constraints(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] == orgpolicy.ListCustomConstraintsRequest() + request = orgpolicy.ListCustomConstraintsRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListCustomConstraintsPager) @@ -3973,6 +4506,60 @@ def test_list_custom_constraints_empty_call(): assert args[0] == orgpolicy.ListCustomConstraintsRequest() +def test_list_custom_constraints_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 = OrgPolicyClient( + 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 = orgpolicy.ListCustomConstraintsRequest( + parent="parent_value", + page_token="page_token_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_custom_constraints), "__call__" + ) as call: + client.list_custom_constraints(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.ListCustomConstraintsRequest( + parent="parent_value", + page_token="page_token_value", + ) + + +@pytest.mark.asyncio +async def test_list_custom_constraints_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 = OrgPolicyAsyncClient( + 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.list_custom_constraints), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + orgpolicy.ListCustomConstraintsResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_custom_constraints() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.ListCustomConstraintsRequest() + + @pytest.mark.asyncio async def test_list_custom_constraints_async( transport: str = "grpc_asyncio", request_type=orgpolicy.ListCustomConstraintsRequest @@ -4001,7 +4588,8 @@ async def test_list_custom_constraints_async( # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == orgpolicy.ListCustomConstraintsRequest() + request = orgpolicy.ListCustomConstraintsRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListCustomConstraintsAsyncPager) @@ -4390,7 +4978,8 @@ def test_delete_custom_constraint(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] == orgpolicy.DeleteCustomConstraintRequest() + request = orgpolicy.DeleteCustomConstraintRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert response is None @@ -4414,6 +5003,54 @@ def test_delete_custom_constraint_empty_call(): assert args[0] == orgpolicy.DeleteCustomConstraintRequest() +def test_delete_custom_constraint_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 = OrgPolicyClient( + 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 = orgpolicy.DeleteCustomConstraintRequest( + name="name_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_custom_constraint), "__call__" + ) as call: + client.delete_custom_constraint(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.DeleteCustomConstraintRequest( + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_custom_constraint_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 = OrgPolicyAsyncClient( + 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.delete_custom_constraint), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_custom_constraint() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == orgpolicy.DeleteCustomConstraintRequest() + + @pytest.mark.asyncio async def test_delete_custom_constraint_async( transport: str = "grpc_asyncio", @@ -4439,7 +5076,8 @@ async def test_delete_custom_constraint_async( # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == orgpolicy.DeleteCustomConstraintRequest() + request = orgpolicy.DeleteCustomConstraintRequest() + assert args[0] == request # Establish that the response is the type that we expect. assert response is None