def test_create_client_event(self):
        # Setup Expected Response
        request_id = "requestId37109963"
        event_id = "eventId278118624"
        expected_response = {"request_id": request_id, "event_id": event_id}
        expected_response = event_pb2.ClientEvent(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = talent_v4beta1.EventServiceClient()

        # Setup Request
        parent = client.project_path("[PROJECT]")
        client_event = {}

        response = client.create_client_event(parent, client_event)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = event_service_pb2.CreateClientEventRequest(
            parent=parent, client_event=client_event)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_create_client_event(self):
        # Setup Expected Response
        request_id = 'requestId37109963'
        event_id = 'eventId278118624'
        event_notes = 'eventNotes445073628'
        expected_response = {
            'request_id': request_id,
            'event_id': event_id,
            'event_notes': event_notes
        }
        expected_response = event_pb2.ClientEvent(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        patch = mock.patch('google.api_core.grpc_helpers.create_channel')
        with patch as create_channel:
            create_channel.return_value = channel
            client = talent_v4beta1.EventServiceClient()

        # Setup Request
        parent = client.tenant_path('[PROJECT]', '[TENANT]')
        client_event = {}

        response = client.create_client_event(parent, client_event)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = event_service_pb2.CreateClientEventRequest(
            parent=parent, client_event=client_event)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Esempio n. 3
0
def sample_create_client_event(project_id, tenant_id, request_id, event_id):
    """
    Creates a client event

    Args:
      project_id Your Google Cloud Project ID
      tenant_id Identifier of the Tenant
      request_id A unique ID generated in the API responses.
      Value should be set to the request_id from an API response.
      event_id A unique identifier, generated by the client application
    """
    # [START job_search_create_client_event_core]

    client = talent_v4beta1.EventServiceClient()

    # project_id = 'Your Google Cloud Project ID'
    # tenant_id = 'Your Tenant ID (using tenancy is optional)'
    # request_id = '[request_id from ResponseMetadata]'
    # event_id = '[Set this to a unique identifier]'

    if isinstance(project_id, six.binary_type):
        project_id = project_id.decode('utf-8')
    if isinstance(tenant_id, six.binary_type):
        tenant_id = tenant_id.decode('utf-8')
    if isinstance(request_id, six.binary_type):
        request_id = request_id.decode('utf-8')
    if isinstance(event_id, six.binary_type):
        event_id = event_id.decode('utf-8')
    parent = client.tenant_path(project_id, tenant_id)

    # The timestamp of the event as seconds of UTC time since Unix epoch
    # For more information on how to create google.protobuf.Timestamps
    # See:
    # https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/timestamp.proto
    seconds = 0
    create_time = {'seconds': seconds}

    # The type of event attributed to the behavior of the end user
    type_ = enums.JobEvent.JobEventType.VIEW

    # List of job names associated with this event
    jobs_element = 'projects/[Project ID]/tenants/[Tenant ID]/jobs/[Job ID]'
    jobs_element_2 = 'projects/[Project ID]/tenants/[Tenant ID]/jobs/[Job ID]'
    jobs = [jobs_element, jobs_element_2]
    job_event = {'type': type_, 'jobs': jobs}
    client_event = {
        'request_id': request_id,
        'event_id': event_id,
        'create_time': create_time,
        'job_event': job_event
    }

    response = client.create_client_event(parent, client_event)
    print(response)
    def test_create_client_event_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        patch = mock.patch('google.api_core.grpc_helpers.create_channel')
        with patch as create_channel:
            create_channel.return_value = channel
            client = talent_v4beta1.EventServiceClient()

        # Setup request
        parent = client.tenant_path('[PROJECT]', '[TENANT]')
        client_event = {}

        with pytest.raises(CustomException):
            client.create_client_event(parent, client_event)