-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is supposed to allow consuming a bug in creating the caching key. (cherry picked from commit 24f8217) (cherry picked from commit b749ac0)
- Loading branch information
Showing
2 changed files
with
12 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,35 @@ | ||
from django.test import TestCase | ||
from asgiref.sync import sync_to_async | ||
|
||
from pulpcore.download.factory import DownloaderFactory | ||
from pulpcore.plugin.models import Remote | ||
|
||
|
||
class DownloaderFactoryHeadersTestCase(TestCase): | ||
def test_user_agent_header(self): | ||
remote = Remote.objects.create(url="http://example.org/", name="foo") | ||
async def test_user_agent_header(self): | ||
remote = await sync_to_async(Remote.objects.create)(url="http://example.org/", name="foo") | ||
factory = DownloaderFactory(remote) | ||
downloader = factory.build(remote.url) | ||
default_user_agent = DownloaderFactory.user_agent() | ||
self.assertEqual(downloader.session.headers["User-Agent"], default_user_agent) | ||
remote.delete() | ||
await sync_to_async(remote.delete)() | ||
|
||
def test_custom_user_agent_header(self): | ||
remote = Remote.objects.create( | ||
async def test_custom_user_agent_header(self): | ||
remote = await sync_to_async(Remote.objects.create)( | ||
url="http://example.org/", headers=[{"User-Agent": "foo"}], name="foo" | ||
) | ||
factory = DownloaderFactory(remote) | ||
downloader = factory.build(remote.url) | ||
default_user_agent = DownloaderFactory.user_agent() | ||
expected_user_agent = f"{default_user_agent}, foo" | ||
self.assertEqual(downloader.session.headers["User-Agent"], expected_user_agent) | ||
remote.delete() | ||
await sync_to_async(remote.delete)() | ||
|
||
def test_custom_headers(self): | ||
remote = Remote.objects.create( | ||
async def test_custom_headers(self): | ||
remote = await sync_to_async(Remote.objects.create)( | ||
url="http://example.org/", headers=[{"Connection": "keep-alive"}], name="foo" | ||
) | ||
factory = DownloaderFactory(remote) | ||
downloader = factory.build(remote.url) | ||
self.assertEqual(downloader.session.headers["Connection"], "keep-alive") | ||
await sync_to_async(remote.delete)() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters