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`
45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
from django.test import RequestFactory, SimpleTestCase
|
|
from django.urls import resolve, reverse
|
|
from unittest.mock import patch
|
|
|
|
from .. import views
|
|
|
|
|
|
class PublishRouteTests(SimpleTestCase):
|
|
def setUp(self):
|
|
self.factory = RequestFactory()
|
|
|
|
def test_publish_url_resolves_to_publish_view(self):
|
|
match = resolve("/task/publish_42/")
|
|
self.assertEqual(match.func, views.publish)
|
|
self.assertEqual(match.kwargs, {"id": 42})
|
|
|
|
def test_publish_url_reverse(self):
|
|
url = reverse("publish", args=[7])
|
|
self.assertEqual(url, "/task/publish_7/")
|
|
|
|
@patch("fetcher.views.Publisher")
|
|
def test_publish_invokes_publisher(self, mock_publisher_cls):
|
|
mock_instance = mock_publisher_cls.return_value
|
|
mock_instance.publish.return_value = None
|
|
|
|
request = self.factory.get("/task/publish_9/")
|
|
response = views.publish(request, 9)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
mock_publisher_cls.assert_called_once_with()
|
|
mock_instance.publish.assert_called_once_with(9)
|
|
self.assertIn(b"9", response.content)
|
|
|
|
@patch("fetcher.views.Publisher")
|
|
def test_publish_reports_error_gracefully(self, mock_publisher_cls):
|
|
mock_instance = mock_publisher_cls.return_value
|
|
mock_instance.publish.side_effect = RuntimeError("boom")
|
|
|
|
request = self.factory.get("/task/publish_3/")
|
|
response = views.publish(request, 3)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertIn(b"Error publishing", response.content)
|
|
mock_instance.publish.assert_called_once_with(3)
|