feat: filter site bodies before media upload

This commit is contained in:
Your Name
2026-08-10 22:52:23 +05:00
parent e5ef3fb9e8
commit aad9ee46eb
16 changed files with 127 additions and 61 deletions
+27
View File
@@ -35,6 +35,13 @@ class FollowedPageResponse(FakeResponse):
return data
class EmptyBodyResponse(FakeResponse):
async def json(self, **_kwargs):
data = await super().json(**_kwargs)
data["items"][0]["text"] = ""
return data
class FakeSession:
def post(self, *_args, **_kwargs):
return FakeResponse()
@@ -45,6 +52,11 @@ class FollowedPageSession(FakeSession):
return FollowedPageResponse()
class EmptyBodySession(FakeSession):
def post(self, *_args, **_kwargs):
return EmptyBodyResponse()
class SourceAdapterTests(unittest.IsolatedAsyncioTestCase):
async def test_worker_response_is_normalized(self) -> None:
client = SiteParserClient(FakeSession(), "http://worker", "token", "captcha", 30)
@@ -66,6 +78,17 @@ class SourceAdapterTests(unittest.IsolatedAsyncioTestCase):
"runtime_state_json": "{}",
})
self.assertEqual(items[0].text, "Title\nAuthor")
self.assertEqual(items[0].body_text, "Title\nAuthor")
async def test_title_is_not_counted_as_site_body(self) -> None:
client = SiteParserClient(EmptyBodySession(), "http://worker", "token", "captcha", 30)
items, _ = await client.fetch({
"url": "https://example.test/rss.xml",
"settings_json": '{"format":"rss"}',
"runtime_state_json": "{}",
})
self.assertEqual(items[0].text, "Title")
self.assertEqual(items[0].body_text, "")
def test_site_config_is_required(self) -> None:
with self.assertRaisesRegex(ValueError, "нужен конфиг"):
@@ -75,6 +98,10 @@ class SourceAdapterTests(unittest.IsolatedAsyncioTestCase):
with self.assertRaisesRegex(ValueError, "content_selector"):
validate_source_config("site", {"format": "rss", "follow_links": True})
def test_site_min_text_length_is_validated(self) -> None:
with self.assertRaisesRegex(ValueError, "min_text_length"):
validate_source_config("site", {"format": "rss", "min_text_length": "many"})
if __name__ == "__main__":
unittest.main()
+2 -2
View File
@@ -1,7 +1,7 @@
import asyncio
from pathlib import Path
from vk_parser_app.workers.vk_storage_uploader import TelegramStorageUploader, video_provider
from vk_parser_app.workers.media_uploader import MediaUploader, video_provider
class FakeContent:
@@ -35,7 +35,7 @@ def test_video_provider() -> None:
async def test_http_video_download() -> None:
path = "/tmp/vkparser_tg_media_http_test.mp4"
result = await TelegramStorageUploader().download_http_video(FakeSession(), "https://example.test/a.mp4", path)
result = await MediaUploader().download_http_video(FakeSession(), "https://example.test/a.mp4", path)
assert result["size_bytes"] == 5
assert Path(path).read_bytes() == b"video"
Path(path).unlink()