Private
Public Access
Folders are gone — organization is tags-only, via the SubscriptionTag model added last commit. A migration converts every existing Folder into a same-named Tag applied to its feeds, and every folder-scoped FilterRule into an equivalent tag-scoped one, before the Folder table is dropped, so upgrading an existing instance loses nothing (verified by seeding the pre-removal schema directly and running the migration chain against it). Unlike folders, a feed can carry more than one tag, so: - apps.articles.tasks.apply_filter_rules_for_feed and apps.rules.tasks's backlog re-apply now scope by "does this feed carry tag X" rather than "does this feed belong to folder X". - apps.feeds.opml: a feed's tags export as a comma-separated "category" attribute (the standard OPML way to represent multiple categories) instead of nesting under one folder outline. Import reads both that attribute and nested category outlines, turning each enclosing level into its own tag rather than collapsing to the nearest one. - The sidebar groups feeds by tag instead of folder, so a feed with two tags now appears in both groups; untagged feeds fall into "Untagged". AddFeedForm gained a comma-separated tag_names field for parity with the old add-time folder picker. EditSubscriptionForm dropped its folder field entirely — tagging a subscription happens through the tag editor already on that page. Verified end to end: the migration chain from empty, the data migration against a seeded pre-removal schema (folder/subscription/rule all convert correctly), and the running app's sidebar grouping, OPML export category attributes, and tag editor. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
147 lines
5.3 KiB
Python
147 lines
5.3 KiB
Python
import pytest
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from apps.feeds.models import Feed, Subscription
|
|
from apps.rules.models import FilterRule
|
|
|
|
from .models import Article, SubscriptionTag, Tag, UserArticleState
|
|
from .tasks import apply_filter_rules_for_feed
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
@pytest.fixture
|
|
def feed(db):
|
|
return Feed.objects.create(feed_url="https://example.com/feed.xml", title="Example Feed")
|
|
|
|
|
|
@pytest.fixture
|
|
def alice(db):
|
|
return User.objects.create_user("alice", password="pw-alice-123")
|
|
|
|
|
|
@pytest.fixture
|
|
def bob(db):
|
|
return User.objects.create_user("bob", password="pw-bob-123")
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_dispatch_applies_rules_only_for_subscribers_with_matching_rules(feed, alice, bob):
|
|
Subscription.objects.create(user=alice, feed=feed)
|
|
Subscription.objects.create(user=bob, feed=feed)
|
|
FilterRule.objects.create(
|
|
user=alice,
|
|
match_field=FilterRule.FIELD_TITLE,
|
|
match_type=FilterRule.MATCH_CONTAINS,
|
|
match_value="Python",
|
|
action=FilterRule.ACTION_STAR,
|
|
)
|
|
article = Article.objects.create(feed=feed, guid="guid-1", title="Python 4 released")
|
|
|
|
apply_filter_rules_for_feed(feed.id, [article.pk])
|
|
|
|
assert UserArticleState.objects.get(user=alice, article=article).is_starred is True
|
|
# Bob has no rules, so he should get no state row at all.
|
|
assert not UserArticleState.objects.filter(user=bob, article=article).exists()
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_feed_scoped_rule_does_not_apply_to_other_feeds(alice):
|
|
feed_a = Feed.objects.create(feed_url="https://a.example.com/feed.xml")
|
|
feed_b = Feed.objects.create(feed_url="https://b.example.com/feed.xml")
|
|
Subscription.objects.create(user=alice, feed=feed_a)
|
|
Subscription.objects.create(user=alice, feed=feed_b)
|
|
|
|
FilterRule.objects.create(
|
|
user=alice,
|
|
feed=feed_a,
|
|
match_field=FilterRule.FIELD_TITLE,
|
|
match_type=FilterRule.MATCH_CONTAINS,
|
|
match_value="Python",
|
|
action=FilterRule.ACTION_STAR,
|
|
)
|
|
|
|
article_a = Article.objects.create(feed=feed_a, guid="guid-1", title="Python news")
|
|
article_b = Article.objects.create(feed=feed_b, guid="guid-2", title="Python news too")
|
|
|
|
apply_filter_rules_for_feed(feed_a.id, [article_a.pk])
|
|
apply_filter_rules_for_feed(feed_b.id, [article_b.pk])
|
|
|
|
assert UserArticleState.objects.get(user=alice, article=article_a).is_starred is True
|
|
assert not UserArticleState.objects.filter(user=alice, article=article_b).exists()
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_tag_scoped_rule_only_applies_to_feeds_carrying_that_tag(alice, feed):
|
|
other_feed = Feed.objects.create(feed_url="https://other.example.com/feed.xml")
|
|
tagged_sub = Subscription.objects.create(user=alice, feed=feed)
|
|
Subscription.objects.create(user=alice, feed=other_feed)
|
|
tag = Tag.objects.create(user=alice, name="Tech")
|
|
SubscriptionTag.objects.create(user=alice, subscription=tagged_sub, tag=tag)
|
|
|
|
FilterRule.objects.create(
|
|
user=alice,
|
|
tag=tag,
|
|
match_field=FilterRule.FIELD_TITLE,
|
|
match_type=FilterRule.MATCH_CONTAINS,
|
|
match_value="Python",
|
|
action=FilterRule.ACTION_STAR,
|
|
)
|
|
|
|
tagged_article = Article.objects.create(feed=feed, guid="guid-1", title="Python in tagged feed")
|
|
untagged_article = Article.objects.create(
|
|
feed=other_feed, guid="guid-2", title="Python in untagged feed"
|
|
)
|
|
|
|
apply_filter_rules_for_feed(feed.id, [tagged_article.pk])
|
|
apply_filter_rules_for_feed(other_feed.id, [untagged_article.pk])
|
|
|
|
assert UserArticleState.objects.get(user=alice, article=tagged_article).is_starred is True
|
|
assert not UserArticleState.objects.filter(user=alice, article=untagged_article).exists()
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_rule_scoped_to_one_tag_still_applies_to_a_feed_with_multiple_tags(alice, feed):
|
|
subscription = Subscription.objects.create(user=alice, feed=feed)
|
|
tech_tag = Tag.objects.create(user=alice, name="Tech")
|
|
news_tag = Tag.objects.create(user=alice, name="News")
|
|
SubscriptionTag.objects.create(user=alice, subscription=subscription, tag=tech_tag)
|
|
SubscriptionTag.objects.create(user=alice, subscription=subscription, tag=news_tag)
|
|
|
|
FilterRule.objects.create(
|
|
user=alice,
|
|
tag=news_tag,
|
|
match_field=FilterRule.FIELD_TITLE,
|
|
match_type=FilterRule.MATCH_CONTAINS,
|
|
match_value="Python",
|
|
action=FilterRule.ACTION_STAR,
|
|
)
|
|
article = Article.objects.create(feed=feed, guid="guid-1", title="Python news")
|
|
|
|
apply_filter_rules_for_feed(feed.id, [article.pk])
|
|
|
|
assert UserArticleState.objects.get(user=alice, article=article).is_starred is True
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_disabled_rule_does_not_apply(feed, alice):
|
|
Subscription.objects.create(user=alice, feed=feed)
|
|
FilterRule.objects.create(
|
|
user=alice,
|
|
match_field=FilterRule.FIELD_TITLE,
|
|
match_type=FilterRule.MATCH_CONTAINS,
|
|
match_value="Python",
|
|
action=FilterRule.ACTION_STAR,
|
|
is_enabled=False,
|
|
)
|
|
article = Article.objects.create(feed=feed, guid="guid-1", title="Python 4 released")
|
|
|
|
apply_filter_rules_for_feed(feed.id, [article.pk])
|
|
|
|
assert not UserArticleState.objects.filter(user=alice, article=article).exists()
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_dispatch_with_empty_article_ids_is_a_noop(feed):
|
|
assert apply_filter_rules_for_feed(feed.id, []) == 0
|