special galleries: add tests; make special breadcrumb clickable; highlight active special; hide back only

This commit is contained in:
2026-03-27 20:31:43 -04:00
parent 532690a329
commit 5f1035a252
3 changed files with 69 additions and 2 deletions

53
viewer/test_specials.py Normal file
View File

@@ -0,0 +1,53 @@
from pathlib import Path
import tempfile
from django.test import TestCase, override_settings
from django.contrib.auth.models import User
from django.utils import timezone
from viewer.models import Image as Im
class SpecialGalleriesTests(TestCase):
def setUp(self):
# prepare a temporary gallery root and files
self.tmp_gallery = tempfile.TemporaryDirectory()
self.gallery_root = Path(self.tmp_gallery.name)
self.settings_override = override_settings(GALLERY_ROOT=self.gallery_root)
self.settings_override.enable()
self.user = User.objects.create_user("specuser", "s@example.com", "pw")
# create files under gallery root
now = timezone.now()
a = self.gallery_root / "a.jpg"
b = self.gallery_root / "b.jpg"
c = self.gallery_root / "c.jpg"
for p in (a, b, c):
p.write_bytes(b"x")
Im.objects.create(
user=self.user, path=str(a), favorite=True, visits=5, last_visited=now
)
Im.objects.create(
user=self.user, path=str(b), favorite=False, visits=10, last_visited=now
)
Im.objects.create(
user=self.user, path=str(c), favorite=True, visits=2, last_visited=now
)
def tearDown(self):
self.settings_override.disable()
self.tmp_gallery.cleanup()
def test_get_special_paths_filters_and_orders(self):
from viewer.specials import get_special_paths
favs = get_special_paths(self.user, "favorites")
# favorites should include only those marked favorite (a and c)
fav_names = sorted([p.name for p in favs])
self.assertEqual(fav_names, ["a.jpg", "c.jpg"])
most = get_special_paths(self.user, "most-visited")
# most-visited should be ordered descending by visits, expect b.jpg first
self.assertGreaterEqual(len(most), 1)
self.assertEqual(most[0].name, "b.jpg")