Rencana mingguan RPS: satu minggu boleh lebih dari satu Sub-CPMK

- Pilihan Sub-CPMK per minggu jadi kotak centang (kunci "subs"); "sub" tetap
  berisi teks gabungan untuk pembaca lama. Catatan bila >2 di minggu biasa.
- UTS/UAS mencentang Sub-CPMK yang benar-benar diujikan; penanda lama
  __uts__/__uas__ diurai otomatis dari minggu 1-7 / 9-15.
- Bobot per minggu tetap satu angka; rumus nilai tetap dari bagian G.
- Cek baru: Sub-CPMK belum direncanakan (F) dan diajarkan tapi tidak diukur (G).
- .docx, RPS publik, dan portofolio (Jumlah Minggu, rencana penilaian) ikut daftar.
- Data lama dan kiriman form versi lama (dropdown) tetap terbaca.
- Uji baru tests/uji_sub_minggu.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Power BI Dev
2026-11-16 12:18:07 +07:00
co-authored by Claude Opus 5.5
parent 7b15429848
commit 4e1020290e
8 changed files with 196 additions and 54 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
cd "$(dirname "$0")/.." || exit 1
ROOT="$(pwd -W 2>/dev/null || pwd)"
gagal=0
for u in uji_peran uji_autosave uji_simpan uji_klinik3 uji_cqi uji_impor uji_siklus uji_kurikulum uji_google; do
for u in uji_peran uji_autosave uji_simpan uji_klinik3 uji_cqi uji_impor uji_siklus uji_kurikulum uji_google uji_sub_minggu; do
cp data/app.db tests/uji.db
if PYTHONIOENCODING=utf-8 python "tests/$u.py" "$ROOT" > "tests/$u.log" 2>&1; then echo "OK $u"; else echo "GAGAL $u (lihat tests/$u.log)"; gagal=1; fi
done
+4 -1
View File
@@ -47,7 +47,9 @@ r = c.post(f"/rps/{kode}", content=urlencode(isi), follow_redirects=False,
headers={"Content-Type": "application/x-www-form-urlencoded"})
baru = db.ambil_rps(kode)["data"]
cek(baru.get("sub_uraian_custom") == custom, "simpan ulang: redaksi tersesuaikan utuh")
cek(baru["minggu"] == lama["minggu"] and baru["komponen"] == lama["komponen"] and baru["identitas"] == lama["identitas"],
def _urut(mk): return [x["kode"] for x in db.peta_mk(mk)["subs"]]
# rencana mingguan lama (1 Sub-CPMK/minggu, penanda UTS/UAS) sengaja dinormalkan jadi daftar
cek(baru["minggu"] == main.normal_minggu(lama["minggu"], _urut(kode)) and baru["komponen"] == lama["komponen"] and baru["identitas"] == lama["identitas"],
"simpan ulang: rencana mingguan, komponen, identitas tidak berubah")
# SEMUA RPS produksi: buka → simpan ulang tanpa perubahan → isi identik
@@ -64,6 +66,7 @@ for mk, in [tuple(r) for r in db.get_conn().execute("SELECT mk_kode FROM rps")]:
c2.post(f"/rps/{mk}", content=urlencode(kirim), follow_redirects=False,
headers={"Content-Type": "application/x-www-form-urlencoded"})
sesudah = db.ambil_rps(mk)["data"]
sebelum = {**sebelum, "minggu": main.normal_minggu(sebelum.get("minggu") or main.minggu_default(), _urut(mk))}
beda = [b for b in sebelum if _j.dumps(sebelum[b], sort_keys=True).replace("\r\n", "\n") != _j.dumps(sesudah.get(b), sort_keys=True).replace("\r\n", "\n")]
cek(not beda, f"{mk}: buka + simpan ulang tanpa perubahan → isi identik {beda}")
+77
View File
@@ -0,0 +1,77 @@
"""Rencana mingguan RPS: satu minggu boleh >1 Sub-CPMK, satu Sub-CPMK boleh di beberapa minggu,
UTS/UAS memakai centang Sub-CPMK nyata; data lama (1 kode/minggu, penanda __uts__/__uas__) tetap terbaca."""
import io, os, sys
from urllib.parse import urlencode
SP = os.path.dirname(os.path.abspath(__file__))
os.environ["DB_PATH"] = os.path.join(SP, "uji.db")
sys.path.insert(0, sys.argv[1])
from docx import Document
from fastapi.testclient import TestClient
from app import main, db, auth
gagal = []
def cek(ok, pesan):
print(("OK " if ok else "GAGAL"), pesan)
if not ok: gagal.append(pesan)
# ── normalisasi data lama ──
lama = [{"ke": 1, "sub": "S1"}, {"ke": 2, "sub": "S2"}, {"ke": 3, "sub": "S1"},
{"ke": 8, "sub": "__uts__"}, {"ke": 9, "sub": "S3"}, {"ke": 16, "sub": "__uas__"},
{"ke": 4, "sub": "LAIN"}]
n = {m["ke"]: m for m in main.normal_minggu(lama, ["S1", "S2", "S3"])}
cek(n[1]["subs"] == ["S1"] and n[1]["sub"] == "S1", "kode tunggal lama → daftar satu kode")
cek(n[8]["subs"] == ["S1", "S2"], "penanda UTS lama → Sub-CPMK minggu 1–7, tanpa duplikat")
cek(n[16]["subs"] == ["S3"], "penanda UAS lama → Sub-CPMK minggu 9–15")
cek(n[4]["subs"] == [], "kode di luar kurikulum MK dibuang bila urutan diberikan")
cek(main.normal_minggu([{"ke": 5, "subs": ["S2", "S1"]}], ["S1", "S2"])[0]["subs"] == ["S1", "S2"],
"daftar baru diurutkan sesuai kurikulum")
# ── simpan lewat form ──
kode = next(m["kode"] for m in db.daftar_mk()
if not db.terkunci(m["kode"]) and len((db.peta_mk(m["kode"]) or {}).get("subs", [])) >= 3)
subs = [s["kode"] for s in db.peta_mk(kode)["subs"]]
dosen = next(p for p in db.daftar_pengguna() if p["role"] == "dosen")
db.set_penugasan(dosen["id"], [(kode, "koordinator")], {}) # hanya koordinator boleh simpan
tok = auth.token_baru(); db.buat_sesi(dosen["id"], tok)
c = TestClient(main.app); c.cookies.set("sesi", tok)
cek(c.get(f"/rps/{kode}").status_code == 200, f"{kode}: form RPS tampil")
isi = [("m2_subs", subs[0]), ("m2_subs", subs[1]), # minggu 2: dua Sub-CPMK
("m3_subs", subs[0]), ("m4_subs", subs[0]), # Sub-CPMK pertama diulang 3 minggu
("m8_subs", subs[0]), ("m8_subs", subs[1]), # UTS mencakup dua
("m2_bobot", "10"), ("k1_nama", "Kuis"), ("k1_subs", subs[0]), ("k1_bobot", "100"),
("aksi", "draft")]
r = c.post(f"/rps/{kode}", content=urlencode(isi), follow_redirects=False,
headers={"Content-Type": "application/x-www-form-urlencoded"})
cek(r.status_code == 303, "simpan RPS diterima")
mg = {m["ke"]: m for m in db.ambil_rps(kode)["data"]["minggu"]}
cek(mg[2]["subs"] == [subs[0], subs[1]], "minggu 2 menyimpan dua Sub-CPMK")
cek(mg[2]["sub"] == f"{subs[0]}, {subs[1]}", "kunci 'sub' tetap berisi teks gabungan untuk pembaca lama")
cek(mg[8]["subs"] == [subs[0], subs[1]], "UTS menyimpan Sub-CPMK yang dicentang")
cek(mg[5]["subs"] == [] and mg[5]["sub"] == "", "minggu tanpa centang → kosong")
h = c.get(f"/rps/{kode}").text
cek(h.count(f'name="m2_subs" value="{subs[0]}" checked') == 1
and f'name="m2_subs" value="{subs[1]}" checked' in h, "form menampilkan centang tersimpan")
# halaman versi lama (dropdown m{w}_sub) tetap bisa menyimpan
r = c.post(f"/rps/{kode}", content=urlencode([("m1_sub", subs[2]), ("aksi", "draft")]),
follow_redirects=False, headers={"Content-Type": "application/x-www-form-urlencoded"})
cek(db.ambil_rps(kode)["data"]["minggu"][0]["subs"] == [subs[2]], "kiriman dropdown lama tetap tersimpan")
c.post(f"/rps/{kode}", content=urlencode(isi), follow_redirects=False,
headers={"Content-Type": "application/x-www-form-urlencoded"})
# ── portofolio: jumlah minggu per Sub-CPMK (minggu ujian tidak dihitung) ──
bahan = main._bahan_porto(kode)
cek(bahan["minggu_sub"].get(subs[0]) == 3 and bahan["minggu_sub"].get(subs[1]) == 1,
f"jumlah minggu: {subs[0]}=3, {subs[1]}=1 (UTS tidak dihitung)")
rc = {x["minggu"]: x["sub"] for x in bahan["rencana"]}
cek(rc[2] == f"{subs[0]}, {subs[1]}" and rc[8] == f"UTS ({subs[0]}, {subs[1]})", "label rencana penilaian portofolio")
# ── .docx RPS ──
r = c.get(f"/rps/{kode}/unduh")
doc = Document(io.BytesIO(r.content))
sel = [cell.text for tb in doc.tables for row in tb.rows for cell in row.cells]
cek(r.status_code == 200 and any(subs[0] in t and subs[1] in t and "\n" in t for t in sel),
"unduhan .docx menulis kedua Sub-CPMK minggu 2 dalam satu sel")
print("TOTAL GAGAL:", len(gagal)); sys.exit(1 if gagal else 0)