Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

Merge PR #1472: normalize packaged EPUB archives

Bingxi Zhao (Frank)125dfaf0376d
diff --cc tests/reading/test_router.py
index d44166de2,22a15b081..2fd475c35
--- a/tests/reading/test_router.py
+++ b/tests/reading/test_router.py
@@@ -355,31 -362,25 +363,50 @@@ def test_epub_contract_exposes_source_r
assert client.put(base, json={"locator": 2, "percentage": 0}).status_code == 400
+def test_saved_reading_position_updates_account_learning_record(client: TestClient) -> None:
+ material = _upload(client)
+ base = f"/api/reading/materials/{material['material_id']}/position"
+
+ assert client.put(base, json={"locator": 1, "percentage": 0.2}).status_code == 200
+ assert client.put(base, json={"locator": 2, "percentage": 0.7}).status_code == 200
+ assert (
+ client.put(
+ base,
+ json={"locator": 1, "source_anchor": "private-anchor", "percentage": 0.3},
+ ).status_code
+ == 200
+ )
+
+ records = LearningStore().list_reading_records()
+ assert len(records.progress) == 1
+ progress = records.progress[0]
+ assert progress.material_id == material["material_id"]
+ assert progress.latest_locator == 1
+ assert progress.latest_percentage == 0.3
+ assert progress.furthest_locator == 2
+ assert progress.furthest_percentage == 0.7
+ assert "source_anchor" not in progress.model_dump()
+
+
+ def test_epub_raw_response_is_normalized_for_browser_readers(client: TestClient) -> None:
+ material = _upload(
+ client,
+ name="finder-book.epub",
+ data=_epub_bytes(finder_package=True),
+ )
+
+ raw = client.get(f"/api/reading/materials/{material['material_id']}/raw")
+
+ assert raw.status_code == 200
+ with zipfile.ZipFile(io.BytesIO(raw.content)) as archive:
+ infos = archive.infolist()
+ assert archive.read("mimetype") == b"application/epub+zip"
+ assert infos[0].filename == "mimetype"
+ assert infos[0].compress_type == zipfile.ZIP_STORED
+ assert "META-INF/container.xml" in {info.filename for info in infos}
+ assert all("__MACOSX" not in info.filename for info in infos)
+
+
def test_epub_pairing_requires_confirmation_and_preserves_source_materials(
client: TestClient,
) -> None: