fix: reuse Cloudflare session for site media
This commit is contained in:
@@ -25,6 +25,7 @@ class FakeResponse:
|
||||
"media": [{"type": "photo", "url": "https://example.test/1.jpg"}],
|
||||
}],
|
||||
"browser_state": {"cookies": [{"name": "cf_clearance"}]},
|
||||
"browser_user_agent": "Test Browser",
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +70,7 @@ class SourceAdapterTests(unittest.IsolatedAsyncioTestCase):
|
||||
self.assertEqual(items[0].text, "Title\n\nBody")
|
||||
self.assertEqual(items[0].media[0].url, "https://example.test/1.jpg")
|
||||
self.assertEqual(state["browser_state"]["cookies"][0]["name"], "cf_clearance")
|
||||
self.assertEqual(state["browser_user_agent"], "Test Browser")
|
||||
|
||||
async def test_followed_page_does_not_repeat_title(self) -> None:
|
||||
client = SiteParserClient(FollowedPageSession(), "http://worker", "token", "captcha", 30)
|
||||
|
||||
@@ -33,6 +33,22 @@ def test_video_provider() -> None:
|
||||
assert video_provider("http://127.0.0.1/video.mp4") is None
|
||||
|
||||
|
||||
def test_site_request_options() -> None:
|
||||
options = MediaUploader().site_request_options({
|
||||
"platform": "site",
|
||||
"source_url": "https://example.test/rss.xml",
|
||||
"source_runtime_state": {
|
||||
"browser_user_agent": "Test Browser",
|
||||
"browser_state": {"cookies": [{"name": "cf_clearance", "value": "secret"}]},
|
||||
},
|
||||
})
|
||||
assert options["headers"] == {
|
||||
"User-Agent": "Test Browser",
|
||||
"Referer": "https://example.test/rss.xml",
|
||||
}
|
||||
assert options["cookies"] == {"cf_clearance": "secret"}
|
||||
|
||||
|
||||
async def test_http_video_download() -> None:
|
||||
path = "/tmp/vkparser_tg_media_http_test.mp4"
|
||||
result = await MediaUploader().download_http_video(FakeSession(), "https://example.test/a.mp4", path)
|
||||
@@ -43,4 +59,5 @@ async def test_http_video_download() -> None:
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_video_provider()
|
||||
test_site_request_options()
|
||||
asyncio.run(test_http_video_download())
|
||||
|
||||
Reference in New Issue
Block a user