def test_create_read_session(self):
        # Setup Expected Response
        name = "name3373707"
        expected_response = {"name": name}
        expected_response = storage_pb2.ReadSession(**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 = big_query_storage_client.BigQueryStorageClient()

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

        response = client.create_read_session(table_reference, parent)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = storage_pb2.CreateReadSessionRequest(
            table_reference=table_reference, parent=parent
        )
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Exemplo n.º 2
0
 def CreateReadSession(self, request, context):  # pylint: disable=unused-argument
     """CreateReadSession"""
     print("called CreateReadSession on a fake server")
     self._project_id = request.table_reference.project_id
     self._table_id = request.table_reference.table_id
     self._dataset_id = request.table_reference.dataset_id
     self._streams = []
     response = storage_pb2.ReadSession()
     response.avro_schema.schema = self._avro_schema
     for i in range(request.requested_streams):
         stream_name = self._build_stream_name(i)
         self._streams.append(stream_name)
         stream = response.streams.add()
         stream.name = stream_name
     return response