feat: implement import exam answers feature with preview and confirmation steps

This commit is contained in:
Ross
2026-07-05 22:47:50 +01:00
parent 89963d6257
commit 5ce4a67b31
5 changed files with 462 additions and 194 deletions
+14 -2
View File
@@ -223,11 +223,23 @@ def test_import_exam_answers_post_success(cid_manager_client, exam_data, logged_
answers_file.name = "backup.json"
url = reverse("generic:import_exam_answers")
# 1. First stage: Upload file -> renders preview
response = cid_manager_client.post(url, {"answers_file": answers_file}, format="multipart")
assert response.status_code == 200
assert b"Preview Import" in response.content
assert b"Imported Test Answer" in response.content
assert response.status_code == 302 # redirects to manage_cids on success
# Check session has pending data
assert cid_manager_client.session["pending_import_data"] == import_data
# Verify answers were saved
# 2. Second stage: Confirm import
response2 = cid_manager_client.post(url, {"confirm": "1"})
assert response2.status_code == 200
assert b"Import Successful" in response2.content
assert b"1" in response2.content # created_count count
# Verify answers were saved to DB
answers = AnatomyUserAnswer.objects.filter(exam=exam, user=logged_in_user)
assert answers.count() == 1
assert answers.first().answer == "Imported Test Answer"