def test_target_already_enrolled(self): source = self._create_user(enrolled=self.course) target = self._create_user(enrolled=self.course, create_progress=True) self.assertEqual( _migrate_progress(self.course_id, source.email, target.email), OUTCOME_TARGET_ALREADY_ENROLLED )
def test_source_not_enrolled(self): source = self._create_user() target = self._create_user() self.assertEqual( _migrate_progress(self.course_id, source.email, target.email), OUTCOME_SOURCE_NOT_ENROLLED )
def test_course_not_found(self): source = self._create_user(enrolled=self.course) target = self._create_user() self.assertEqual( _migrate_progress(self.course_id + 'abc', source.email, target.email), OUTCOME_COURSE_NOT_FOUND )
def test_course_invalid_key(self): source = self._create_user(enrolled=self.course) target = self._create_user() self.assertEqual( _migrate_progress('a+b+c', source.email, target.email), OUTCOME_COURSE_KEY_INVALID )
def test_failed_migration(self): source = self._create_user(enrolled=self.course) target = self._create_user() with patch.object(CourseEnrollment, 'save') as mock: mock.side_effect = Exception('Failed to save') self.assertEqual( _migrate_progress(self.course_id, source.email, target.email), OUTCOME_FAILED_MIGRATION )
def test_migrated(self): source = self._create_user(enrolled=self.course) target = self._create_user() self._create_user_progress(source) with patch('openedx.core.djangoapps.user_api.completion.tasks.update_user_gradebook') as update_user_gradebook: outcome = _migrate_progress(self.course_id, source.email, target.email) course_key = str(self.course.id) update_user_gradebook.assert_has_calls([ call(course_key, source.id), call(course_key, target.id) ]) self.assertEqual(outcome, OUTCOME_MIGRATED) # Check that all user's progress transferred to another user assert CourseEnrollment.objects.filter(user=target, course=self.course.id).exists() assert BlockCompletion.user_learning_context_completion_queryset(user=target, context_key=self.course.id).exists() assert StudentItem.objects.filter( course_id=self.course.id, student_id=anonymous_id_for_user(target, self.course.id) ).exists() assert StudentModule.objects.filter(student=target, course_id=self.course.id).exists()
def test_target_not_found(self): source = self._create_user(enrolled=self.course) self.assertEqual( _migrate_progress(self.course_id, source.email, '*****@*****.**'), OUTCOME_TARGET_NOT_FOUND )
def test_source_not_found(self): target = self._create_user() self.assertEqual( _migrate_progress(self.course_id, '*****@*****.**', target.email), OUTCOME_SOURCE_NOT_FOUND )