def fetch_mock(self, request, raise_error=True):
        """Fetch a mocked request

        Arguments:
            request (HTTPRequest): the request to fetch
        Returns:
            HTTPResponse constructed from the info stored in the mocks
        Raises:
            HTTPError if the cached response has status >= 400
        """
        mock_data = self.mocks[self.url_key(request.url)]
        code = mock_data.get("code", 200)
        headers = HTTPHeaders(mock_data.get("headers", {}))
        response = HTTPResponse(request, code, headers=headers)
        response.buffer = io.BytesIO(mock_data["body"].encode("utf8"))
        if code >= 400 and raise_error:
            raise HTTPError(mock_data["code"], response=response)

        return response
Fetch a mocked request

        Arguments:
            request (HTTPRequest): the request to fetch
        Returns:
            HTTPResponse constructed from the info stored in the mocks
        Raises:
            HTTPError if the cached response has status >= 400
        
binderhub/tests/utils.py