async def test_content(self):
     mock_response = mock.AsyncMock()
     mock_response.content.read.return_value = mock.sentinel.read
     combined_response = aiohttp_requests._CombinedResponse(
         response=mock_response)
     content = await combined_response.content()
     assert content == mock.sentinel.read
    async def test_content_compressed(self, urllib3_mock):
        rm = core.RequestMatch("url",
                               headers={"Content-Encoding": "gzip"},
                               payload="compressed")
        response = await rm.build_response(core.URL("url"))

        combined_response = aiohttp_requests._CombinedResponse(
            response=response)
        content = await combined_response.content()

        urllib3_mock.assert_called_once()
        assert content == "decompressed"
Exemplo n.º 3
0
    async def _get_body(response):
        """Access the response body from an HTTP response.

        Args:
            response (~requests.Response): The HTTP response object.

        Returns:
            bytes: The body of the ``response``.
        """
        wrapped_response = aiohttp_requests._CombinedResponse(response)
        content = await wrapped_response.data.read()
        return content
    async def test_raw_content(self):

        mock_response = mock.AsyncMock()
        mock_response.content.read.return_value = mock.sentinel.read
        combined_response = aiohttp_requests._CombinedResponse(
            response=mock_response)
        raw_content = await combined_response.raw_content()
        assert raw_content == mock.sentinel.read

        # Second call to validate the preconfigured path.
        combined_response._raw_content = mock.sentinel.stored_raw
        raw_content = await combined_response.raw_content()
        assert raw_content == mock.sentinel.stored_raw
Exemplo n.º 5
0
    async def test_download_full(self, add_files, authorized_transport, checksum):
        for info in ALL_FILES:
            actual_contents = self._get_contents(info)
            blob_name = get_blob_name(info)

            # Create the actual download object.
            media_url = utils.DOWNLOAD_URL_TEMPLATE.format(blob_name=blob_name)
            download = self._make_one(media_url, checksum=checksum)
            # Consume the resource.
            response = await download.consume(authorized_transport)
            response = tr_requests._CombinedResponse(response)
            assert response.status == http_client.OK
            content = await self._read_response_content(response)
            assert content == actual_contents
            await check_tombstoned(download, authorized_transport)
 def test__is_compressed_not(self):
     response = core.CallbackResult(headers={"Content-Encoding": "not"})
     combined_response = aiohttp_requests._CombinedResponse(response)
     compressed = combined_response._is_compressed()
     assert not compressed
async def _get_body(response):
    # TODO(asyncio): This code differs from sync. Leaving this comment in case
    # this difference causes downstream issues.
    wrapped_response = aiohttp_requests._CombinedResponse(response)
    content = await wrapped_response.raw_content()
    return content