def test_lookup_entry(self):
        # Setup Expected Response
        name = "name3373707"
        linked_resource = "linkedResource1544625012"
        user_specified_type = "userSpecifiedType-940364963"
        user_specified_system = "userSpecifiedSystem-1776119406"
        display_name = "displayName1615086568"
        description = "description-1724546052"
        expected_response = {
            "name": name,
            "linked_resource": linked_resource,
            "user_specified_type": user_specified_type,
            "user_specified_system": user_specified_system,
            "display_name": display_name,
            "description": description,
        }
        expected_response = datacatalog_pb2.Entry(**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 = datacatalog_v1beta1.DataCatalogClient()

        response = client.lookup_entry()
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = datacatalog_pb2.LookupEntryRequest()
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Ejemplo n.º 2
0
    def lookup_entry(
        self,
        linked_resource=None,
        sql_resource=None,
        retry=google.api_core.gapic_v1.method.DEFAULT,
        timeout=google.api_core.gapic_v1.method.DEFAULT,
        metadata=None,
    ):
        """
        Get an entry by target resource name. This method allows clients to use
        the resource name from the source Google Cloud Platform service to get the
        Cloud Data Catalog Entry.

        Example:
            >>> from google.cloud import datacatalog_v1beta1
            >>>
            >>> client = datacatalog_v1beta1.DataCatalogClient()
            >>>
            >>> response = client.lookup_entry()

        Args:
            linked_resource (str): The full name of the Google Cloud Platform resource the Data Catalog
                entry represents. See:
                https://cloud.google.com/apis/design/resource\_names#full\_resource\_name
                Full names are case-sensitive.

                Examples:
                "//bigquery.googleapis.com/projects/projectId/datasets/datasetId/tables/tableId".
                "//pubsub.googleapis.com/projects/projectId/topics/topicId"
            sql_resource (str): The SQL name of the entry. SQL names are case-sensitive.

                Examples:

                1. cloud\_pubsub.project\_id.topic\_id
                2. bigquery.project\_id.dataset\_id.table\_id
                3. datacatalog.project\_id.location\_id.entry\_group\_id.entry\_id
            retry (Optional[google.api_core.retry.Retry]):  A retry object used
                to retry requests. If ``None`` is specified, requests will not
                be retried.
            timeout (Optional[float]): The amount of time, in seconds, to wait
                for the request to complete. Note that if ``retry`` is
                specified, the timeout applies to each individual attempt.
            metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
                that is provided to the method.

        Returns:
            A :class:`~google.cloud.datacatalog_v1beta1.types.Entry` instance.

        Raises:
            google.api_core.exceptions.GoogleAPICallError: If the request
                    failed for any reason.
            google.api_core.exceptions.RetryError: If the request failed due
                    to a retryable error and retry attempts failed.
            ValueError: If the parameters are invalid.
        """
        # Wrap the transport method to add retry and timeout logic.
        if "lookup_entry" not in self._inner_api_calls:
            self._inner_api_calls[
                "lookup_entry"] = google.api_core.gapic_v1.method.wrap_method(
                    self.transport.lookup_entry,
                    default_retry=self._method_configs["LookupEntry"].retry,
                    default_timeout=self._method_configs["LookupEntry"].
                    timeout,
                    client_info=self._client_info,
                )

        # Sanity check: We have some fields which are mutually exclusive;
        # raise ValueError if more than one is sent.
        google.api_core.protobuf_helpers.check_oneof(
            linked_resource=linked_resource, sql_resource=sql_resource)

        request = datacatalog_pb2.LookupEntryRequest(
            linked_resource=linked_resource, sql_resource=sql_resource)
        return self._inner_api_calls["lookup_entry"](request,
                                                     retry=retry,
                                                     timeout=timeout,
                                                     metadata=metadata)