style: apply ruff format across backend + scripts (line-length 100)

Mechanical, whole-tree `ruff format` pass — no behaviour change. Recorded in
.git-blame-ignore-revs (next commit) so git blame skips it.
This commit is contained in:
2026-08-23 07:43:06 +02:00
parent 434a98d6ed
commit b1832afd18
217 changed files with 3149 additions and 1744 deletions
+118 -42
View File
@@ -3,6 +3,7 @@ payload (continue watching / recently added / genre tiles / because-you-watched)
and GET /api/plex/surprise returns a scope-bounded random sample. DB lane (`db` fixture) — skipped
without Postgres.
"""
from datetime import datetime, timedelta, timezone
from fastapi.testclient import TestClient
@@ -26,8 +27,13 @@ def _seed(db):
db.flush()
m1 = PlexItem(
rating_key="m1", library_id=lib_m.id, kind="movie", title="Anchor Movie",
guid="tmdb:111", genres=["Drama"], year=2001,
rating_key="m1",
library_id=lib_m.id,
kind="movie",
title="Anchor Movie",
guid="tmdb:111",
genres=["Drama"],
year=2001,
added_at=NOW - timedelta(days=1),
tmdb_enriched_at=NOW - timedelta(days=1),
recommendations=[
@@ -35,26 +41,52 @@ def _seed(db):
],
)
m2 = PlexItem(
rating_key="m2", library_id=lib_m.id, kind="movie", title="Rec Movie",
guid="tmdb:555", genres=["Comedy"], year=2002,
rating_key="m2",
library_id=lib_m.id,
kind="movie",
title="Rec Movie",
guid="tmdb:555",
genres=["Comedy"],
year=2002,
added_at=NOW - timedelta(days=2),
)
m3 = PlexItem(
rating_key="m3", library_id=lib_m.id, kind="movie", title="Half-Watched Movie",
guid="tmdb:333", genres=["Drama"], year=2003, duration_s=6000,
rating_key="m3",
library_id=lib_m.id,
kind="movie",
title="Half-Watched Movie",
guid="tmdb:333",
genres=["Drama"],
year=2003,
duration_s=6000,
added_at=NOW - timedelta(days=3),
)
sh1 = PlexShow(rating_key="sh1", library_id=lib_s.id, title="A Show", child_count=1,
added_at=NOW - timedelta(hours=1)) # newest → leads recently-added
sh1 = PlexShow(
rating_key="sh1",
library_id=lib_s.id,
title="A Show",
child_count=1,
added_at=NOW - timedelta(hours=1),
) # newest → leads recently-added
db.add_all([m1, m2, m3, sh1])
db.flush()
ep1 = PlexItem(
rating_key="sh1e1", library_id=lib_s.id, kind="episode", title="Ep 1",
show_id=sh1.id, season_number=1, episode_number=1,
rating_key="sh1e1",
library_id=lib_s.id,
kind="episode",
title="Ep 1",
show_id=sh1.id,
season_number=1,
episode_number=1,
)
ep2 = PlexItem(
rating_key="sh1e2", library_id=lib_s.id, kind="episode", title="Ep 2",
show_id=sh1.id, season_number=1, episode_number=2,
rating_key="sh1e2",
library_id=lib_s.id,
kind="episode",
title="Ep 2",
show_id=sh1.id,
season_number=1,
episode_number=2,
)
db.add_all([ep1, ep2])
@@ -62,16 +94,28 @@ def _seed(db):
db.add(user)
db.flush()
db.add_all([
# m1 watched most recently → the because-you-watched anchor.
PlexState(user_id=user.id, item_id=m1.id, status="watched", watched_at=NOW),
# m3 in-progress → continue watching.
PlexState(user_id=user.id, item_id=m3.id, status="new", position_seconds=1200,
progress_updated_at=NOW - timedelta(hours=1)),
# sh1's ep1 in-progress → the show is in continue watching.
PlexState(user_id=user.id, item_id=ep1.id, status="new", position_seconds=300,
progress_updated_at=NOW - timedelta(minutes=30)),
])
db.add_all(
[
# m1 watched most recently → the because-you-watched anchor.
PlexState(user_id=user.id, item_id=m1.id, status="watched", watched_at=NOW),
# m3 in-progress → continue watching.
PlexState(
user_id=user.id,
item_id=m3.id,
status="new",
position_seconds=1200,
progress_updated_at=NOW - timedelta(hours=1),
),
# sh1's ep1 in-progress → the show is in continue watching.
PlexState(
user_id=user.id,
item_id=ep1.id,
status="new",
position_seconds=300,
progress_updated_at=NOW - timedelta(minutes=30),
),
]
)
db.commit()
return user
@@ -131,22 +175,40 @@ def test_continue_watching_null_status_in_hidden_out(db, monkeypatch):
lib = PlexLibrary(plex_key="1", title="Movies", kind="movie", enabled=True)
db.add(lib)
db.flush()
m_null = PlexItem(rating_key="mn", library_id=lib.id, kind="movie", title="Null Status", guid="tmdb:1")
m_hidden = PlexItem(rating_key="mh", library_id=lib.id, kind="movie", title="Hidden", guid="tmdb:2")
m_null = PlexItem(
rating_key="mn", library_id=lib.id, kind="movie", title="Null Status", guid="tmdb:1"
)
m_hidden = PlexItem(
rating_key="mh", library_id=lib.id, kind="movie", title="Hidden", guid="tmdb:2"
)
db.add_all([m_null, m_hidden])
db.flush()
user = User(email="cw-null@example.com")
db.add(user)
db.flush()
db.add_all([
PlexState(user_id=user.id, item_id=m_null.id, status=None, position_seconds=500,
progress_updated_at=NOW),
PlexState(user_id=user.id, item_id=m_hidden.id, status="hidden", position_seconds=500,
progress_updated_at=NOW - timedelta(hours=1)),
])
db.add_all(
[
PlexState(
user_id=user.id,
item_id=m_null.id,
status=None,
position_seconds=500,
progress_updated_at=NOW,
),
PlexState(
user_id=user.id,
item_id=m_hidden.id,
status="hidden",
position_seconds=500,
progress_updated_at=NOW - timedelta(hours=1),
),
]
)
db.commit()
ids = _ids(_get(db, user, monkeypatch, "/api/plex/discover?scope=movie").json()["continue_watching"])
ids = _ids(
_get(db, user, monkeypatch, "/api/plex/discover?scope=movie").json()["continue_watching"]
)
assert "mn" in ids # NULL-status started movie IS in progress
assert "mh" not in ids # hidden is excluded
@@ -160,18 +222,34 @@ def test_continue_watching_excludes_fully_watched_show(db, monkeypatch):
sh = PlexShow(rating_key="shw", library_id=lib_s.id, title="All Watched", child_count=1)
db.add(sh)
db.flush()
ep = PlexItem(rating_key="shwe1", library_id=lib_s.id, kind="episode", title="E1",
show_id=sh.id, season_number=1, episode_number=1)
ep = PlexItem(
rating_key="shwe1",
library_id=lib_s.id,
kind="episode",
title="E1",
show_id=sh.id,
season_number=1,
episode_number=1,
)
db.add(ep)
db.flush()
user = User(email="fullywatched@example.com")
db.add(user)
db.flush()
db.add(PlexState(user_id=user.id, item_id=ep.id, status="watched", position_seconds=0,
progress_updated_at=NOW))
db.add(
PlexState(
user_id=user.id,
item_id=ep.id,
status="watched",
position_seconds=0,
progress_updated_at=NOW,
)
)
db.commit()
ids = _ids(_get(db, user, monkeypatch, "/api/plex/discover?scope=show").json()["continue_watching"])
ids = _ids(
_get(db, user, monkeypatch, "/api/plex/discover?scope=show").json()["continue_watching"]
)
assert "shw" not in ids # fully watched → excluded from continue-watching
@@ -209,9 +287,7 @@ def test_recently_watched_movies_and_episodes(db, monkeypatch):
# The rail lists last-fully-watched titles newest-first: a watched MOVIE as its own card, a show as
# the specific watched EPISODE (with its show title). _seed watches m1 (movie); add a watched episode.
user = _seed(db)
ep2 = db.execute(
select(PlexItem).where(PlexItem.rating_key == "sh1e2")
).scalars().one()
ep2 = db.execute(select(PlexItem).where(PlexItem.rating_key == "sh1e2")).scalars().one()
db.add(PlexState(user_id=user.id, item_id=ep2.id, status="watched", watched_at=NOW))
db.commit()
rw = _get(db, user, monkeypatch, "/api/plex/discover?scope=both").json()["recently_watched"]
@@ -260,8 +336,8 @@ def test_filters_narrow_every_discover_rail(db, monkeypatch):
def test_filters_narrow_surprise(db, monkeypatch):
user = _seed(db)
items = _get(
db, user, monkeypatch, "/api/plex/surprise?scope=movie&genres=Comedy"
).json()["items"]
items = _get(db, user, monkeypatch, "/api/plex/surprise?scope=movie&genres=Comedy").json()[
"items"
]
# Only the one Comedy movie qualifies under the filter.
assert _ids(items) == ["m2"]