forked from ChelseaKR/queer-the-stacks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_catalogs_lists.py
More file actions
71 lines (53 loc) · 2.14 KB
/
Copy pathtest_catalogs_lists.py
File metadata and controls
71 lines (53 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""Catalog source interface + curated-list helpers."""
from __future__ import annotations
import pytest
from ingest.models import Author, Book, SourceKind
from recommender.catalogs import FixtureCatalog
from recommender.lists import (
DEMO_LISTS,
CuratedList,
ListValidationError,
lists_for,
load_lists,
validate_lists,
)
def test_fixture_catalog_returns_books() -> None:
book = Book(book_id="b1", title="T", authors=(Author("A"),))
cat = FixtureCatalog((book,))
assert cat.candidates() == (book,)
def test_curated_list_as_source() -> None:
lst = CuratedList(name="My List", citation="curated-list:my-list", book_ids=("ol:x",))
src = lst.as_source()
assert src.kind is SourceKind.CURATED_LIST
assert src.detail == "My List"
assert lst.contains("ol:x")
assert not lst.contains("ol:y")
def test_lists_for_finds_membership() -> None:
hits = lists_for("ol:nevada", DEMO_LISTS)
assert any(lst.name == "Trans & Spec-Fic Canon" for lst in hits)
assert lists_for("ol:does-not-exist", DEMO_LISTS) == ()
def test_demo_lists_are_valid() -> None:
validate_lists(DEMO_LISTS) # all carry citation + retrieved_at + books
def test_validate_rejects_missing_citation() -> None:
bad = (CuratedList(name="X", citation="", book_ids=("ol:1",)),)
with pytest.raises(ListValidationError, match="citation"):
validate_lists(bad)
def test_validate_rejects_empty_list() -> None:
bad = (CuratedList(name="X", citation="c", book_ids=()),)
with pytest.raises(ListValidationError, match="no books"):
validate_lists(bad)
def test_load_lists_from_records() -> None:
records: list[dict[str, object]] = [
{
"name": "Trans Futures",
"citation": "curated-list:trans-futures",
"book_ids": ["ol:nevada", "ol:dawn-butler"],
"retrieved_at": "2026-06-05",
}
]
lists = load_lists(records)
assert lists[0].name == "Trans Futures"
assert lists[0].contains("ol:nevada")
def test_load_lists_validates() -> None:
with pytest.raises(ListValidationError):
load_lists([{"name": "No Citation", "book_ids": ["ol:1"]}])