Private
Public Access
UserArticleState.is_starred/is_saved_for_later/starred_at are gone — starring and saving now add/remove an ArticleTag against a per-user "Starred" / "Saved for later" Tag, created lazily on first use and marked Tag.is_system=True. is_read/is_hidden stay on UserArticleState since they're genuine reading state, not categorization, which is what made these two candidates for unifying into the general tag mechanism. System tags are excluded from the Manage Tags page and from delete_tag (get_object_or_404 now requires is_system=False, so attempting to delete one 404s) and from the subscription-tag autocomplete, since they categorize articles, not feeds. The star/save icons are still exactly where they were — this only changes what powers them. apps.rules.engine's star action now does get_system_tag + ArticleTag. get_or_create instead of setting a boolean field. A data migration converts every existing is_starred=True/is_saved_for_later=True row into its ArticleTag equivalent before the fields are dropped — verified by seeding the pre-removal schema directly (including a row with both flags set) and confirming the migration produces the right tags. apps.articles.queries.with_user_state gained one more query (tag lookup for the current page's articles) to stay in the same "fixed number of queries regardless of article count" shape it already had. Verified end to end against a running dev server: toggling star/saved, the starred/saved filters, the sidebar's Favourites count, and that the Starred tag doesn't appear on the Manage Tags page. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
import pytest
|
|
from django.contrib.auth import get_user_model
|
|
from django.urls import reverse
|
|
|
|
from apps.articles.models import STARRED_TAG_NAME, Article, ArticleTag, get_system_tag
|
|
from apps.feeds.models import Feed, Subscription
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
@pytest.fixture
|
|
def alice(db):
|
|
return User.objects.create_user("alice", password="pw-alice-123")
|
|
|
|
|
|
@pytest.fixture
|
|
def feed(db):
|
|
return Feed.objects.create(feed_url="https://example.com/feed.xml", title="Example Feed")
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_search_requires_login(client):
|
|
response = client.get(reverse("search:search"), {"q": "django"})
|
|
assert response.status_code == 302
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_search_view_renders_matching_articles(client, alice, feed):
|
|
Subscription.objects.create(user=alice, feed=feed)
|
|
article = Article.objects.create(feed=feed, guid="g1", title="Django 5 release notes")
|
|
client.login(username="alice", password="pw-alice-123")
|
|
|
|
response = client.get(reverse("search:search"), {"q": "Django"})
|
|
|
|
assert response.status_code == 200
|
|
assert article.title in response.content.decode()
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_search_view_with_no_query_shows_no_results_block(client, alice):
|
|
client.login(username="alice", password="pw-alice-123")
|
|
response = client.get(reverse("search:search"))
|
|
assert response.status_code == 200
|
|
assert b"article-list" not in response.content
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_search_results_carry_user_state(client, alice, feed):
|
|
Subscription.objects.create(user=alice, feed=feed)
|
|
article = Article.objects.create(feed=feed, guid="g1", title="Django 5 release notes")
|
|
ArticleTag.objects.create(
|
|
user=alice, article=article, tag=get_system_tag(alice, STARRED_TAG_NAME)
|
|
)
|
|
client.login(username="alice", password="pw-alice-123")
|
|
|
|
response = client.get(reverse("search:search"), {"q": "Django"})
|
|
content = response.content.decode()
|
|
|
|
assert 'class="icon-btn icon-btn-star active"' in content
|