Private
Public Access
Remove folders; feeds are organized by tags now
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>
This commit is contained in:
1 parent
3b58fdcb7e
commit
0e132e9ab9
24 files changed
+417
-307
No files matched your search
+66
-27
@@ -3,7 +3,9 @@ from io import BytesIO
|
||||
import pytest
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from .models import Feed, Folder, Subscription
|
||||
from apps.articles.models import SubscriptionTag, Tag
|
||||
|
||||
from .models import Feed, Subscription
|
||||
from .opml import export_opml, import_opml, parse_opml
|
||||
|
||||
User = get_user_model()
|
||||
@@ -16,8 +18,8 @@ SIMPLE_OPML = b"""<?xml version="1.0" encoding="UTF-8"?>
|
||||
<outline type="rss" text="Example Blog" title="Example Blog"
|
||||
xmlUrl="https://example.com/feed.xml" htmlUrl="https://example.com"/>
|
||||
</outline>
|
||||
<outline type="rss" text="Unfoldered Feed" title="Unfoldered Feed"
|
||||
xmlUrl="https://unfoldered.example.com/feed.xml"/>
|
||||
<outline type="rss" text="Untagged Feed" title="Untagged Feed"
|
||||
xmlUrl="https://untagged.example.com/feed.xml"/>
|
||||
</body>
|
||||
</opml>
|
||||
"""
|
||||
@@ -35,6 +37,15 @@ NESTED_OPML = b"""<?xml version="1.0" encoding="UTF-8"?>
|
||||
</opml>
|
||||
"""
|
||||
|
||||
CATEGORY_ATTR_OPML = b"""<?xml version="1.0" encoding="UTF-8"?>
|
||||
<opml version="2.0">
|
||||
<body>
|
||||
<outline type="rss" text="Multi-tag feed" category="Tech,Backend"
|
||||
xmlUrl="https://multi.example.com/feed.xml"/>
|
||||
</body>
|
||||
</opml>
|
||||
"""
|
||||
|
||||
MALFORMED_XML = b"<opml><body><outline"
|
||||
|
||||
|
||||
@@ -44,25 +55,32 @@ def alice(db):
|
||||
|
||||
|
||||
class TestParseOPML:
|
||||
def test_parses_foldered_and_unfoldered_entries(self):
|
||||
def test_parses_tagged_and_untagged_entries(self):
|
||||
entries = parse_opml(BytesIO(SIMPLE_OPML))
|
||||
|
||||
assert len(entries) == 2
|
||||
foldered = next(e for e in entries if e["feed_url"] == "https://example.com/feed.xml")
|
||||
assert foldered["folder_name"] == "Tech"
|
||||
assert foldered["title"] == "Example Blog"
|
||||
tagged = next(e for e in entries if e["feed_url"] == "https://example.com/feed.xml")
|
||||
assert tagged["tag_names"] == ["Tech"]
|
||||
assert tagged["title"] == "Example Blog"
|
||||
|
||||
unfoldered = next(
|
||||
e for e in entries if e["feed_url"] == "https://unfoldered.example.com/feed.xml"
|
||||
untagged = next(
|
||||
e for e in entries if e["feed_url"] == "https://untagged.example.com/feed.xml"
|
||||
)
|
||||
assert unfoldered["folder_name"] is None
|
||||
assert untagged["tag_names"] == []
|
||||
|
||||
def test_flattens_nesting_deeper_than_one_level(self):
|
||||
def test_nesting_produces_a_tag_per_level(self):
|
||||
entries = parse_opml(BytesIO(NESTED_OPML))
|
||||
|
||||
assert len(entries) == 1
|
||||
# Deepest enclosing folder name wins rather than a path.
|
||||
assert entries[0]["folder_name"] == "Child"
|
||||
# Unlike the old single-folder scheme, each enclosing level becomes
|
||||
# its own tag rather than collapsing to the nearest one.
|
||||
assert entries[0]["tag_names"] == ["Parent", "Child"]
|
||||
|
||||
def test_category_attribute_produces_multiple_tags(self):
|
||||
entries = parse_opml(BytesIO(CATEGORY_ATTR_OPML))
|
||||
|
||||
assert len(entries) == 1
|
||||
assert entries[0]["tag_names"] == ["Tech", "Backend"]
|
||||
|
||||
def test_malformed_xml_raises(self):
|
||||
with pytest.raises(Exception):
|
||||
@@ -71,18 +89,23 @@ class TestParseOPML:
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestImportOPML:
|
||||
def test_creates_feeds_folders_and_subscriptions(self, alice):
|
||||
def test_creates_feeds_tags_and_subscriptions(self, alice):
|
||||
result = import_opml(alice, BytesIO(SIMPLE_OPML))
|
||||
|
||||
assert result == {"total": 2, "created": 2, "already_subscribed": 0}
|
||||
assert Folder.objects.filter(user=alice, name="Tech").exists()
|
||||
assert Subscription.objects.filter(
|
||||
assert Tag.objects.filter(user=alice, name="Tech").exists()
|
||||
|
||||
tagged_sub = Subscription.objects.get(
|
||||
user=alice, feed__feed_url="https://example.com/feed.xml"
|
||||
).exists()
|
||||
unfoldered_sub = Subscription.objects.get(
|
||||
user=alice, feed__feed_url="https://unfoldered.example.com/feed.xml"
|
||||
)
|
||||
assert unfoldered_sub.folder is None
|
||||
assert SubscriptionTag.objects.filter(
|
||||
user=alice, subscription=tagged_sub, tag__name="Tech"
|
||||
).exists()
|
||||
|
||||
untagged_sub = Subscription.objects.get(
|
||||
user=alice, feed__feed_url="https://untagged.example.com/feed.xml"
|
||||
)
|
||||
assert not SubscriptionTag.objects.filter(user=alice, subscription=untagged_sub).exists()
|
||||
|
||||
def test_reimporting_the_same_file_does_not_duplicate(self, alice):
|
||||
import_opml(alice, BytesIO(SIMPLE_OPML))
|
||||
@@ -90,7 +113,7 @@ class TestImportOPML:
|
||||
|
||||
assert result == {"total": 2, "created": 0, "already_subscribed": 2}
|
||||
assert Subscription.objects.filter(user=alice).count() == 2
|
||||
assert Folder.objects.filter(user=alice, name="Tech").count() == 1
|
||||
assert Tag.objects.filter(user=alice, name="Tech").count() == 1
|
||||
|
||||
def test_reuses_existing_feed_across_users(self, alice):
|
||||
bob = User.objects.create_user("bob", password="pw-bob-123")
|
||||
@@ -109,18 +132,34 @@ class TestExportOPML:
|
||||
import_opml(alice, BytesIO(SIMPLE_OPML))
|
||||
|
||||
exported = export_opml(alice)
|
||||
assert b'category="Tech"' in exported
|
||||
|
||||
bob = User.objects.create_user("bob", password="pw-bob-123")
|
||||
result = import_opml(bob, BytesIO(exported))
|
||||
|
||||
assert result["created"] == 2
|
||||
assert Folder.objects.filter(user=bob, name="Tech").exists()
|
||||
assert Subscription.objects.filter(
|
||||
user=bob, feed__feed_url="https://example.com/feed.xml", folder__name="Tech"
|
||||
).exists()
|
||||
assert Subscription.objects.filter(
|
||||
user=bob, feed__feed_url="https://unfoldered.example.com/feed.xml", folder__isnull=True
|
||||
tagged_sub = Subscription.objects.get(
|
||||
user=bob, feed__feed_url="https://example.com/feed.xml"
|
||||
)
|
||||
assert SubscriptionTag.objects.filter(
|
||||
user=bob, subscription=tagged_sub, tag__name="Tech"
|
||||
).exists()
|
||||
untagged_sub = Subscription.objects.get(
|
||||
user=bob, feed__feed_url="https://untagged.example.com/feed.xml"
|
||||
)
|
||||
assert not SubscriptionTag.objects.filter(user=bob, subscription=untagged_sub).exists()
|
||||
|
||||
def test_export_represents_multiple_tags_as_comma_separated_category(self, alice):
|
||||
feed = Feed.objects.create(feed_url="https://multi.example.com/feed.xml")
|
||||
subscription = Subscription.objects.create(user=alice, feed=feed)
|
||||
for name in ["Tech", "Backend"]:
|
||||
tag, _ = Tag.objects.get_or_create(user=alice, name=name)
|
||||
SubscriptionTag.objects.create(user=alice, subscription=subscription, tag=tag)
|
||||
|
||||
exported = export_opml(alice)
|
||||
|
||||
# Alphabetical (export_opml orders by tag name), not insertion order.
|
||||
assert b'category="Backend,Tech"' in exported
|
||||
|
||||
def test_export_with_no_subscriptions(self, alice):
|
||||
exported = export_opml(alice)
|
||||
|
||||
Reference in new issue
Block a user