feat: implement import exam answers feature with preview and confirmation steps
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user