-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: exam reset producer #196
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
get_exam_by_content_id, | ||
get_exam_url_path, | ||
is_exam_passed_due, | ||
reset_exam_attempt, | ||
update_attempt_status | ||
) | ||
from edx_exams.apps.core.exceptions import ( | ||
|
@@ -35,7 +36,7 @@ | |
) | ||
from edx_exams.apps.core.models import Exam, ExamAttempt | ||
from edx_exams.apps.core.statuses import ExamAttemptStatus | ||
from edx_exams.apps.core.test_utils.factories import ExamAttemptFactory, ExamFactory | ||
from edx_exams.apps.core.test_utils.factories import ExamAttemptFactory, ExamFactory, UserFactory | ||
|
||
test_start_time = datetime(2023, 11, 4, 11, 5, 23) | ||
test_time_limit_mins = 30 | ||
|
@@ -623,6 +624,62 @@ def test_exam_with_no_due_date(self): | |
self.assertIsNotNone(ExamAttempt.objects.get(user_id=user_id, exam_id=exam_id)) | ||
|
||
|
||
class TestResetExamAttempt(ExamsAPITestCase): | ||
""" | ||
Tests for the API utility function `reset_exam_attempt` | ||
""" | ||
def setUp(self): | ||
super().setUp() | ||
|
||
self.exam = ExamFactory() | ||
self.student_user = UserFactory() | ||
self.exam_attempt = ExamAttemptFactory(user=self.student_user, exam=self.exam) | ||
|
||
def test_reset_exam_attempt(self): | ||
""" | ||
Test that an exam attempt is deleted | ||
""" | ||
reset_exam_attempt(self.exam_attempt, self.user) | ||
self.assertFalse(ExamAttempt.objects.filter(id=self.exam_attempt.id).exists()) | ||
|
||
@patch('edx_exams.apps.core.signals.signals.EXAM_ATTEMPT_RESET.send_event') | ||
def test_event_emitted(self, mock_event_send): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be worked into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this one is still separate because a reset doesn't go through the useual 'update_attempt_status' flow |
||
""" | ||
Test that when an exam attempt is reset, the EXAM_ATTEMPT_RESET event is emitted. | ||
""" | ||
reset_exam_attempt(self.exam_attempt, self.user) | ||
|
||
user_data = UserData( | ||
id=self.student_user.id, | ||
is_active=self.student_user.is_active, | ||
pii=UserPersonalData( | ||
username=self.student_user.username, | ||
email=self.student_user.email, | ||
name=self.student_user.full_name | ||
) | ||
) | ||
requesting_user_data = UserData( | ||
id=self.user.id, | ||
is_active=self.user.is_active, | ||
pii=UserPersonalData( | ||
username=self.user.username, | ||
email=self.user.email, | ||
name=self.user.full_name | ||
) | ||
) | ||
course_key = CourseKey.from_string(self.exam.course_id) | ||
usage_key = UsageKey.from_string(self.exam.content_id) | ||
|
||
expected_data = ExamAttemptData( | ||
student_user=user_data, | ||
course_key=course_key, | ||
usage_key=usage_key, | ||
exam_type=self.exam.exam_type, | ||
requesting_user=requesting_user_data, | ||
) | ||
mock_event_send.assert_called_once_with(exam_attempt=expected_data) | ||
|
||
|
||
class TestGetExamByContentId(ExamsAPITestCase): | ||
""" | ||
Tests for the API utility function `get_exam_by_content_id` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a log here, similar to the one we have in edx-proctoring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have a few things to track this that we didn't have when that was written. There's a distinct API request for deletes and we also keep track of changes with the simple history library.
edit: actually I'm just going to add this anyway cuz we do a log on update