Private
Public Access
scripts/upgrade.sh now fetches tags and does a detached-HEAD checkout of the latest one (git tag --sort=-creatordate | head -n1), matching the ds-chat project's deploy/upgrade.sh exactly rather than a plain git pull on whatever branch happened to be checked out. Errors clearly if the repo has no tags yet (true for Evection right now — nothing to deploy until a release is tagged and pushed), and no-ops cleanly if already on the latest tag. scripts/install.sh does the same tag pin on first install (falling back to whatever's checked out if no tags exist yet), so the very first deploy is consistent with every upgrade after it. Added a GET /health/ endpoint (apps.core.views.health) that checks DB connectivity and is exempt from the first-run setup redirect, for the upgrade script's post-restart verification (curled over the gunicorn unix socket, same as ds-chat's curl-based check) and for any external uptime monitor. While wiring the setup-wizard exemption for /health/, found that SetupWizardMiddleware._a_user_exists's reset fixture was scoped only to apps/accounts/tests.py, so a test anywhere else that creates a user and makes a request could leak a stale "a user exists" into later test files with no reset — confirmed this concretely by temporarily breaking the new exemption and watching the "works before setup" test still pass purely from accounts/tests.py leaving the module-order-adjacent apps/articles tests to poison the shared class attribute. Moved the fixture to a new top-level conftest.py so it's autouse across every test file, which also makes the new health-check test meaningful regardless of run order. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
80 lines
3.0 KiB
Python
80 lines
3.0 KiB
Python
from unittest.mock import patch
|
|
|
|
import pytest
|
|
from django.urls import reverse
|
|
|
|
from apps.feeds.models import Feed, Subscription
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_health_check_returns_ok_without_login(client):
|
|
response = client.get(reverse("core:health"))
|
|
assert response.status_code == 200
|
|
assert response.json() == {"status": "ok"}
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_health_check_works_before_first_run_setup(client):
|
|
# No User exists yet, so SetupWizardMiddleware would normally redirect
|
|
# every request to /setup/ — scripts/upgrade.sh needs this reachable
|
|
# immediately after a fresh deploy, before anyone's created an account.
|
|
response = client.get(reverse("core:health"))
|
|
assert response.status_code == 200
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_dashboard_requires_staff(client, django_user_model):
|
|
django_user_model.objects.create_user("regular", password="pw-regular-123")
|
|
client.login(username="regular", password="pw-regular-123")
|
|
|
|
response = client.get(reverse("core:dashboard"))
|
|
assert response.status_code == 302
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_dashboard_lists_erroring_feeds(client, django_user_model):
|
|
admin = django_user_model.objects.create_user("admin", password="pw-admin-123", is_staff=True)
|
|
client.login(username="admin", password="pw-admin-123")
|
|
|
|
ok_feed = Feed.objects.create(feed_url="https://ok.example.com/feed", title="OK Feed")
|
|
broken_feed = Feed.objects.create(
|
|
feed_url="https://broken.example.com/feed",
|
|
title="Broken Feed",
|
|
last_fetch_status=Feed.STATUS_ERROR,
|
|
fetch_error_count=3,
|
|
last_error_message="Connection timed out",
|
|
)
|
|
Subscription.objects.create(user=admin, feed=ok_feed)
|
|
Subscription.objects.create(user=admin, feed=broken_feed)
|
|
|
|
response = client.get(reverse("core:dashboard"))
|
|
assert response.status_code == 200
|
|
assert b"Broken Feed" in response.content
|
|
assert b"Connection timed out" in response.content
|
|
# "OK Feed" legitimately appears elsewhere on the page (the sidebar
|
|
# lists every subscription), so check the dashboard's own error table
|
|
# scope via context rather than raw page content.
|
|
assert list(response.context["erroring_feeds"]) == [broken_feed]
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_retry_feed_resets_backoff_and_requeues(client, django_user_model):
|
|
django_user_model.objects.create_user("admin", password="pw-admin-123", is_staff=True)
|
|
client.login(username="admin", password="pw-admin-123")
|
|
|
|
feed = Feed.objects.create(
|
|
feed_url="https://broken.example.com/feed",
|
|
fetch_error_count=5,
|
|
last_fetch_status=Feed.STATUS_ERROR,
|
|
)
|
|
|
|
with (
|
|
patch("apps.core.views.reset_feed_backoff.delay") as mock_reset,
|
|
patch("apps.core.views.fetch_feed.delay") as mock_fetch,
|
|
):
|
|
response = client.post(reverse("core:retry_feed", args=[feed.id]))
|
|
|
|
assert response.status_code == 302
|
|
mock_reset.assert_called_once_with(feed.id)
|
|
mock_fetch.assert_called_once_with(feed.id)
|