diff --git a/openassessment/runtime_imports/classes.py b/openassessment/runtime_imports/classes.py index 89cdd4b4d3..e518f9d27e 100644 --- a/openassessment/runtime_imports/classes.py +++ b/openassessment/runtime_imports/classes.py @@ -41,6 +41,7 @@ def import_waffle_flag(): def import_student_module(): """ Helper method that imports StudentModule from edx-platform at runtime. + https://github.com/openedx/edx-platform/blob/master/lms/djangoapps/courseware/models.py#L79 """ from lms.djangoapps.courseware.models import StudentModule return StudentModule diff --git a/openassessment/xblock/test/test_allow_resubmission.py b/openassessment/xblock/test/test_allow_resubmission.py index 4c0f2c5196..a827d2a132 100644 --- a/openassessment/xblock/test/test_allow_resubmission.py +++ b/openassessment/xblock/test/test_allow_resubmission.py @@ -13,10 +13,12 @@ class ConfigDataMock: 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 + def is_closed(self, step: str): # pylint: disable=unused-argument + return (False, None, None, None) + class WorkflowDataMock: """Mock class for the WorkflowAPI object.""" @@ -104,6 +106,7 @@ 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 ) @@ -114,7 +117,7 @@ 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" + self.config_data.is_closed = lambda step: (True, "due", None, None) result = allow_resubmission( self.config_data, self.workflow_data, self.submission_data diff --git a/openassessment/xblock/test/test_submission.py b/openassessment/xblock/test/test_submission.py index 376cda2bff..de961d7333 100644 --- a/openassessment/xblock/test/test_submission.py +++ b/openassessment/xblock/test/test_submission.py @@ -153,23 +153,54 @@ def test_cannot_submit_in_preview_mode(self, xblock): self.assertEqual(resp[1], "ENOPREVIEW") self.assertIsNot(resp[2], None) + @patch("openassessment.xblock.openassessmentblock.import_student_module") @patch("openassessment.xblock.openassessmentblock.reset_student_attempts") @patch("openassessment.xblock.openassessmentblock.get_user_by_username_or_email") @scenario("data/basic_scenario.xml", user_id="Bob") - def test_reset_submission(self, xblock, mock_user: Mock, mock_reset: Mock): + def test_reset_submission( + self, xblock, mock_user: Mock, mock_reset: Mock, mock_student_module: Mock + ): xblock.xmodule_runtime = Mock(course_id=COURSE_ID) mock_user.return_value = "test-user" mock_reset.return_value = True + mock_student_module.return_value = "test-student-module" resp = self.request(xblock, "reset_submission", json.dumps({}), response_format="json") + self.assertTrue(resp["success"]) self.assertEqual(resp["msg"], "Submission reset successfully.") + @patch("openassessment.xblock.openassessmentblock.import_student_module") + @patch("openassessment.xblock.openassessmentblock.get_user_by_username_or_email") @scenario("data/basic_scenario.xml", user_id="Bob") - def test_reset_submission_error(self, xblock): + def test_reset_submission_user_not_found_error( + self, xblock, mock_user: Mock, mock_student_module: Mock + ): + mock_student_module.return_value = "test-student-module" + mock_user.side_effect = get_user_model().DoesNotExist + resp = self.request(xblock, "reset_submission", json.dumps({}), response_format="json") self.assertFalse(resp["success"]) - self.assertEqual(resp["msg"], "Error resetting submission.") + self.assertEqual(resp["msg"], "The user does not exist.") + + @patch("openassessment.xblock.openassessmentblock.import_student_module") + @patch("openassessment.xblock.openassessmentblock.reset_student_attempts") + @patch("openassessment.xblock.openassessmentblock.get_user_by_username_or_email") + @scenario("data/basic_scenario.xml", user_id="Bob") + def test_reset_submission_submission_not_found_error( + self, xblock, mock_user: Mock, mock_reset: Mock, mock_student_module: Mock + ): + xblock.xmodule_runtime = Mock(course_id=COURSE_ID) + mock_user.side_effect = "test-user" + error_mock = Mock() + error_mock.DoesNotExist = ObjectDoesNotExist + mock_student_module.return_value = error_mock + mock_reset.side_effect = ObjectDoesNotExist + + resp = self.request(xblock, "reset_submission", json.dumps({}), response_format="json") + + self.assertFalse(resp["success"]) + self.assertEqual(resp["msg"], "There is no submission to reset.") @scenario('data/over_grade_scenario.xml', user_id='Alice') def test_closed_submissions(self, xblock):