Skip to content

Commit

Permalink
Add tests for the URL of the download progress iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernricks committed Jul 4, 2023
1 parent a74db8c commit 2504aa5
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions tests/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,16 @@ async def test_download_progress_without_length(self):

class DownloadAsyncTestCase(IsolatedAsyncioTestCase):
async def test_download_async(self):
response = create_response()
response = create_response(url="http://some.url")
response.aiter_bytes.return_value = AsyncIteratorMock(["1", "2"])
stream = AsyncMock()
stream.__aenter__.return_value = response

async with download_async(
stream, content_length=2
) as download_iterable:
self.assertEqual(download_iterable.url, "http://some.url")

it = aiter(download_iterable)
content, progress = await anext(it)

Expand All @@ -120,13 +122,38 @@ async def test_download_async(self):
self.assertEqual(progress, 100)

async def test_download_async_content_length(self):
response = create_response(headers=MagicMock())
response = create_response(headers=MagicMock(), url="http://some.url")
response.aiter_bytes.return_value = AsyncIteratorMock(["1", "2"])
response.headers.get.return_value = 2
stream = AsyncMock()
stream.__aenter__.return_value = response

async with download_async(stream) as download_iterable:
self.assertEqual(download_iterable.url, "http://some.url")

it = aiter(download_iterable)
content, progress = await anext(it)

self.assertEqual(content, "1")
self.assertEqual(progress, 50)

content, progress = await anext(it)
self.assertEqual(content, "2")
self.assertEqual(progress, 100)

async def test_download_async_url(self):
response = create_response(url="http://some.url")
response.aiter_bytes.return_value = AsyncIteratorMock(["1", "2"])
stream = AsyncMock()
stream.__aenter__.return_value = response

async with download_async(
stream,
url="http://foo.bar",
content_length=2,
) as download_iterable:
self.assertEqual(download_iterable.url, "http://foo.bar")

it = aiter(download_iterable)
content, progress = await anext(it)

Expand Down

0 comments on commit 2504aa5

Please sign in to comment.