Skip to content

Commit d92e18d

Browse files
committed
cleanup default values and add test coverage
1 parent c8099f0 commit d92e18d

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

google/auth/aio/transport/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ def headers(self) -> Mapping[str, str]:
7171
raise NotImplementedError("headers must be implemented.")
7272

7373
@abc.abstractmethod
74-
async def content(self, chunk_size: int = 1024) -> AsyncGenerator[bytes, None]:
74+
async def content(self, chunk_size: int) -> AsyncGenerator[bytes, None]:
7575
"""The raw response content.
7676
7777
Args:
78-
chunk_size (int): The size of each chunk. Defaults to 1024.
78+
chunk_size (int): The size of each chunk.
7979
8080
Yields:
8181
AsyncGenerator[bytes, None]: An asynchronous generator yielding

google/auth/aio/transport/aiohttp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def headers(self) -> Mapping[str, str]:
5858
@_helpers.copy_docstring(transport.Response)
5959
async def content(self, chunk_size: int = 1024) -> AsyncGenerator[bytes, None]:
6060
try:
61-
async for chunk in self._response.content.iter_chunked(chunk_size):
61+
async for chunk in self._response.content.iter_chunked(chunk_size): # pragma: no branch
6262
yield chunk
6363
except aiohttp.ClientPayloadError as exc:
6464
raise exceptions.ResponseError(

tests/transport/aio/test_aiohttp.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,19 @@ async def test_request_call_success(self, aiohttp_request):
125125
assert response.headers == {"Content-Type": "application/json"}
126126
content = b"".join([chunk async for chunk in response.content()])
127127
assert content == b"Cavefish have no sight."
128+
129+
async def test_request_call_success_with_provided_session(self):
130+
mock_session = aiohttp.ClientSession()
131+
request = auth_aiohttp.Request(mock_session)
132+
with aioresponses() as m:
133+
mocked_chunks = [b"Cavefish ", b"have ", b"no ", b"sight."]
134+
mocked_response = b"".join(mocked_chunks)
135+
m.get("http://example.com", status=200, body=mocked_response)
136+
response = await request("http://example.com")
137+
assert response.status_code == 200
138+
assert response.headers == {"Content-Type": "application/json"}
139+
content = b"".join([chunk async for chunk in response.content()])
140+
assert content == b"Cavefish have no sight."
128141

129142
async def test_request_call_raises_client_error(self, aiohttp_request):
130143
with aioresponses() as m:

0 commit comments

Comments
 (0)