From e9300e1541f284fb9a262d0c2615897addee5cb5 Mon Sep 17 00:00:00 2001 From: Alie Langston Date: Tue, 21 Sep 2021 11:19:15 -0400 Subject: [PATCH] fix: if multiple attempts for a user exist, return attempt with non-reset status if possible MST-995. If a user has two or more active attempts, and one of them is has an onboarding_reset status, we should always return the non reset status attempt. --- CHANGELOG.rst | 4 ++++ edx_proctoring/__init__.py | 2 +- edx_proctoring/tests/test_views.py | 9 ++++++++- edx_proctoring/views.py | 9 ++++++++- package.json | 2 +- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a3455e0435f..6529fee16a3 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,10 @@ Change Log Unreleased ~~~~~~~~~~ +[4.0.1] - 2021-09-21 +~~~~~~~~~~~~~~~~~~~~~ +* Bug fix for student onboarding statuses by course. If learner has multiple attempts, return non-reset attempt status if possible. + [4.0.0] - 2021-08-25 ~~~~~~~~~~~~~~~~~~~~~ **BREAKING CHANGES:** diff --git a/edx_proctoring/__init__.py b/edx_proctoring/__init__.py index 8a223adf8c9..161fd8ee38f 100644 --- a/edx_proctoring/__init__.py +++ b/edx_proctoring/__init__.py @@ -3,6 +3,6 @@ """ # Be sure to update the version number in edx_proctoring/package.json -__version__ = '4.0.0' +__version__ = '4.0.1' default_app_config = 'edx_proctoring.apps.EdxProctoringConfig' # pylint: disable=invalid-name diff --git a/edx_proctoring/tests/test_views.py b/edx_proctoring/tests/test_views.py index db59f780638..a03f52540c7 100644 --- a/edx_proctoring/tests/test_views.py +++ b/edx_proctoring/tests/test_views.py @@ -1598,7 +1598,8 @@ def test_returns_correct_attempt(self, attempt_statuses, expected_onboarding_sta self.assertEqual(response.status_code, 200) self.assertEqual(response_data['results'][0]['status'], expected_onboarding_status) - def test_multiple_exam_attempts(self): + @ddt.data(True, False) + def test_multiple_exam_attempts(self, should_reset_attempt_be_most_recent_modified): attempt_id = create_exam_attempt(self.onboarding_exam.id, self.user.id, True) # create a second exam attempt by resetting the onboarding attempt @@ -1609,6 +1610,12 @@ def test_multiple_exam_attempts(self): # get serialized onboarding_attempt to get modified time serialized_onboarding_attempt = get_exam_attempt_by_id(second_exam_attempt_id) + if should_reset_attempt_be_most_recent_modified: + # if we want the reset attempt to have the most recent modified date, we should resave the attempt + # a reset attempt having a more recent modified date is an edge case + attempt = ProctoredExamStudentAttempt.objects.get(id=attempt_id) + attempt.save() + response = self.client.get(reverse( 'edx_proctoring:user_onboarding.status.course', kwargs={'course_id': self.onboarding_exam.course_id} diff --git a/edx_proctoring/views.py b/edx_proctoring/views.py index 5e079591d95..a2112d39883 100644 --- a/edx_proctoring/views.py +++ b/edx_proctoring/views.py @@ -870,7 +870,7 @@ def _get_onboarding_info_no_onboarding_api(self, course_id, onboarding_exam, use onboarding_attempts = ProctoredExamStudentAttempt.objects.get_proctored_practice_attempts_by_course_id( course_id, users - ).values('user_id', 'status', 'modified') + ).values('user_id', 'status', 'modified', 'id') # get all of the last verified onboarding attempts of these users last_verified_attempt_dict = get_last_verified_onboarding_attempts_per_user( @@ -967,6 +967,7 @@ def _get_relevant_attempt_per_user(self, attempts): """ Given an ordered list of attempts, return, for each learner, their most recent exam attempt. If the learner has a verified attempt, always return verified. + If possible, do not return a reset attempt. Parameters: * attempts: an iterable of attempt objects """ @@ -979,6 +980,12 @@ def _get_relevant_attempt_per_user(self, attempts): # Always return a verified attempt if it exists. if attempt['status'] == ProctoredExamStudentAttemptStatus.verified: onboarding_attempts_per_user[attempt['user_id']] = attempt + # Always return a non reset attempt if its ID is greater + if ( + existing_attempt['status'] == ProctoredExamStudentAttemptStatus.onboarding_reset + and existing_attempt['id'] < attempt['id'] + ): + onboarding_attempts_per_user[attempt['user_id']] = attempt else: onboarding_attempts_per_user[attempt['user_id']] = attempt diff --git a/package.json b/package.json index 87cae471859..9b9bd5b254e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@edx/edx-proctoring", "//": "Note that the version format is slightly different than that of the Python version when using prereleases.", - "version": "4.0.0", + "version": "4.0.1", "main": "edx_proctoring/static/index.js", "scripts": { "test": "gulp test"