@@ -644,6 +644,110 @@ async def test_batch_update_submission_statuses(
644644 assert converted_submission_annotations ["batch_processed" ] == ["true" ]
645645
646646
647+ class TestSubmissionStatusCancellation :
648+ """Tests for SubmissionStatus cancellation functionality async."""
649+
650+ @pytest .fixture (autouse = True , scope = "function" )
651+ def init (self , syn : Synapse , schedule_for_cleanup : Callable [..., None ]) -> None :
652+ self .syn = syn
653+ self .schedule_for_cleanup = schedule_for_cleanup
654+
655+ @pytest .fixture (scope = "function" )
656+ async def test_evaluation (
657+ self ,
658+ project_model : Project ,
659+ syn : Synapse ,
660+ schedule_for_cleanup : Callable [..., None ],
661+ ) -> Evaluation :
662+ """Create a test evaluation for submission status tests."""
663+ evaluation = Evaluation (
664+ name = f"test_evaluation_{ uuid .uuid4 ()} " ,
665+ description = "A test evaluation for submission status tests" ,
666+ content_source = project_model .id ,
667+ submission_instructions_message = "Please submit your results" ,
668+ submission_receipt_message = "Thank you!" ,
669+ )
670+ created_evaluation = await evaluation .store_async (synapse_client = syn )
671+ schedule_for_cleanup (created_evaluation .id )
672+ return created_evaluation
673+
674+ @pytest .fixture (scope = "function" )
675+ async def test_file (
676+ self ,
677+ project_model : Project ,
678+ syn : Synapse ,
679+ schedule_for_cleanup : Callable [..., None ],
680+ ) -> File :
681+ """Create a test file for submission status tests."""
682+ # Create a temporary file
683+ with tempfile .NamedTemporaryFile (
684+ mode = "w" , delete = False , suffix = ".txt"
685+ ) as temp_file :
686+ temp_file .write ("This is test content for submission status testing." )
687+ temp_file_path = temp_file .name
688+
689+ try :
690+ file = File (
691+ path = temp_file_path ,
692+ name = f"test_file_{ uuid .uuid4 ()} .txt" ,
693+ parent_id = project_model .id ,
694+ )
695+ stored_file = await file .store_async (synapse_client = syn )
696+ schedule_for_cleanup (stored_file .id )
697+ return stored_file
698+ finally :
699+ # Clean up the temporary file
700+ os .unlink (temp_file_path )
701+
702+ @pytest .fixture (scope = "function" )
703+ async def test_submission (
704+ self ,
705+ test_evaluation : Evaluation ,
706+ test_file : File ,
707+ syn : Synapse ,
708+ schedule_for_cleanup : Callable [..., None ],
709+ ) -> Submission :
710+ """Create a test submission for status tests."""
711+ submission = Submission (
712+ entity_id = test_file .id ,
713+ evaluation_id = test_evaluation .id ,
714+ name = f"Test Submission { uuid .uuid4 ()} " ,
715+ )
716+ created_submission = await submission .store_async (synapse_client = syn )
717+ schedule_for_cleanup (created_submission .id )
718+ return created_submission
719+
720+ async def test_submission_cancellation_workflow (
721+ self , test_submission : Submission
722+ ):
723+ """Test the complete submission cancellation workflow async."""
724+ # GIVEN a submission that exists
725+ submission_id = test_submission .id
726+
727+ # WHEN I get the initial submission status
728+ initial_status = await SubmissionStatus (id = submission_id ).get_async (synapse_client = self .syn )
729+
730+ # THEN initially it should not be cancellable or cancelled
731+ assert initial_status .can_cancel is False
732+ assert initial_status .cancel_requested is False
733+
734+ # WHEN I update the submission status to allow cancellation
735+ initial_status .can_cancel = True
736+ updated_status = await initial_status .store_async (synapse_client = self .syn )
737+
738+ # THEN the submission should be marked as cancellable
739+ assert updated_status .can_cancel is True
740+ assert updated_status .cancel_requested is False
741+
742+ # WHEN I cancel the submission
743+ await test_submission .cancel_async ()
744+
745+ # THEN I should be able to retrieve the updated status showing cancellation was requested
746+ final_status = await SubmissionStatus (id = submission_id ).get_async (synapse_client = self .syn )
747+ assert final_status .can_cancel is True
748+ assert final_status .cancel_requested is True
749+
750+
647751class TestSubmissionStatusValidation :
648752 """Tests for SubmissionStatus validation and error handling async."""
649753
0 commit comments