AI Update: اصلاحات را روی کدها و سرویسها اعمال کن
This commit is contained in:
@@ -654,7 +654,7 @@ class AdminBotService:
|
|||||||
|
|
||||||
tag_line = f"🏷 <b>موضوع:</b> #{post.subject}\n\n" if getattr(post, "subject", None) else ""
|
tag_line = f"🏷 <b>موضوع:</b> #{post.subject}\n\n" if getattr(post, "subject", None) else ""
|
||||||
|
|
||||||
if post.source_channel_id <= -900000000:
|
if -999999999 <= post.source_channel_id <= -900000000:
|
||||||
site_id = abs(post.source_channel_id + 900000000)
|
site_id = abs(post.source_channel_id + 900000000)
|
||||||
site = await self.repo.get_source_website_by_id(site_id)
|
site = await self.repo.get_source_website_by_id(site_id)
|
||||||
if site and site.name:
|
if site and site.name:
|
||||||
@@ -685,7 +685,7 @@ class AdminBotService:
|
|||||||
|
|
||||||
async def get_effective_review_channel_id(self, post: Post) -> Optional[int]:
|
async def get_effective_review_channel_id(self, post: Post) -> Optional[int]:
|
||||||
"""Determine which Admin Review Channel this post should be sent to."""
|
"""Determine which Admin Review Channel this post should be sent to."""
|
||||||
if post.source_channel_id <= -900000000:
|
if -999999999 <= post.source_channel_id <= -900000000:
|
||||||
site_id = abs(post.source_channel_id + 900000000)
|
site_id = abs(post.source_channel_id + 900000000)
|
||||||
site = await self.repo.get_source_website_by_id(site_id)
|
site = await self.repo.get_source_website_by_id(site_id)
|
||||||
if site and site.admin_channel_id:
|
if site and site.admin_channel_id:
|
||||||
|
|||||||
@@ -43,3 +43,39 @@ async def test_admin_bot_format_raw_post_caption_website():
|
|||||||
|
|
||||||
assert "دیجیاتو" in caption
|
assert "دیجیاتو" in caption
|
||||||
assert "وبسایت" in caption
|
assert "وبسایت" in caption
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_admin_bot_format_raw_post_caption_real_telegram_supergroup_id():
|
||||||
|
repo = MagicMock()
|
||||||
|
real_tg_id = -1009199982627
|
||||||
|
repo.get_source_by_channel_id = AsyncMock(return_value=SourceChannel(
|
||||||
|
id=1, channel_id=real_tg_id, username="mychannel", title="کانال تست"
|
||||||
|
))
|
||||||
|
repo.get_source_website_by_id = AsyncMock()
|
||||||
|
bot = AdminBotService(repo=repo, ai_processor=MagicMock(), queue=MagicMock())
|
||||||
|
|
||||||
|
post = Post(id=3, source_channel_id=real_tg_id, source_message_id=100, raw_text="متن خبر کانال")
|
||||||
|
caption = await bot._format_raw_post_caption(post)
|
||||||
|
|
||||||
|
assert "کانال تست" in caption
|
||||||
|
# Verify get_source_website_by_id was NEVER called for telegram channel
|
||||||
|
repo.get_source_website_by_id.assert_not_called()
|
||||||
|
repo.get_source_by_channel_id.assert_called_once_with(real_tg_id)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_admin_bot_get_effective_review_channel_id():
|
||||||
|
repo = MagicMock()
|
||||||
|
real_tg_id = -1009199982627
|
||||||
|
repo.get_source_by_channel_id = AsyncMock(return_value=SourceChannel(
|
||||||
|
id=1, channel_id=real_tg_id, username="mychannel", title="کانال تست", admin_channel_id=-100111222333
|
||||||
|
))
|
||||||
|
repo.get_source_website_by_id = AsyncMock()
|
||||||
|
bot = AdminBotService(repo=repo, ai_processor=MagicMock(), queue=MagicMock())
|
||||||
|
|
||||||
|
post = Post(id=3, source_channel_id=real_tg_id, source_message_id=100, raw_text="متن خبر")
|
||||||
|
rev_id = await bot.get_effective_review_channel_id(post)
|
||||||
|
assert rev_id == -100111222333
|
||||||
|
repo.get_source_website_by_id.assert_not_called()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user