-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
247 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
"""This module contains the tests for the allow_resubmission module.""" | ||
|
||
import datetime | ||
import unittest | ||
|
||
import ddt | ||
|
||
from openassessment.xblock.utils.allow_resubmission import allow_resubmission | ||
|
||
|
||
class ConfigDataMock: | ||
"""Mock class for the ORAConfigAPI object.""" | ||
|
||
def __init__(self): | ||
self.allow_learner_resubmissions = True | ||
self.submission_due = "2029-01-01T00:00:00+00:00" | ||
self.resubmissions_grace_period_hours = 0 | ||
self.resubmissions_grace_period_minutes = 0 | ||
|
||
|
||
class WorkflowDataMock: | ||
"""Mock class for the WorkflowAPI object.""" | ||
|
||
def __init__(self): | ||
self.status = "waiting" | ||
self.status_details = { | ||
"staff": {"complete": True, "graded": False, "skipped": False}, | ||
"peer": { | ||
"complete": False, | ||
"graded": False, | ||
"skipped": True, | ||
"peers_graded_count": 0, | ||
"graded_by_count": 0, | ||
}, | ||
} | ||
|
||
|
||
@ddt.ddt | ||
class TestAllowResubmission(unittest.TestCase): | ||
"""Tests for the allow_resubmission module.""" | ||
|
||
def setUp(self): | ||
self.config_data = ConfigDataMock() | ||
self.workflow_data = WorkflowDataMock() | ||
self.submission_data = { | ||
"created_at": datetime.datetime.now(tz=datetime.timezone.utc) | ||
} | ||
|
||
def test_allow_resubmission_all_conditions_met(self): | ||
""" | ||
Test case for the allow_resubmission function when all conditions are met. | ||
This test checks if the function returns True when: | ||
- Learner resubmissions are allowed | ||
- The submission date has not been exceeded | ||
- The workflow has not been graded | ||
""" | ||
result = allow_resubmission( | ||
self.config_data, self.workflow_data, self.submission_data | ||
) | ||
|
||
self.assertTrue(result) | ||
|
||
@ddt.data( | ||
(1, 0), | ||
(0, 30), | ||
(10, 59), | ||
(0, 0), | ||
) | ||
@ddt.unpack | ||
def test_allow_resubmission_resubmissions_with_grace_period( | ||
self, hours: int, minutes: int | ||
): | ||
""" | ||
Test case for the allow_resubmission function when the resubmissions grace period is set. | ||
""" | ||
self.config_data.resubmissions_grace_period_hours = hours | ||
self.config_data.resubmissions_grace_period_minutes = minutes | ||
|
||
result = allow_resubmission( | ||
self.config_data, self.workflow_data, self.submission_data | ||
) | ||
|
||
self.assertTrue(result) | ||
|
||
def test_allow_resubmission_resubmissions_with_grace_period_exceeded(self): | ||
""" | ||
Test case for the allow_resubmission function when the resubmissions grace period is exceeded. | ||
""" | ||
self.submission_data["created_at"] = datetime.datetime( | ||
2020, 1, 1, tzinfo=datetime.timezone.utc | ||
) | ||
self.config_data.resubmissions_grace_period_hours = 1 | ||
self.config_data.resubmissions_grace_period_minutes = 30 | ||
|
||
result = allow_resubmission( | ||
self.config_data, self.workflow_data, self.submission_data | ||
) | ||
|
||
self.assertFalse(result) | ||
|
||
def test_allow_resubmission_resubmissions_not_allowed(self): | ||
""" | ||
Test case for the allow_resubmission function when learner resubmissions are not allowed. | ||
""" | ||
self.config_data.allow_learner_resubmissions = False | ||
result = allow_resubmission( | ||
self.config_data, self.workflow_data, self.submission_data | ||
) | ||
|
||
self.assertFalse(result) | ||
|
||
def test_allow_resubmission_submission_date_exceeded(self): | ||
""" | ||
Test case for the allow_resubmission function when the submission date has been exceeded. | ||
""" | ||
self.config_data.submission_due = "2020-01-01T00:00:00+00:00" | ||
|
||
result = allow_resubmission( | ||
self.config_data, self.workflow_data, self.submission_data | ||
) | ||
|
||
self.assertFalse(result) | ||
|
||
@ddt.data("done", "cancelled") | ||
def test_allow_resubmission_has_been_graded_or_cancelled(self, status: str): | ||
""" | ||
Test case for the allow_resubmission function when the | ||
learner's response has been graded or cancelled. | ||
""" | ||
self.workflow_data.status = status | ||
|
||
result = allow_resubmission( | ||
self.config_data, self.workflow_data, self.submission_data | ||
) | ||
|
||
self.assertFalse(result) | ||
|
||
@ddt.data( | ||
(0, True), | ||
(1, False), | ||
(2, False), | ||
) | ||
@ddt.unpack | ||
def test_allow_resubmission_has_been_graded_by_peers( | ||
self, count: int, expected_result: bool | ||
): | ||
""" | ||
Test case for the allow_resubmission function when the | ||
learner's response has been graded by peers. | ||
""" | ||
self.workflow_data.status = "self" | ||
self.workflow_data.status_details["peer"]["graded_by_count"] = count | ||
|
||
result = allow_resubmission( | ||
self.config_data, self.workflow_data, self.submission_data | ||
) | ||
|
||
self.assertEqual(result, expected_result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters