1
0
Files
coldcall_lti/tests/test_launch.py
Benjamin Mako Hill 52afc57ebd Phase 2: LTI plumbing, roster sync, and fake-launch dev mode
OIDC login, launch, and JWKS endpoints built on pylti1p3next's Flask
adapter, with launch-claim processing split into a testable module.
Instructor launches refresh the roster through NRPS; the sync code is
source-agnostic and also drives the dev-mode fake roster. Dev mode
(COLDCALL_DEV_MODE=1) provides fake instructor and student personas
that set up the same session state as a real launch, so the rest of
the app can be developed before a Canvas Developer Key exists.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-31 16:33:08 -07:00

52 lines
1.8 KiB
Python

from coldcall_lti import launch, models
def sample_launch_data(is_instructor=False):
roles = [launch.ROLE_INSTRUCTOR] if is_instructor else [launch.ROLE_LEARNER]
return {
"sub": "canvas-user-42",
"name": "Pat Example",
"email": "pat@example.edu",
"picture": "https://example.edu/pat.png",
launch.CLAIM_DEPLOYMENT: "dep-1",
launch.CLAIM_CONTEXT: {"id": "ctx-abc", "title": "COM 999"},
launch.CLAIM_ROLES: roles,
}
def test_extract_launch_info_student():
info = launch.extract_launch_info(sample_launch_data())
assert info.context_id == "ctx-abc"
assert info.course_title == "COM 999"
assert info.user_id == "canvas-user-42"
assert info.deployment_id == "dep-1"
assert not info.is_instructor
def test_extract_launch_info_instructor():
info = launch.extract_launch_info(sample_launch_data(is_instructor=True))
assert info.is_instructor
def test_upsert_launch_creates_and_is_idempotent(db_session):
info = launch.extract_launch_info(sample_launch_data())
course, student = launch.upsert_launch(db_session, info)
assert course.title == "COM 999"
assert student.canvas_user_id == "canvas-user-42"
course2, student2 = launch.upsert_launch(db_session, info)
assert course2.id == course.id
assert student2.id == student.id
assert db_session.query(models.Enrollment).count() == 1
def test_upsert_launch_reactivates_dropped_enrollment(db_session):
info = launch.extract_launch_info(sample_launch_data())
course, student = launch.upsert_launch(db_session, info)
enrollment = db_session.query(models.Enrollment).one()
enrollment.active = False
db_session.flush()
launch.upsert_launch(db_session, info)
assert db_session.query(models.Enrollment).one().active