Beispiel #1
0
    def test_create_snapshot(self):
        # Setup Expected Response
        name_2 = "name2-1052831874"
        topic = "topic110546223"
        expected_response = {"name": name_2, "topic": topic}
        expected_response = pubsub_pb2.Snapshot(**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 = subscriber_client.SubscriberClient()

        # Setup Request
        name = client.snapshot_path("[PROJECT]", "[SNAPSHOT]")
        subscription = client.subscription_path("[PROJECT]", "[SUBSCRIPTION]")

        response = client.create_snapshot(name, subscription)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = pubsub_pb2.CreateSnapshotRequest(
            name=name, subscription=subscription)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Beispiel #2
0
    def test_update_snapshot(self):
        # Setup Expected Response
        name = "name3373707"
        topic = "topic110546223"
        expected_response = {"name": name, "topic": topic}
        expected_response = pubsub_pb2.Snapshot(**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 = subscriber_client.SubscriberClient()

        # Setup Request
        seconds = 123456
        expire_time = {"seconds": seconds}
        snapshot = {"expire_time": expire_time}
        paths_element = "expire_time"
        paths = [paths_element]
        update_mask = {"paths": paths}

        response = client.update_snapshot(snapshot, update_mask)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = pubsub_pb2.UpdateSnapshotRequest(
            snapshot=snapshot, update_mask=update_mask
        )
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_update_snapshot(self):
        # Setup Expected Response
        name = 'name3373707'
        topic = 'topic110546223'
        expected_response = {'name': name, 'topic': topic}
        expected_response = pubsub_pb2.Snapshot(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = subscriber_client.SubscriberClient(channel=channel)

        # Setup Request
        snapshot = {}
        update_mask = {}

        response = client.update_snapshot(snapshot, update_mask)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = pubsub_pb2.UpdateSnapshotRequest(
            snapshot=snapshot, update_mask=update_mask)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_create_snapshot(self):
        # Setup Expected Response
        name_2 = 'name2-1052831874'
        topic = 'topic110546223'
        expected_response = {'name': name_2, 'topic': topic}
        expected_response = pubsub_pb2.Snapshot(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = subscriber_client.SubscriberClient(channel=channel)

        # Setup Request
        name = client.snapshot_path('[PROJECT]', '[SNAPSHOT]')
        subscription = client.subscription_path('[PROJECT]', '[SUBSCRIPTION]')

        response = client.create_snapshot(name, subscription)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = pubsub_pb2.CreateSnapshotRequest(
            name=name, subscription=subscription)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_get_snapshot(self):
        # Setup Expected Response
        name = "name3373707"
        topic = "topic110546223"
        expected_response = {"name": name, "topic": topic}
        expected_response = pubsub_pb2.Snapshot(**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 = subscriber_client.SubscriberClient()

        # Setup Request
        snapshot = client.snapshot_path("[PROJECT]", "[SNAPSHOT]")

        response = client.get_snapshot(snapshot)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = pubsub_pb2.GetSnapshotRequest(snapshot=snapshot)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request