コード例 #1
0
    def test_run_query_wo_namespace_empty_result(self):
        from gcloudoem.datastore import datastore_v1_pb2 as datastore_pb

        KIND = 'Nonesuch'
        CURSOR = b'\x00'
        q_pb = self._make_query_pb(KIND)
        rsp_pb = datastore_pb.RunQueryResponse()
        rsp_pb.batch.end_cursor = CURSOR
        no_more = datastore_pb.QueryResultBatch.NO_MORE_RESULTS
        rsp_pb.batch.more_results = no_more
        rsp_pb.batch.entity_result_type = datastore_pb.EntityResult.FULL
        conn = self._makeOne()
        URI = '/'.join([
            conn.api_base_url,
            'datastore',
            conn.API_VERSION,
            'datasets',
            conn.dataset,
            'runQuery',
        ])
        http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
        pbs, end, more, skipped = conn.run_query(q_pb)
        self.assertEqual(pbs, [])
        self.assertEqual(end, CURSOR)
        self.assertTrue(more)
        self.assertEqual(skipped, 0)
        cw = http._called_with
        self._verifyProtobufCall(cw, URI, conn)
        rq_class = datastore_pb.RunQueryRequest
        request = rq_class()
        request.ParseFromString(cw['body'])
        self.assertEqual(request.partition_id.namespace, '')
        self.assertEqual(request.query, q_pb)
コード例 #2
0
    def test_run_query_w_namespace_nonempty_result(self):
        from gcloudoem.datastore import datastore_v1_pb2 as datastore_pb

        KIND = 'Kind'
        entity = datastore_pb.Entity()
        q_pb = self._make_query_pb(KIND)
        rsp_pb = datastore_pb.RunQueryResponse()
        rsp_pb.batch.entity_result.add(entity=entity)
        rsp_pb.batch.entity_result_type = 1  # FULL
        rsp_pb.batch.more_results = 3  # NO_MORE_RESULTS
        conn = self._makeOne()
        URI = '/'.join([
            conn.api_base_url,
            'datastore',
            conn.API_VERSION,
            'datasets',
            conn.dataset,
            'runQuery',
        ])
        http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
        pbs = conn.run_query(q_pb, 'NS')[0]
        self.assertEqual(len(pbs), 1)
        cw = http._called_with
        self._verifyProtobufCall(cw, URI, conn)
        rq_class = datastore_pb.RunQueryRequest
        request = rq_class()
        request.ParseFromString(cw['body'])
        self.assertEqual(request.partition_id.namespace, 'NS')
        self.assertEqual(request.query, q_pb)
コード例 #3
0
    def test_run_query_w_eventual_and_transaction(self):
        from gcloudoem.datastore import datastore_v1_pb2 as datastore_pb

        KIND = 'Nonesuch'
        CURSOR = b'\x00'
        TRANSACTION = b'TRANSACTION'
        q_pb = self._make_query_pb(KIND)
        rsp_pb = datastore_pb.RunQueryResponse()
        rsp_pb.batch.end_cursor = CURSOR
        no_more = datastore_pb.QueryResultBatch.NO_MORE_RESULTS
        rsp_pb.batch.more_results = no_more
        rsp_pb.batch.entity_result_type = datastore_pb.EntityResult.FULL
        conn = self._makeOne()
        self.assertRaises(ValueError,
                          conn.run_query,
                          q_pb,
                          eventual=True,
                          transaction_id=TRANSACTION)