1919
2020# Local imports
2121from submissions import api
22- from submissions .api import SubmissionFileProcessor
22+ from submissions .api import create_external_grader_detail , get_files_for_grader
2323from submissions .errors import ExternalGraderQueueEmptyError , SubmissionInternalError
2424from submissions .models import (
2525 ExternalGraderDetail ,
@@ -993,44 +993,71 @@ def test_create_external_grader_detail_without_files(self):
993993 self .assertEqual (external_grader_instance .files .count (), 0 )
994994
995995
996- class TestSubmissionFileProcessor (TestCase ):
996+ class TestExternalGraderFileProcessing (TestCase ):
997997 """
998- Test the SubmissionFileProcessor functionality.
998+ Test the file processing functionality for external graders .
999999 """
10001000
10011001 def setUp (self ):
10021002 """Set up common test data."""
1003- self .student_item = StudentItem .objects .create (
1004- student_id = "test_student" ,
1005- course_id = "test_course" ,
1006- item_id = "test_item"
1007- )
1008- self .submission = Submission .objects .create (
1009- student_item = self .student_item ,
1010- answer = "test answer" ,
1011- attempt_number = 1
1012- )
1013- self .external_grader_detail = ExternalGraderDetail .objects .create (
1014- submission = self .submission ,
1015- queue_name = "test_queue"
1016- )
1017- self .processor = SubmissionFileProcessor (self .external_grader_detail )
1003+ self .student_item_dict = {
1004+ "student_id" : "test_student" ,
1005+ "course_id" : "test_course" ,
1006+ "item_id" : "test_item" ,
1007+ "item_type" : "test_type"
1008+ }
1009+ self .answer = "test answer"
1010+ self .queue_name = "test_queue"
10181011
1019- def test_process_files_with_file_objects (self ):
1020- """Test processing files with file objects that have a file attribute ."""
1012+ def test_create_external_grader_with_files (self ):
1013+ """Test processing files within create_external_grader_detail ."""
10211014
10221015 class FileObjWithFileAttr :
10231016 def __init__ (self ):
10241017 self .file = SimpleUploadedFile ("test.txt" , b"test content" )
10251018
10261019 file_obj = FileObjWithFileAttr ()
10271020 files_dict = {"test.txt" : file_obj }
1028- urls = self .processor .process_files (files_dict )
1029- self .assertEqual (len (urls ), 1 )
1030- self .assertTrue (urls ["test.txt" ].startswith (f"/{ self .external_grader_detail .queue_name } /" ))
1021+
1022+ # Create external grader with files
1023+ instance = create_external_grader_detail (
1024+ student_item_dict = self .student_item_dict ,
1025+ answer = self .answer ,
1026+ queue_name = self .queue_name ,
1027+ files = files_dict
1028+ )
1029+
1030+ # Verify SubmissionFile was created correctly
1031+ submission_file = SubmissionFile .objects .get (
1032+ external_grader = instance ,
1033+ original_filename = "test.txt"
1034+ )
1035+ self .assertTrue (submission_file .xqueue_url .startswith (f"/{ self .queue_name } /" ))
10311036
10321037 def test_get_files_for_grader (self ):
1033- """Test retrieving files in xwatcher format."""
1038+ """Test the standalone get_files_for_grader function."""
1039+
1040+ class FileObjWithFileAttr :
1041+ def __init__ (self ):
1042+ self .file = SimpleUploadedFile ("test.txt" , b"test content" )
1043+
1044+ # Create external grader with a file
1045+ instance = create_external_grader_detail (
1046+ student_item_dict = self .student_item_dict ,
1047+ answer = self .answer ,
1048+ queue_name = self .queue_name ,
1049+ files = {"test.txt" : FileObjWithFileAttr ()}
1050+ )
1051+
1052+ # Test get_files_for_grader function
1053+ grader_files = get_files_for_grader (instance )
1054+ self .assertEqual (len (grader_files ), 1 )
1055+ self .assertIn ("test.txt" , grader_files )
1056+ self .assertTrue (isinstance (grader_files ["test.txt" ], str ))
1057+
1058+ def test_multiple_files_processing (self ):
1059+ """Test processing multiple files through create_external_grader_detail."""
1060+
10341061 class FileObjWithFileAttr1 :
10351062 def __init__ (self ):
10361063 self .file = SimpleUploadedFile ("test1.txt" , b"content1" )
@@ -1039,16 +1066,30 @@ class FileObjWithFileAttr2:
10391066 def __init__ (self ):
10401067 self .file = SimpleUploadedFile ("test2.txt" , b"content2" )
10411068
1042- self . processor . process_files ( {
1069+ files_dict = {
10431070 "test1.txt" : FileObjWithFileAttr1 (),
10441071 "test2.txt" : FileObjWithFileAttr2 ()
1045- })
1072+ }
10461073
1047- grader_files = self .processor .get_files_for_grader ()
1074+ # Create external grader with multiple files
1075+ instance = create_external_grader_detail (
1076+ student_item_dict = self .student_item_dict ,
1077+ answer = self .answer ,
1078+ queue_name = self .queue_name ,
1079+ files = files_dict
1080+ )
1081+
1082+ # Verify both files were created
1083+ submission_files = SubmissionFile .objects .filter (external_grader = instance )
1084+ self .assertEqual (submission_files .count (), 2 )
1085+
1086+ # Test get_files_for_grader
1087+ grader_files = get_files_for_grader (instance )
10481088 self .assertEqual (len (grader_files ), 2 )
1049- self .assertTrue (all (isinstance (url , str ) for url in grader_files .values ()))
1089+ self .assertIn ("test1.txt" , grader_files )
1090+ self .assertIn ("test2.txt" , grader_files )
10501091
1051- def test_process_files_complete_flow (self ):
1092+ def test_complete_file_processing_flow (self ):
10521093 """
10531094 Test the complete flow of processing a file through to SubmissionFile creation.
10541095 """
@@ -1059,17 +1100,22 @@ def __init__(self):
10591100
10601101 files_dict = {"complete_test.txt" : FileObjWithFileAttr ()}
10611102
1062- # Process the file
1063- urls = self . processor . process_files ( files_dict )
1064-
1065- # Verify URL was created
1066- self .assertEqual ( len ( urls ), 1 )
1067- file_url = urls [ "complete_test.txt" ]
1068- self . assertTrue ( file_url . startswith ( f"/ { self . external_grader_detail . queue_name } /" ) )
1103+ # Create external grader with file
1104+ instance = create_external_grader_detail (
1105+ student_item_dict = self . student_item_dict ,
1106+ answer = self . answer ,
1107+ queue_name = self .queue_name ,
1108+ files = files_dict
1109+ )
10691110
10701111 # Verify SubmissionFile was created correctly
10711112 submission_file = SubmissionFile .objects .get (
1072- external_grader = self . external_grader_detail ,
1113+ external_grader = instance ,
10731114 original_filename = "complete_test.txt"
10741115 )
1075- self .assertEqual (submission_file .xqueue_url , file_url )
1116+
1117+ # Verify URL format
1118+ self .assertTrue (submission_file .xqueue_url .startswith (f"/{ self .queue_name } /" ))
1119+
1120+ # Verify file content is accessible
1121+ self .assertEqual (submission_file .file .read (), b"test binary content" )
0 commit comments