Exemple #1
0
    def test_update_feed(self):
        # Setup Expected Response
        name = "name3373707"
        expected_response = {"name": name}
        expected_response = asset_service_pb2.Feed(**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 = asset_v1p2beta1.AssetServiceClient()

        # Setup Request
        feed = {}
        update_mask = {}

        response = client.update_feed(feed, update_mask)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = asset_service_pb2.UpdateFeedRequest(
            feed=feed, update_mask=update_mask)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Exemple #2
0
    def test_create_feed(self):
        # Setup Expected Response
        name = "name3373707"
        expected_response = {"name": name}
        expected_response = asset_service_pb2.Feed(**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 = asset_v1p2beta1.AssetServiceClient()

        # Setup Request
        parent = "parent-995424086"
        feed_id = "feedId-976011428"
        feed = {}

        response = client.create_feed(parent, feed_id, feed)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = asset_service_pb2.CreateFeedRequest(parent=parent,
                                                               feed_id=feed_id,
                                                               feed=feed)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Exemple #3
0
    def test_batch_get_assets_history(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = asset_service_pb2.BatchGetAssetsHistoryResponse(
            **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 = asset_v1p2beta1.AssetServiceClient()

        # Setup Request
        parent = "parent-995424086"
        asset_names = []
        content_type = enums.ContentType.CONTENT_TYPE_UNSPECIFIED

        response = client.batch_get_assets_history(parent, asset_names,
                                                   content_type)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = asset_service_pb2.BatchGetAssetsHistoryRequest(
            parent=parent, asset_names=asset_names, content_type=content_type)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Exemple #4
0
    def test_export_assets(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = asset_service_pb2.ExportAssetsResponse(
            **expected_response)
        operation = operations_pb2.Operation(
            name="operations/test_export_assets", done=True)
        operation.response.Pack(expected_response)

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

        # Setup Request
        parent = "parent-995424086"
        output_config = {}

        response = client.export_assets(parent, output_config)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = asset_service_pb2.ExportAssetsRequest(
            parent=parent, output_config=output_config)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Exemple #5
0
def sample_delete_feed():
    # Create a client
    client = asset_v1p2beta1.AssetServiceClient()

    # Initialize request argument(s)
    request = asset_v1p2beta1.DeleteFeedRequest(name="name_value", )

    # Make the request
    client.delete_feed(request=request)
def list_feeds(parent_resource):
    # [START asset_quickstart_list_feeds]
    from google.cloud import asset_v1p2beta1

    # TODO parent_resource = 'Parent resource you want to list all feeds'

    client = asset_v1p2beta1.AssetServiceClient()
    response = client.list_feeds(parent_resource)
    print('feeds: {}'.format(response.feeds))
Exemple #7
0
def delete_feed(feed_name):
    # [START asset_quickstart_delete_feed]
    from google.cloud import asset_v1p2beta1

    # TODO feed_name = 'Feed name you want to delete'

    client = asset_v1p2beta1.AssetServiceClient()
    client.delete_feed(feed_name)
    print('deleted_feed')
Exemple #8
0
def get_feed(feed_name):
    # [START asset_quickstart_get_feed]
    from google.cloud import asset_v1p2beta1

    # TODO feed_name = 'Feed Name you want to get'

    client = asset_v1p2beta1.AssetServiceClient()
    response = client.get_feed(feed_name)
    print('gotten_feed: {}'.format(response))
def sample_get_feed():
    # Create a client
    client = asset_v1p2beta1.AssetServiceClient()

    # Initialize request argument(s)
    request = asset_v1p2beta1.GetFeedRequest(name="name_value", )

    # Make the request
    response = client.get_feed(request=request)

    # Handle the response
    print(response)
def sample_list_feeds():
    # Create a client
    client = asset_v1p2beta1.AssetServiceClient()

    # Initialize request argument(s)
    request = asset_v1p2beta1.ListFeedsRequest(parent="parent_value", )

    # Make the request
    response = client.list_feeds(request=request)

    # Handle the response
    print(response)
Exemple #11
0
    def test_delete_feed_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 = asset_v1p2beta1.AssetServiceClient()

        # Setup request
        name = client.feed_path("[PROJECT]", "[FEED]")

        with pytest.raises(CustomException):
            client.delete_feed(name)
Exemple #12
0
    def test_list_feeds_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 = asset_v1p2beta1.AssetServiceClient()

        # Setup request
        parent = "parent-995424086"

        with pytest.raises(CustomException):
            client.list_feeds(parent)
Exemple #13
0
    def test_update_feed_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 = asset_v1p2beta1.AssetServiceClient()

        # Setup request
        feed = {}
        update_mask = {}

        with pytest.raises(CustomException):
            client.update_feed(feed, update_mask)
def sample_update_feed():
    # Create a client
    client = asset_v1p2beta1.AssetServiceClient()

    # Initialize request argument(s)
    feed = asset_v1p2beta1.Feed()
    feed.name = "name_value"

    request = asset_v1p2beta1.UpdateFeedRequest(feed=feed, )

    # Make the request
    response = client.update_feed(request=request)

    # Handle the response
    print(response)
Exemple #15
0
    def test_batch_get_assets_history_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 = asset_v1p2beta1.AssetServiceClient()

        # Setup request
        parent = "parent-995424086"
        asset_names = []
        content_type = enums.ContentType.CONTENT_TYPE_UNSPECIFIED

        with pytest.raises(CustomException):
            client.batch_get_assets_history(parent, asset_names, content_type)
Exemple #16
0
    def test_delete_feed(self):
        channel = ChannelStub()
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = asset_v1p2beta1.AssetServiceClient()

        # Setup Request
        name = client.feed_path("[PROJECT]", "[FEED]")

        client.delete_feed(name)

        assert len(channel.requests) == 1
        expected_request = asset_service_pb2.DeleteFeedRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
def create_feed(project_id, feed_id, asset_names, topic):
    # [START asset_quickstart_create_feed]
    from google.cloud import asset_v1p2beta1
    from google.cloud.asset_v1p2beta1.proto import asset_service_pb2

    # TODO project_id = 'Your Google Cloud Project ID'
    # TODO feed_id = 'Feed ID you want to create'
    # TODO asset_names = 'List of asset names the feed listen to'
    # TODO topic = "Topic name of the feed"

    client = asset_v1p2beta1.AssetServiceClient()
    parent = "projects/{}".format(project_id)
    feed = asset_service_pb2.Feed()
    feed.asset_names.extend(asset_names)
    feed.feed_output_config.pubsub_destination.topic = topic
    response = client.create_feed(parent, feed_id, feed)
    print('feed: {}'.format(response))
def update_feed(feed_name, topic):
    # [START asset_quickstart_update_feed]
    from google.cloud import asset_v1p2beta1
    from google.cloud.asset_v1p2beta1.proto import asset_service_pb2
    from google.protobuf import field_mask_pb2

    # TODO feed_name = 'Feed Name you want to update'
    # TODO topic = "Topic name you want to update with"

    client = asset_v1p2beta1.AssetServiceClient()
    feed = asset_service_pb2.Feed()
    feed.name = feed_name
    feed.feed_output_config.pubsub_destination.topic = topic
    update_mask = field_mask_pb2.FieldMask()
    # In this example, we update topic of the feed
    update_mask.paths.append("feed_output_config.pubsub_destination.topic")
    response = client.update_feed(feed, update_mask)
    print('updated_feed: {}'.format(response))
Exemple #19
0
    def test_export_assets_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name="operations/test_export_assets_exception", done=True)
        operation.error.CopyFrom(error)

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

        # Setup Request
        parent = "parent-995424086"
        output_config = {}

        response = client.export_assets(parent, output_config)
        exception = response.exception()
        assert exception.errors[0] == error
Exemple #20
0
    def test_get_feed(self):
        # Setup Expected Response
        name_2 = "name2-1052831874"
        expected_response = {"name": name_2}
        expected_response = asset_service_pb2.Feed(**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 = asset_v1p2beta1.AssetServiceClient()

        # Setup Request
        name = client.feed_path("[PROJECT]", "[FEED]")

        response = client.get_feed(name)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = asset_service_pb2.GetFeedRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Exemple #21
0
    def test_list_feeds(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = asset_service_pb2.ListFeedsResponse(
            **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 = asset_v1p2beta1.AssetServiceClient()

        # Setup Request
        parent = "parent-995424086"

        response = client.list_feeds(parent)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = asset_service_pb2.ListFeedsRequest(parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request