Files
shelfmark/tests/core/test_request_helpers.py
T
splitsec2 e575ff0fcb feat(activity): clearer cards, a Rejected view and Reopen for failed deliveries (#1618)
A batch of activity list changes from running it as an admin on my own
instance. They are separate commits that build on each other, so they
can be reviewed in order.

The cards read better. Every card gets a format pill (violet for audio,
orange for ebooks), the requester is named once, and finished cards say
how long a download took and how long ago it ended ("took 5m · 35m
ago"). A download that picked up work already under way shows a
Reattached pill.

Admins can tell what is automatic and what needs a person. A declined
request shows who declined it and when, anything with an `[auto]` note
reads "Declined automatically", and "Needs Review" becomes "No Match
Yet" with a line saying the search repeats on every sync.

There is a Rejected view next to History for admins, with Reopen on each
card and a way to hide the dead ones.

The part to read most carefully is the backend in `requests_service.py`
and `user_db.py`. An admin can now reopen a fulfilled request whose
download failed or was cancelled, and the reopen a failed download
triggers remembers which release failed, so the next search doesn't pick
it again.

I ran it on a scratch instance (when pulling them together to move from
my fork to upstream) as an admin with seeded requests and looked at the
pills, the durations, the wording and the Rejected view in a browser.
Reopening a fulfilled request I only exercised in the tests. The
frontend and Python suites, type check, ruff and basedpyright pass.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* Admins can review rejected requests in a dedicated view, hide or
restore cards, and reopen requests.
* Fulfilled requests with failed or cancelled deliveries can be
reopened; the failed release is skipped in the next automatic search.
* Activity cards now show format badges, download timing, and when a
download resumes existing work.
* **Improvements**
* Activity views clarify automatic retries and actions, and show
reviewer names for admins.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-09 12:02:21 -06:00

39 lines
1.1 KiB
Python

"""Tests for shared request helper normalization utilities."""
from shelfmark.core.request_helpers import normalize_optional_text, populate_request_reviewers
def test_normalize_optional_text_trims_strings():
assert normalize_optional_text(" hello ") == "hello"
def test_normalize_optional_text_returns_none_for_empty_or_non_string_values():
assert normalize_optional_text("") is None
assert normalize_optional_text(None) is None
assert normalize_optional_text(123) is None
assert normalize_optional_text(False) is None
class _Users:
def __init__(self):
self.lookups = 0
def get_user(self, *, user_id):
self.lookups += 1
return {1: {"username": "admin@example.com"}}.get(user_id)
def test_populate_request_reviewers_names_the_reviewer_once_per_user():
users = _Users()
rows = [{"reviewed_by": 1}, {"reviewed_by": 1}, {"reviewed_by": None}, {"reviewed_by": 99}]
populate_request_reviewers(rows, users)
assert [row["reviewer_username"] for row in rows] == [
"admin@example.com",
"admin@example.com",
"",
"",
]
assert users.lookups == 2