def test_get_campaign_draft(transport: str = 'grpc', request_type=campaign_draft_service.GetCampaignDraftRequest): client = CampaignDraftServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.get_campaign_draft), '__call__') as call: # Designate an appropriate return value for the call. call.return_value = campaign_draft.CampaignDraft( resource_name='resource_name_value', status=campaign_draft_status.CampaignDraftStatusEnum.CampaignDraftStatus.UNKNOWN, ) response = client.get_campaign_draft(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] assert args[0] == campaign_draft_service.GetCampaignDraftRequest() # Establish that the response is the type that we expect. assert isinstance(response, campaign_draft.CampaignDraft) assert response.resource_name == 'resource_name_value' assert response.status == campaign_draft_status.CampaignDraftStatusEnum.CampaignDraftStatus.UNKNOWN
def test_promote_campaign_draft(transport: str = 'grpc', request_type=campaign_draft_service.PromoteCampaignDraftRequest): client = CampaignDraftServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.promote_campaign_draft), '__call__') as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name='operations/spam') response = client.promote_campaign_draft(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] assert args[0] == campaign_draft_service.PromoteCampaignDraftRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future)
def test_list_campaign_draft_async_errors(transport: str = 'grpc', request_type=campaign_draft_service.ListCampaignDraftAsyncErrorsRequest): client = CampaignDraftServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.list_campaign_draft_async_errors), '__call__') as call: # Designate an appropriate return value for the call. call.return_value = campaign_draft_service.ListCampaignDraftAsyncErrorsResponse( next_page_token='next_page_token_value', ) response = client.list_campaign_draft_async_errors(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] assert args[0] == campaign_draft_service.ListCampaignDraftAsyncErrorsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListCampaignDraftAsyncErrorsPager) assert response.next_page_token == 'next_page_token_value'
def test_promote_campaign_draft_field_headers(): client = CampaignDraftServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = campaign_draft_service.PromoteCampaignDraftRequest() request.campaign_draft = 'campaign_draft/value' # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.promote_campaign_draft), '__call__') as call: call.return_value = operations_pb2.Operation(name='operations/op') client.promote_campaign_draft(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] assert args[0] == request # Establish that the field header was sent. _, _, kw = call.mock_calls[0] assert ( 'x-goog-request-params', 'campaign_draft=campaign_draft/value', ) in kw['metadata']
def test_list_campaign_draft_async_errors_field_headers(): client = CampaignDraftServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = campaign_draft_service.ListCampaignDraftAsyncErrorsRequest() request.resource_name = 'resource_name/value' # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.list_campaign_draft_async_errors), '__call__') as call: call.return_value = campaign_draft_service.ListCampaignDraftAsyncErrorsResponse() client.list_campaign_draft_async_errors(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] assert args[0] == request # Establish that the field header was sent. _, _, kw = call.mock_calls[0] assert ( 'x-goog-request-params', 'resource_name=resource_name/value', ) in kw['metadata']
def test_parse_common_project_path(): expected = { "project": "octopus", } path = CampaignDraftServiceClient.common_project_path(**expected) # Check that the path construction is reversible. actual = CampaignDraftServiceClient.parse_common_project_path(path) assert expected == actual
def test_parse_common_organization_path(): expected = { "organization": "clam", } path = CampaignDraftServiceClient.common_organization_path(**expected) # Check that the path construction is reversible. actual = CampaignDraftServiceClient.parse_common_organization_path(path) assert expected == actual
def test_parse_common_folder_path(): expected = { "folder": "abalone", } path = CampaignDraftServiceClient.common_folder_path(**expected) # Check that the path construction is reversible. actual = CampaignDraftServiceClient.parse_common_folder_path(path) assert expected == actual
def test_parse_common_billing_account_path(): expected = { "billing_account": "nautilus", } path = CampaignDraftServiceClient.common_billing_account_path(**expected) # Check that the path construction is reversible. actual = CampaignDraftServiceClient.parse_common_billing_account_path(path) assert expected == actual
def test_parse_campaign_draft_path(): expected = { "customer": "cuttlefish", "campaign_draft": "mussel", } path = CampaignDraftServiceClient.campaign_draft_path(**expected) # Check that the path construction is reversible. actual = CampaignDraftServiceClient.parse_campaign_draft_path(path) assert expected == actual
def test_parse_common_location_path(): expected = { "project": "cuttlefish", "location": "mussel", } path = CampaignDraftServiceClient.common_location_path(**expected) # Check that the path construction is reversible. actual = CampaignDraftServiceClient.parse_common_location_path(path) assert expected == actual
def test_parse_campaign_path(): expected = { "customer": "whelk", "campaign": "octopus", } path = CampaignDraftServiceClient.campaign_path(**expected) # Check that the path construction is reversible. actual = CampaignDraftServiceClient.parse_campaign_path(path) assert expected == actual
def test_campaign_draft_service_client_from_service_account_file(): creds = ga_credentials.AnonymousCredentials() with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: factory.return_value = creds client = CampaignDraftServiceClient.from_service_account_file("dummy/file/path.json") assert client.transport._credentials == creds client = CampaignDraftServiceClient.from_service_account_json("dummy/file/path.json") assert client.transport._credentials == creds assert client.transport._host == 'googleads.googleapis.com:443'
def test_promote_campaign_draft_flattened_error(): client = CampaignDraftServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.promote_campaign_draft( campaign_draft_service.PromoteCampaignDraftRequest(), campaign_draft='campaign_draft_value', )
def test_list_campaign_draft_async_errors_flattened_error(): client = CampaignDraftServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_campaign_draft_async_errors( campaign_draft_service.ListCampaignDraftAsyncErrorsRequest(), resource_name='resource_name_value', )
def test_list_campaign_draft_async_errors_pager(): client = CampaignDraftServiceClient( credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.list_campaign_draft_async_errors), '__call__') as call: # Set the response to a series of pages. call.side_effect = ( campaign_draft_service.ListCampaignDraftAsyncErrorsResponse( errors=[ status_pb2.Status(), status_pb2.Status(), status_pb2.Status(), ], next_page_token='abc', ), campaign_draft_service.ListCampaignDraftAsyncErrorsResponse( errors=[], next_page_token='def', ), campaign_draft_service.ListCampaignDraftAsyncErrorsResponse( errors=[ status_pb2.Status(), ], next_page_token='ghi', ), campaign_draft_service.ListCampaignDraftAsyncErrorsResponse( errors=[ status_pb2.Status(), status_pb2.Status(), ], ), RuntimeError, ) metadata = () metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata(( ('resource_name', ''), )), ) pager = client.list_campaign_draft_async_errors(request={}) assert pager._metadata == metadata results = [i for i in pager] assert len(results) == 6 assert all(isinstance(i, status_pb2.Status) for i in results)
def test_mutate_campaign_drafts_flattened_error(): client = CampaignDraftServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.mutate_campaign_drafts( campaign_draft_service.MutateCampaignDraftsRequest(), customer_id='customer_id_value', operations=[campaign_draft_service.CampaignDraftOperation(update_mask=field_mask_pb2.FieldMask(paths=['paths_value']))], )
def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.CampaignDraftServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), ) client = CampaignDraftServiceClient(transport=transport) assert client.transport is transport
def test_campaign_draft_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, 'default') as adc: adc.return_value = (ga_credentials.AnonymousCredentials(), None) CampaignDraftServiceClient() adc.assert_called_once_with(scopes=( 'https://www.googleapis.com/auth/adwords', ))
def test_client_withDEFAULT_CLIENT_INFO(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object(transports.CampaignDraftServiceTransport, '_prep_wrapped_messages') as prep: client = CampaignDraftServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) with mock.patch.object(transports.CampaignDraftServiceTransport, '_prep_wrapped_messages') as prep: transport_class = CampaignDraftServiceClient.get_transport_class() transport = transport_class( credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info)
def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = CampaignDraftServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) assert isinstance( client.transport, transports.CampaignDraftServiceGrpcTransport, )
def test_campaign_draft_service_client_from_service_account_info(): creds = ga_credentials.AnonymousCredentials() with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: factory.return_value = creds info = {"valid": True} client = CampaignDraftServiceClient.from_service_account_info(info) assert client.transport._credentials == creds assert client.transport._host == 'googleads.googleapis.com:443'
def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.CampaignDraftServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = CampaignDraftServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, )
def test_campaign_draft_service_client_client_options_from_dict(): with mock.patch('google.ads.googleads.v5.services.services.campaign_draft_service.transports.CampaignDraftServiceGrpcTransport.__init__') as grpc_transport: grpc_transport.return_value = None client = CampaignDraftServiceClient( client_options={'api_endpoint': 'squid.clam.whelk'} ) grpc_transport.assert_called_once_with( ssl_channel_credentials=None, credentials=None, host="squid.clam.whelk", client_info=transports.base.DEFAULT_CLIENT_INFO, )
def test_list_campaign_draft_async_errors_pages(): client = CampaignDraftServiceClient( credentials=ga_credentials.AnonymousCredentials, ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.list_campaign_draft_async_errors), '__call__') as call: # Set the response to a series of pages. call.side_effect = ( campaign_draft_service.ListCampaignDraftAsyncErrorsResponse( errors=[ status_pb2.Status(), status_pb2.Status(), status_pb2.Status(), ], next_page_token='abc', ), campaign_draft_service.ListCampaignDraftAsyncErrorsResponse( errors=[], next_page_token='def', ), campaign_draft_service.ListCampaignDraftAsyncErrorsResponse( errors=[ status_pb2.Status(), ], next_page_token='ghi', ), campaign_draft_service.ListCampaignDraftAsyncErrorsResponse( errors=[ status_pb2.Status(), status_pb2.Status(), ], ), RuntimeError, ) pages = list(client.list_campaign_draft_async_errors(request={}).pages) for page_, token in zip(pages, ['abc','def','ghi', '']): assert page_.raw_page.next_page_token == token
def test_list_campaign_draft_async_errors_flattened(): client = CampaignDraftServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.list_campaign_draft_async_errors), '__call__') as call: # Designate an appropriate return value for the call. call.return_value = campaign_draft_service.ListCampaignDraftAsyncErrorsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_campaign_draft_async_errors( resource_name='resource_name_value', ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] assert args[0].resource_name == 'resource_name_value'
def test_promote_campaign_draft_flattened(): client = CampaignDraftServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.promote_campaign_draft), '__call__') as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name='operations/op') # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.promote_campaign_draft( campaign_draft='campaign_draft_value', ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] assert args[0].campaign_draft == 'campaign_draft_value'
def test_campaign_draft_service_grpc_lro_client(): client = CampaignDraftServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport='grpc', ) transport = client.transport # Ensure that we have a api-core operations client. assert isinstance( transport.operations_client, operations_v1.OperationsClient, ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client
def test_mutate_campaign_drafts_flattened(): client = CampaignDraftServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.mutate_campaign_drafts), '__call__') as call: # Designate an appropriate return value for the call. call.return_value = campaign_draft_service.MutateCampaignDraftsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.mutate_campaign_drafts( customer_id='customer_id_value', operations=[campaign_draft_service.CampaignDraftOperation(update_mask=field_mask_pb2.FieldMask(paths=['paths_value']))], ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] assert args[0].customer_id == 'customer_id_value' assert args[0].operations == [campaign_draft_service.CampaignDraftOperation(update_mask=field_mask_pb2.FieldMask(paths=['paths_value']))]
def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" assert CampaignDraftServiceClient._get_default_mtls_endpoint(None) is None assert CampaignDraftServiceClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint assert CampaignDraftServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint assert CampaignDraftServiceClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint assert CampaignDraftServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint assert CampaignDraftServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi