예제 #1
0
    def expect(self,
               method,
               url,
               response_code,
               response_data,
               response_headers=None,
               request_payload='',
               request_headers=None,
               urlfetch_error=False,
               apiproxy_error=False,
               deadline_error=False,
               urlfetch_size_error=False):
        """Expects a certain request and response.
    
    Overrides any existing expectations for this stub.
    
    Args:
      method: The expected method.
      url: The expected URL to access.
      response_code: The expected response code.
      response_data: The expected response data.
      response_headers: Headers to serve back, if any.
      request_payload: The expected request payload, if any.
      request_headers: Any expected request headers.
      urlfetch_size_error: Set to True if this call should raise
        a urlfetch_errors.ResponseTooLargeError
      urlfetch_error: Set to True if this call should raise a
        urlfetch_errors.Error exception when made.
      apiproxy_error: Set to True if this call should raise an
        apiproxy_errors.Error exception when made.
      deadline_error: Set to True if this call should raise a
        google.appengine.runtime.DeadlineExceededError error.
    """
        error_instance = None
        if urlfetch_error:
            error_instance = apiproxy_errors.ApplicationError(
                urlfetch_service_pb.URLFetchServiceError.FETCH_ERROR,
                'mock error')
        elif urlfetch_size_error:
            error_instance = apiproxy_errors.ApplicationError(
                urlfetch_service_pb.URLFetchServiceError.RESPONSE_TOO_LARGE,
                'mock error')
        elif apiproxy_error:
            error_instance = apiproxy_errors.OverQuotaError()
        elif deadline_error:
            error_instance = runtime.DeadlineExceededError()

        self._expectations[(method.lower(),
                            url)] = (request_payload, request_headers,
                                     response_code, response_data,
                                     response_headers, error_instance)
예제 #2
0
 def test_task_rescheduling(self):
     """Tests that task is rescheduled for continuation."""
     tq_mock = mox.Mox()
     tq_mock.StubOutWithMock(taskqueue, 'add')
     taskqueue.add(name=mox.IsA(unicode),
                   method='POST',
                   url='/haiti/tasks/process_expirations',
                   queue_name='expiry',
                   params={'cursor': ''})
     tq_mock.ReplayAll()
     # DeadlineExceededErrors can be raised at any time. A convenient way for
     # us to raise it during this test execution is with utils.get_utcnow.
     with mock.patch('utils.get_utcnow') as get_utcnow_mock:
         get_utcnow_mock.side_effect = runtime.DeadlineExceededError()
         self.run_task('/haiti/tasks/process_expirations', method='POST')
     tq_mock.VerifyAll()
     tq_mock.UnsetStubs()
예제 #3
0
def test_tasklet4():
    raise runtime.DeadlineExceededError('Raise an error for testing.')
예제 #4
0
 def raise_deadline_exceeded_error(_):
     raise runtime.DeadlineExceededError()
예제 #5
0
def deadline_exceeded_side_effect(*args, **kwargs):
    del args, kwargs  # Unused.
    raise runtime.DeadlineExceededError()