def _MockExecuteFunction(self, function, *args, **kwargs): response = test_config.FakeResponse( {'x-ms-substatus': SubStatusCodes.WRITE_FORBIDDEN}) raise exceptions.CosmosHttpResponseError( status_code=StatusCodes.FORBIDDEN, message="Write Forbidden", response=response)
def _MockExecuteFunctionSessionReadFailureOnce(self, function, *args, **kwargs): response = test_config.FakeResponse( {HttpHeaders.SubStatus: SubStatusCodes.READ_SESSION_NOTAVAILABLE}) raise exceptions.CosmosHttpResponseError( status_code=StatusCodes.NOT_FOUND, message="Read Session not available", response=response)
def __call__(self, func, *args, **kwargs): self.counter = self.counter + 1 if self.counter % 3 == 0: return self.org_func(func, *args, **kwargs) else: raise errors.CosmosHttpResponseError( status_code=10054, message="Connection was reset", response=test_config.FakeResponse({}))
def _MockExecuteFunction(self, function, *args, **kwargs): response = test_config.FakeResponse({ HttpHeaders.RetryAfterInMilliseconds: self.retry_after_in_milliseconds }) raise errors.CosmosHttpResponseError( status_code=StatusCodes.TOO_MANY_REQUESTS, message="Request rate is too large", response=response)
def MockExecuteFunction(self, function, *args, **kwargs): global location_changed if self.endpoint_discovery_retry_count == 2: _retry_utility.ExecuteFunction = self.OriginalExecuteFunction return (json.dumps([{ 'id': 'mock database' }]), None) else: self.endpoint_discovery_retry_count += 1 location_changed = True raise exceptions.CosmosHttpResponseError( status_code=StatusCodes.FORBIDDEN, message="Forbidden", response=test_config.FakeResponse({'x-ms-substatus' : 3}))
def _MockExecuteFunctionEndpointDiscover(self, function, *args, **kwargs): self.counter += 1 if self.counter >= 10 or (len(args) > 0 and args[1].operation_type == documents._OperationType.Read): return ({}, {}) else: self.endpoint_sequence.append(args[1].location_endpoint_to_route) response = test_config.FakeResponse( {HttpHeaders.SubStatus: SubStatusCodes.WRITE_FORBIDDEN}) raise errors.CosmosHttpResponseError( status_code=StatusCodes.FORBIDDEN, message="Request is not permitted in this region", response=response)
def _MockExecuteFunctionSessionReadFailureTwice(self, function, *args, **kwargs): request = args[1] if self.counter == 0: if not self.use_multiple_write_locations: expected_endpoint = self.database_account.WritableLocations[0][ 'databaseAccountEndpoint'] if self.is_preferred_locations_list_empty else self.preferred_locations[ 0] else: expected_endpoint = self.endpoint_by_location[ self.preferred_locations[0]] self.assertFalse( request.should_clear_session_token_on_session_read_failure) elif self.counter == 1: expected_endpoint = self.database_account.WritableLocations[0][ 'databaseAccountEndpoint'] if not self.use_multiple_write_locations: self.assertTrue( request.should_clear_session_token_on_session_read_failure) else: self.assertFalse( request.should_clear_session_token_on_session_read_failure) elif self.counter == 2: expected_endpoint = self.endpoint_by_location[ self.preferred_locations[1]] self.assertFalse( request.should_clear_session_token_on_session_read_failure) elif self.counter == 3: expected_endpoint = self.database_account.ReadableLocations[2][ 'databaseAccountEndpoint'] self.assertTrue( request.should_clear_session_token_on_session_read_failure) self.assertEqual(expected_endpoint, request.location_endpoint_to_route) self.counter += 1 response = test_config.FakeResponse( {HttpHeaders.SubStatus: SubStatusCodes.READ_SESSION_NOTAVAILABLE}) raise exceptions.CosmosHttpResponseError( status_code=StatusCodes.NOT_FOUND, message="Read Session not available", response=response)