Skip to content

Commit 5e762f0

Browse files
committed
new test class for submission cancel functionality
1 parent f34667d commit 5e762f0

File tree

2 files changed

+207
-0
lines changed

2 files changed

+207
-0
lines changed

tests/integration/synapseclient/models/async/test_submission_status_async.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
647751
class TestSubmissionStatusValidation:
648752
"""Tests for SubmissionStatus validation and error handling async."""
649753

tests/integration/synapseclient/models/synchronous/test_submission_status.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,109 @@ async def test_batch_update_submission_statuses(
641641
assert converted_submission_annotations["batch_processed"] == ["true"]
642642

643643

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

0 commit comments

Comments
 (0)