コード例 #1
0
    def testLookupFailureUnexpectedOk(self):
        request = self.makeLookupRequest()
        payload = request.SerializeToString()
        status = datastore.Status()
        status.code = 0  # Code.OK
        status.message = 'An error message.'
        response = httplib2.Response({
            'status': 400,
            'content-type': 'application/x-protobuf',
        })

        self.expectRequest(
            'https://example.com/datastore/v1/projects/foo:lookup',
            method='POST',
            body=payload,
            headers=self.makeExpectedHeaders(payload)).AndReturn(
                (response, status.SerializeToString()))
        self.mox.ReplayAll()

        with self.assertRaisesRegexp(
                datastore.RPCError, 'datastore call lookup failed: '
                'Unexpected OK error code with HTTP status code of 400. '
                'Message: An error message.'):
            self.conn.lookup(request)
        self.mox.VerifyAll()
コード例 #2
0
    def testLookupFailure(self):
        request = self.makeLookupRequest()
        payload = request.SerializeToString()
        response = datastore.Status()
        response.code = 3  # Code.INVALID_ARGUMENT
        response.message = 'An error message.'
        self.expectRequest(
            'https://example.com/datastore/v1/projects/foo:lookup',
            method='POST',
            body=payload,
            headers=self.makeExpectedHeaders(payload)).AndReturn(
                (TestResponse(status=400,
                              reason='IGNORED'), response.SerializeToString()))
        self.mox.ReplayAll()

        with self.assertRaisesRegexp(
                datastore.RPCError, 'datastore call lookup failed: '
                'Error code: INVALID_ARGUMENT. Message: An error message.'):
            self.conn.lookup(request)
        self.mox.VerifyAll()