Add unit tests and Gitea CI workflow for bug fixes
Tests / test (pull_request) Failing after 3m11s

- Add fetcher/tests/ with 21 tests covering all bug fixes:
  - test_utils: get_with_protocol URL normalization (5 tests)
  - test_config: scheduled_tasks.json PK uniqueness, Celery queue
    settings (7 tests)
  - test_publish: URL routing and view for /task/publish_<id>/ (4 tests)
  - test_template_field: url_detail.html renders images_url field (2 tests)
  - test_search_postprocess: URL host filtering and param stripping (3 tests)
- Replace empty fetcher/tests.py with tests/ package
- Add .gitea/workflows/test.yml: runs on PRs and pushes to main,
  installs dependencies and runs `manage.py test fetcher.tests`
This commit is contained in:
Luciano Gervasoni committed 2026-09-02 09:42:07 -03:00
1 parent 3a33697ca3
commit d18eda2fc4
8 files changed
+298 -3

No files matched your search

@@ -0,0 +1,62 @@
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)