Skip to content

Commit d131caa

Browse files
committed
fix rest of tests
1 parent 9acefb2 commit d131caa

File tree

3 files changed

+20
-32
lines changed

3 files changed

+20
-32
lines changed

aiobotocore/awsrequest.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ async def _content_prop(self):
99
"""Content of the response as bytes."""
1010

1111
if self._content is None:
12-
# Read the contents.
13-
# NOTE: requests would attempt to call stream and fall back
14-
# to a custom generator that would call read in a loop, but
15-
# we don't rely on this behavior
12+
# NOTE: this will cache the data in self.raw
1613
self._content = await self.raw.read() or bytes()
1714

1815
return self._content
@@ -22,12 +19,6 @@ def content(self):
2219
return self._content_prop()
2320

2421
async def _text_prop(self):
25-
"""Content of the response as a proper text type.
26-
27-
Uses the encoding type provided in the reponse headers to decode the
28-
response content into a proper text type. If the encoding is not
29-
present in the headers, UTF-8 is used as a default.
30-
"""
3122
encoding = botocore.utils.get_encoding_from_headers(self.headers)
3223
if encoding:
3324
return (await self.content).decode(encoding)

tests/botocore/test_utils.py

+18-21
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
from aiobotocore import utils
1616
from aiobotocore.utils import AioInstanceMetadataFetcher
1717
from botocore.utils import MetadataRetrievalError, BadIMDSRequestError
18+
import botocore.awsrequest
1819
import yarl
19-
20+
from tests.test_response import AsyncBytesIO
21+
from aiobotocore.awsrequest import AioAWSResponse
2022

2123
# From class TestContainerMetadataFetcher
2224
def fake_aiohttp_session(responses: Union[List[Tuple[Union[str, object], int]],
@@ -130,7 +132,7 @@ async def test_containermetadatafetcher_retrieve_url_not_json():
130132

131133
class TestInstanceMetadataFetcher(unittest.IsolatedAsyncioTestCase):
132134
async def asyncSetUp(self):
133-
urllib3_session_send = 'aiohttp.ClientSession._request'
135+
urllib3_session_send = 'aiobotocore.httpsession.AIOHTTPSession.send'
134136
self._urllib3_patch = mock.patch(urllib3_session_send)
135137
self._send = self._urllib3_patch.start()
136138
self._imds_responses = []
@@ -155,19 +157,14 @@ async def asyncTearDown(self):
155157

156158
def add_imds_response(self, body, status_code=200):
157159
loop = asyncio.get_running_loop()
158-
url = yarl.URL('http://169.254.169.254/')
159-
method = 'get'
160-
response = ClientResponse(method, url,
161-
request_info=RequestInfo(url, method, {}),
162-
writer=mock.AsyncMock(),
163-
continue100=None,
164-
timer=TimerNoop(),
165-
traces=[],
166-
loop=loop,
167-
session=mock.AsyncMock())
168-
response.status = status_code
169-
response._body = body
170-
response._headers = {}
160+
161+
response = AioAWSResponse(
162+
url='http://169.254.169.254/',
163+
status_code=status_code,
164+
headers={},
165+
raw=AsyncBytesIO(body)
166+
)
167+
171168
self._imds_responses.append(response)
172169

173170
def add_get_role_name_imds_response(self, role_name=None):
@@ -380,7 +377,7 @@ async def test_token_is_included(self):
380377
# Check that subsequent calls after getting the token include the token.
381378
self.assertEqual(self._send.call_count, 3)
382379
for call in self._send.call_args_list[1:]:
383-
self.assertEqual(call.kwargs['headers']['x-aws-ec2-metadata-token'],
380+
self.assertEqual(call[0][0].headers['x-aws-ec2-metadata-token'],
384381
'token')
385382
self.assertEqual(result, self._expected_creds)
386383

@@ -396,7 +393,7 @@ async def test_metadata_token_not_supported_404(self):
396393
user_agent=user_agent).retrieve_iam_role_credentials()
397394

398395
for call in self._send.call_args_list[1:]:
399-
self.assertNotIn('x-aws-ec2-metadata-token', call.kwargs['headers'])
396+
self.assertNotIn('x-aws-ec2-metadata-token', call[0][0].headers)
400397
self.assertEqual(result, self._expected_creds)
401398

402399
@pytest.mark.moto
@@ -411,7 +408,7 @@ async def test_metadata_token_not_supported_403(self):
411408
user_agent=user_agent).retrieve_iam_role_credentials()
412409

413410
for call in self._send.call_args_list[1:]:
414-
self.assertNotIn('x-aws-ec2-metadata-token', call.kwargs['headers'])
411+
self.assertNotIn('x-aws-ec2-metadata-token', call[0][0].headers)
415412
self.assertEqual(result, self._expected_creds)
416413

417414
@pytest.mark.moto
@@ -426,7 +423,7 @@ async def test_metadata_token_not_supported_405(self):
426423
user_agent=user_agent).retrieve_iam_role_credentials()
427424

428425
for call in self._send.call_args_list[1:]:
429-
self.assertNotIn('x-aws-ec2-metadata-token', call.kwargs['headers'])
426+
self.assertNotIn('x-aws-ec2-metadata-token', call[0][0].headers)
430427
self.assertEqual(result, self._expected_creds)
431428

432429
@pytest.mark.moto
@@ -441,7 +438,7 @@ async def test_metadata_token_not_supported_timeout(self):
441438
user_agent=user_agent).retrieve_iam_role_credentials()
442439

443440
for call in self._send.call_args_list[1:]:
444-
self.assertNotIn('x-aws-ec2-metadata-token', call.kwargs['headers'])
441+
self.assertNotIn('x-aws-ec2-metadata-token', call[0][0].headers)
445442
self.assertEqual(result, self._expected_creds)
446443

447444
@pytest.mark.moto
@@ -456,7 +453,7 @@ async def test_token_not_supported_exhaust_retries(self):
456453
user_agent=user_agent).retrieve_iam_role_credentials()
457454

458455
for call in self._send.call_args_list[1:]:
459-
self.assertNotIn('x-aws-ec2-metadata-token', call.kwargs['headers'])
456+
self.assertNotIn('x-aws-ec2-metadata-token', call[0][0].headers)
460457
self.assertEqual(result, self._expected_creds)
461458

462459
@pytest.mark.moto

tests/test_response.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self, *args, **kwargs):
2121
super().__init__(*args, **kwargs)
2222
self.content = self
2323

24-
async def read(self, amt):
24+
async def read(self, amt=-1):
2525
if amt == -1: # aiohttp to regular response
2626
amt = None
2727
return super().read(amt)

0 commit comments

Comments
 (0)