예제 #1
0
    def test_batch_create_sessions(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = spanner_pb2.BatchCreateSessionsResponse(
            **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 = spanner_v1.SpannerClient()

        # Setup Request
        database = client.database_path("[PROJECT]", "[INSTANCE]",
                                        "[DATABASE]")
        session_count = 185691686

        response = client.batch_create_sessions(database, session_count)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = spanner_pb2.BatchCreateSessionsRequest(
            database=database, session_count=session_count)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
예제 #2
0
        def mock_batch_create_sessions(db, session_count=10, timeout=10, metadata=[]):
            from google.cloud.spanner_v1.proto import spanner_pb2

            response = spanner_pb2.BatchCreateSessionsResponse()
            if session_count < 2:
                response.session.add()
            else:
                response.session.add()
                response.session.add()
            return response