from datetime import datetime from django.test import SimpleTestCase from django.template.loader import get_template from types import SimpleNamespace def _build_url_item(): return SimpleNamespace( id=1, url="https://example.com/article", ts_fetch=datetime(2025, 7, 1, 12, 0, 0), status="valid", ) def _build_url_content(images_url=None): return SimpleNamespace( date_published=datetime(2025, 7, 1, 11, 0, 0), title="Example title", description="Example description", content="Example body", valid_content=True, language="en", tags=["a", "b"], authors=["Author"], keywords=["kw"], image_main_url="https://example.com/img.jpg", images_url=images_url, videos_url=["https://example.com/v.mp4"], url_host="https://example.com", site_name="Example", ) class UrlDetailTemplateTests(SimpleTestCase): def _render(self, url_content): template = get_template("url_detail.html") context = { "url_item": _build_url_item(), "url_content": url_content, "sources": ["feeds"], "searches": ["child abuse"], "models": ["llama3.2:3b"], "prompt": "Summarize", "url_canonical": None, } return template.render(context) def test_image_urls_field_renders(self): html = self._render(_build_url_content(images_url=["https://example.com/1.jpg"])) self.assertIn("https://example.com/1.jpg", html) def test_legacy_image_urls_attribute_is_not_referenced(self): # Model exposes `images_url`, not `image_urls`. Rendering the template # must not fail nor silently rely on a non-existent field. with open( "fetcher/templates/url_detail.html" ) as f: source = f.read() self.assertNotIn("url_content.image_urls", source) self.assertIn("url_content.images_url", source)