コード例 #1
0
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']
コード例 #2
0
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)
コード例 #3
0
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']))
        ]
コード例 #4
0
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']
コード例 #5
0
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'
コード例 #6
0
def test_parse_common_project_path():
    expected = {
        "project": "nudibranch",
    }
    path = CampaignDraftServiceClient.common_project_path(**expected)

    # Check that the path construction is reversible.
    actual = CampaignDraftServiceClient.parse_common_project_path(path)
    assert expected == actual
コード例 #7
0
def test_parse_common_organization_path():
    expected = {
        "organization": "octopus",
    }
    path = CampaignDraftServiceClient.common_organization_path(**expected)

    # Check that the path construction is reversible.
    actual = CampaignDraftServiceClient.parse_common_organization_path(path)
    assert expected == actual
コード例 #8
0
def test_parse_common_folder_path():
    expected = {
        "folder": "clam",
    }
    path = CampaignDraftServiceClient.common_folder_path(**expected)

    # Check that the path construction is reversible.
    actual = CampaignDraftServiceClient.parse_common_folder_path(path)
    assert expected == actual
コード例 #9
0
def test_parse_common_billing_account_path():
    expected = {
        "billing_account": "abalone",
    }
    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
コード例 #10
0
def test_parse_campaign_path():
    expected = {
        "customer_id": "whelk",
        "campaign_id": "octopus",
    }
    path = CampaignDraftServiceClient.campaign_path(**expected)

    # Check that the path construction is reversible.
    actual = CampaignDraftServiceClient.parse_campaign_path(path)
    assert expected == actual
コード例 #11
0
def test_parse_common_location_path():
    expected = {
        "project": "winkle",
        "location": "nautilus",
    }
    path = CampaignDraftServiceClient.common_location_path(**expected)

    # Check that the path construction is reversible.
    actual = CampaignDraftServiceClient.parse_common_location_path(path)
    assert expected == actual
コード例 #12
0
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',
        )
コード例 #13
0
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',
        )
コード例 #14
0
def test_parse_campaign_draft_path():
    expected = {
        "customer_id": "mussel",
        "base_campaign_id": "winkle",
        "draft_id": "nautilus",
    }
    path = CampaignDraftServiceClient.campaign_draft_path(**expected)

    # Check that the path construction is reversible.
    actual = CampaignDraftServiceClient.parse_campaign_draft_path(path)
    assert expected == actual
コード例 #15
0
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'
コード例 #16
0
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']))
            ],
        )
コード例 #17
0
def test_common_billing_account_path():
    billing_account = "scallop"
    expected = "billingAccounts/{billing_account}".format(
        billing_account=billing_account, )
    actual = CampaignDraftServiceClient.common_billing_account_path(
        billing_account)
    assert expected == actual
コード例 #18
0
def test_campaign_draft_service_host_with_port():
    client = CampaignDraftServiceClient(
        credentials=ga_credentials.AnonymousCredentials(),
        client_options=client_options.ClientOptions(
            api_endpoint='googleads.googleapis.com:8000'),
    )
    assert client.transport._host == 'googleads.googleapis.com:8000'
コード例 #19
0
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', ))
コード例 #20
0
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)
コード例 #21
0
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,
    )
コード例 #22
0
def test_campaign_path():
    customer_id = "squid"
    campaign_id = "clam"
    expected = "customers/{customer_id}/campaigns/{campaign_id}".format(
        customer_id=customer_id,
        campaign_id=campaign_id,
    )
    actual = CampaignDraftServiceClient.campaign_path(customer_id, campaign_id)
    assert expected == actual
コード例 #23
0
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,
        )
コード例 #24
0
def test_common_location_path():
    project = "cuttlefish"
    location = "mussel"
    expected = "projects/{project}/locations/{location}".format(
        project=project,
        location=location,
    )
    actual = CampaignDraftServiceClient.common_location_path(project, location)
    assert expected == actual
コード例 #25
0
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'
コード例 #26
0
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',
            draft_id=829,
            base_campaign='base_campaign_value',
            name='name_value',
            draft_campaign='draft_campaign_value',
            status=campaign_draft_status.CampaignDraftStatusEnum.
            CampaignDraftStatus.UNKNOWN,
            has_experiment_running=True,
            long_running_operation='long_running_operation_value',
        )
        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.draft_id == 829
    assert response.base_campaign == 'base_campaign_value'
    assert response.name == 'name_value'
    assert response.draft_campaign == 'draft_campaign_value'
    assert response.status == campaign_draft_status.CampaignDraftStatusEnum.CampaignDraftStatus.UNKNOWN
    assert response.has_experiment_running is True
    assert response.long_running_operation == 'long_running_operation_value'
コード例 #27
0
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'
コード例 #28
0
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)
コード例 #29
0
def test_campaign_draft_path():
    customer_id = "oyster"
    base_campaign_id = "nudibranch"
    draft_id = "cuttlefish"
    expected = "customers/{customer_id}/campaignDrafts/{base_campaign_id}~{draft_id}".format(
        customer_id=customer_id,
        base_campaign_id=base_campaign_id,
        draft_id=draft_id,
    )
    actual = CampaignDraftServiceClient.campaign_draft_path(
        customer_id, base_campaign_id, draft_id)
    assert expected == actual
コード例 #30
0
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'