Spaces:
Runtime error
Runtime error
| from __future__ import annotations | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| if str(ROOT) not in sys.path: | |
| sys.path.insert(0, str(ROOT)) | |
| from app_kit.demo_pack import store_uploaded_manual | |
| from app_kit.storage import connect, init_db | |
| def test_store_uploaded_manual_persists_manual_and_sections(tmp_path: Path) -> None: | |
| db_path = tmp_path / "field-repair.sqlite3" | |
| init_db(db_path) | |
| manual_path = tmp_path / "generator_manual.md" | |
| manual_path.write_text( | |
| "# Troubleshooting\n\nStart with the battery bank.\n\n# Fuel System\n\nCheck the filter and fuel lines.", | |
| encoding="utf-8", | |
| ) | |
| with connect(db_path) as conn: | |
| manual_id = store_uploaded_manual(conn, manual_path) | |
| conn.commit() | |
| with connect(db_path) as conn: | |
| manual_row = conn.execute( | |
| "SELECT title, source_url, license_name, attribution, body_text FROM manuals WHERE id = ?", | |
| (manual_id,), | |
| ).fetchone() | |
| sections = conn.execute( | |
| """ | |
| SELECT section_title, section_slug, section_order, citation, is_demo | |
| FROM manual_sections | |
| WHERE manual_id = ? | |
| ORDER BY section_order | |
| """, | |
| (manual_id,), | |
| ).fetchall() | |
| assert manual_row is not None | |
| assert manual_row["title"] == "generator_manual" | |
| assert manual_row["source_url"] == manual_path.name | |
| assert manual_row["license_name"] == "uploaded" | |
| assert manual_row["attribution"] == manual_path.name | |
| assert manual_row["body_text"].startswith("# Troubleshooting") | |
| assert [row["section_title"] for row in sections] == ["Troubleshooting", "Fuel System"] | |
| assert [row["section_slug"] for row in sections] == ["troubleshooting", "fuel_system"] | |
| assert [row["section_order"] for row in sections] == [1, 2] | |
| assert [row["citation"] for row in sections] == [ | |
| "generator_manual :: Troubleshooting", | |
| "generator_manual :: Fuel System", | |
| ] | |
| assert all(row["is_demo"] == 0 for row in sections) | |