fix: show quizzes without local artifacts in library exam filters

Classify quizzes as assessments during online and offline scans,
support legacy quiz entries in the Exams filter, and add regression tests.
This commit is contained in:
Meghdad committed 2026-10-29 17:00:53 +03:30
1 parent 3e37df980c
commit 9d277383ac
4 files changed
+61 -2

No files matched your search

+1
View File
@@ -261,6 +261,7 @@ function resourceMatches(item) {
if (state.query && !haystack.includes(state.query)) return false; if (state.query && !haystack.includes(state.query)) return false;
if (state.filter === "all") return true; if (state.filter === "all") return true;
if (state.filter === "downloaded" || state.filter === "missing") return item.status === state.filter; if (state.filter === "downloaded" || state.filter === "missing") return item.status === state.filter;
if (state.filter === "assessment") return item.kind === "assessment" || item.activity_type === "quiz";
return item.kind === state.filter; return item.kind === state.filter;
} }
+1 -1
View File
@@ -257,7 +257,7 @@ def _build_library_catalog(
current_path = local_directory / str(current_relative) if local_directory and current_relative else None current_path = local_directory / str(current_relative) if local_directory and current_relative else None
local_path = current_path if current_path and current_path.is_file() else (local_files[0] if local_files else None) local_path = current_path if current_path and current_path.is_file() else (local_files[0] if local_files else None)
local_bytes = local_path.stat().st_size if local_path else 0 local_bytes = local_path.stat().st_size if local_path else 0
if activity_type == "quiz" and local_activity: if activity_type == "quiz":
local_kind = "assessment" local_kind = "assessment"
elif activity_type in LIVE_CLASS_MODULES and local_path: elif activity_type in LIVE_CLASS_MODULES and local_path:
local_kind = _media_kind(local_path.name, mimetypes.guess_type(local_path.name)[0] or "") local_kind = _media_kind(local_path.name, mimetypes.guess_type(local_path.name)[0] or "")
+2
View File
@@ -254,6 +254,8 @@ def _reconcile_course(public: Path, course: dict[str, Any]) -> dict[str, Any]:
for section in course.get("sections", []): for section in course.get("sections", []):
for item in section.get("items", []): for item in section.get("items", []):
records += 1 records += 1
if item.get("activity_type") == "quiz":
item["kind"] = "assessment"
activity_directory = _activity_directory(public, course_id, section, item) activity_directory = _activity_directory(public, course_id, section, item)
download_state, local_path = _download_state(activity_directory, item) download_state, local_path = _download_state(activity_directory, item)
media_applicable = item.get("kind") in {"video", "audio"} media_applicable = item.get("kind") in {"video", "audio"}
+57 -1
View File
@@ -9,7 +9,63 @@ from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from ravin.scan import scan_offline from ravin.scan import scan_offline, scan_remote
from ravin.catalog import _build_library_catalog
from ravin.models import Course
class QuizVisibilityTests(unittest.TestCase):
def test_remote_scan_includes_quizzes_without_local_artifacts_as_assessments(self):
class Client:
site = "https://training.example"
def list_courses(self):
return [Course(56, "MCSA", "MCSA")]
def list_files(self, course_id):
return []
def course_structure(self, course_id):
return [{"number": 14, "name": "Practices", "activities": [
{"id": activity_id, "position": position, "type": "quiz", "name": f"Practice {position}"}
for position, activity_id in enumerate((6142, 6151, 6238), 1)
]}]
with tempfile.TemporaryDirectory() as directory:
public = Path(directory)
raw = _build_library_catalog(Client(), public)
self.assertEqual([item["kind"] for item in raw["courses"][0]["sections"][0]["items"]],
["assessment"] * 3)
scan_remote(Client(), public)
manifest = json.loads((public / "courses/56/manifest.json").read_text())
items = manifest["course"]["sections"][0]["items"]
self.assertEqual([item["activity_id"] for item in items], [6142, 6151, 6238])
self.assertTrue(all(item["kind"] == "assessment" for item in items))
self.assertTrue(all(item["state"]["questions"] == "missing" for item in items))
def test_offline_scan_repairs_legacy_quiz_kind_and_preserves_questions(self):
with tempfile.TemporaryDirectory() as directory:
public = Path(directory)
root = public / "courses/56"
artifact = root / "content/014--001--6142/artifacts/questions.fa.md"
artifact.parent.mkdir(parents=True)
artifact.write_text("# Practice three\n")
manifest_path = root / "manifest.json"
manifest_path.write_text(json.dumps({"course": {
"id": 56, "fullname": "MCSA", "sections": [{"number": 14, "items": [
{"activity_id": activity_id, "activity_position": position,
"activity_type": "quiz", "kind": "quiz", "title": f"Practice {position}"}
for position, activity_id in enumerate((6142, 6151, 6238), 1)
]}]
}}))
scan_offline(public, [56])
course = json.loads(manifest_path.read_text())["course"]
items = course["sections"][0]["items"]
self.assertTrue(all(item["kind"] == "assessment" for item in items))
self.assertEqual([item["state"]["questions"] for item in items],
["complete", "missing", "missing"])
self.assertEqual(artifact.read_text(), "# Practice three\n")
self.assertEqual(course["states"]["assessments"], {"total": 3, "complete": 1, "missing": 2})
class PortableArtifactStateTests(unittest.TestCase): class PortableArtifactStateTests(unittest.TestCase):