from __future__ import annotations import unittest from vk_parser_app.source_adapters import SiteParserClient, validate_source_config class FakeResponse: status = 200 async def __aenter__(self): return self async def __aexit__(self, *_args): return None async def json(self, **_kwargs): return { "items": [{ "external_id": "post-1", "url": "https://example.test/1", "title": "Title", "text": "Body", "published_at": "2026-08-10T10:00:00+00:00", "media": [{"type": "photo", "url": "https://example.test/1.jpg"}], }], "browser_state": {"cookies": [{"name": "cf_clearance"}]}, } class FakeSession: def post(self, *_args, **_kwargs): return FakeResponse() class SourceAdapterTests(unittest.IsolatedAsyncioTestCase): async def test_worker_response_is_normalized(self) -> None: client = SiteParserClient(FakeSession(), "http://worker", "token", "captcha", 30) items, state = await client.fetch({ "url": "https://example.test/rss.xml", "settings_json": '{"format":"rss","access":"auto","interval_minutes":30}', "runtime_state_json": '{}', }) 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") def test_site_config_is_required(self) -> None: with self.assertRaisesRegex(ValueError, "нужен конфиг"): validate_source_config("site", {}) if __name__ == "__main__": unittest.main()