51 lines
2.2 KiB
Python
51 lines
2.2 KiB
Python
|
|
import unittest
|
|||
|
|
|
|||
|
|
from app.image_generation import build_prompt, content_blocks, section_context
|
|||
|
|
|
|||
|
|
|
|||
|
|
EDITOR_DATA = {
|
|||
|
|
"blocks": [
|
|||
|
|
{"id": "intro", "type": "paragraph", "data": {"text": "Вводный абзац."}},
|
|||
|
|
{"id": "middle-heading", "type": "header", "data": {"text": "Вторая часть"}},
|
|||
|
|
{"id": "middle", "type": "paragraph", "data": {"text": "Факты второй части."}},
|
|||
|
|
{"id": "image", "type": "image", "data": {"file": {"url": "https://example.test/old.jpg"}}},
|
|||
|
|
{"id": "final-heading", "type": "header", "data": {"text": "Вывод"}},
|
|||
|
|
{"id": "final", "type": "paragraph", "data": {"text": "Заключительный вывод статьи."}},
|
|||
|
|
]
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
class ImageGenerationPromptTest(unittest.TestCase):
|
|||
|
|
def test_cover_keeps_exact_title_and_forbids_extra_text(self):
|
|||
|
|
title = "КТО НАВЁЛ УДАР?"
|
|||
|
|
prompt = build_prompt("cover", title, EDITOR_DATA)
|
|||
|
|
|
|||
|
|
self.assertIn(title, prompt)
|
|||
|
|
self.assertIn("ЕДИНСТВЕННЫЙ ТЕКСТ", prompt)
|
|||
|
|
self.assertIn("Bebas Neue", prompt)
|
|||
|
|
|
|||
|
|
def test_body_prompts_are_distinct_and_forbid_text(self):
|
|||
|
|
middle = build_prompt("middle", "Заголовок", EDITOR_DATA)
|
|||
|
|
final = build_prompt("final", "Заголовок", EDITOR_DATA)
|
|||
|
|
|
|||
|
|
self.assertNotEqual(middle, final)
|
|||
|
|
self.assertIn("без текста", middle.lower())
|
|||
|
|
self.assertIn("без текста", final.lower())
|
|||
|
|
|
|||
|
|
def test_image_blocks_are_excluded_from_context(self):
|
|||
|
|
blocks = content_blocks(EDITOR_DATA)
|
|||
|
|
|
|||
|
|
self.assertNotIn("image", {block["id"] for block in blocks})
|
|||
|
|
self.assertIn("Факты второй части.", section_context(EDITOR_DATA, "middle"))
|
|||
|
|
self.assertIn("Заключительный вывод статьи.", section_context(EDITOR_DATA, "final"))
|
|||
|
|
|
|||
|
|
def test_inline_regeneration_uses_nearby_text(self):
|
|||
|
|
context = section_context(EDITOR_DATA, "middle", "image")
|
|||
|
|
|
|||
|
|
self.assertIn("Факты второй части.", context)
|
|||
|
|
self.assertIn("Заключительный вывод статьи.", context)
|
|||
|
|
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
unittest.main()
|