Skip to main content

Integration Tests

All integration tests are in tests/test_integration.py and use FastAPI's TestClient to send real HTTP requests without running a live server.

How to Run

pytest tests/test_integration.py -v

Overview

Integration tests verify that API endpoints behave correctly end-to-end - request in, response out, correct status codes and payloads. No browser or real network needed.


Quiz / Answer Checking

TestEndpointWhat it checksFails if
test_check_answer_correctPOST /api/check_answercorrect answer returns successcorrect answer is marked wrong or endpoint crashes
test_get_configGET /api/configconfig endpoint returns expected shaperesponse is missing required fields
test_learner_can_fetch_video_listGET /api/kids_videosvideo list returns successfullyendpoint errors or returns wrong format
test_learner_can_fetch_questions_for_videoGET /api/final-questions/{video_id}questions returned for a valid videoquestions are missing or malformed

Child Management

TestEndpointWhat it checksFails if
test_admin_can_unlink_child_endpointPOST /api/admin/children/{id}/unlinkchild unlinked from parentchild remains linked after the call
test_admin_can_relink_child_with_putPUT /api/admin/children/{id}child re-linked via updateupdate is ignored or returns wrong status
test_learner_child_videos_empty_when_unlinkedGET /api/learners/children/{id}/videosunlinked child sees no videosunlinked child can still access videos they shouldn't see
test_delete_expert_endpoint_unlinks_child_not_failDELETE /api/admin/experts/{id}deleting parent does not hard-fail on linked childrenserver crashes when a parent with children is deleted
test_delete_child_endpointDELETE /api/admin/children/{id}child deleted successfullychild record remains in DB after delete
test_delete_child_nonexistent_returns_404DELETE /api/admin/children/{id}404 returned for unknown childserver crashes or returns 200 for a child that does not exist

Icon Validation

TestEndpointWhat it checksFails if
test_new_icon_keys_accepted_by_apiPOST /api/admin/childrennew icon keys acceptedvalid icons are rejected, blocking child creation
test_invalid_icon_rejected_by_apiPOST /api/admin/childreninvalid icon key returns 400bad icon is silently accepted and stored
test_duplicate_name_same_expert_allowed_via_apiPOST /api/admin/childrenduplicate name allowed via APIsecond child with same name is incorrectly rejected

Video Claiming

TestWhat it checksFails if
test_claim_and_unclaim_video_apiclaim and unclaim calls hit the correct service functionswrong service is called or no DB change is made

Reports

TestWhat it checksFails if
test_get_child_report_scoped_filters_by_modereport filters attempts by interaction mode correctlyall attempts are returned regardless of mode, mixing strict and flexible data

Parent Login

TestEndpointWhat it checksFails if
test_parent_login_wrong_code_returns_failurePOST /api/learners/parents/loginwrong access code returns success: falsewrong code is accepted and grants access
test_parent_login_empty_code_returns_400POST /api/learners/parents/loginempty code returns 400empty string is treated as a valid code

Downloader API

TestEndpointWhat it checksFails if
test_download_endpoint_returns_structured_failure_payloadPOST /api/downloadprotected-download failures return structured fields (error_code, recovery_hint, auth_source)server crashes with an unhandled exception instead of returning a useful error to the frontend