def test_get_or_create_verification_checkpoint_for_not_existing_values(self): # Retrieving a checkpoint that doesn't yet exist will create it location = u'i4x://edX/DemoX/edx-reverification-block/invalid_location' checkpoint = VerificationCheckpoint.get_or_create_verification_checkpoint(self.course.id, location) self.assertIsNot(checkpoint, None) self.assertEqual(checkpoint.course_id, self.course.id) self.assertEqual(checkpoint.checkpoint_location, location)
def test_get_or_create_verification_checkpoint_for_not_existing_values( self): # Retrieving a checkpoint that doesn't yet exist will create it location = u'i4x://edX/DemoX/edx-reverification-block/invalid_location' checkpoint = VerificationCheckpoint.get_or_create_verification_checkpoint( self.course.id, location) self.assertIsNot(checkpoint, None) self.assertEqual(checkpoint.course_id, self.course.id) self.assertEqual(checkpoint.checkpoint_location, location)
def start_verification(self, course_id, related_assessment_location): """Create re-verification link against a verification checkpoint. Args: course_id(str): A string of course id related_assessment_location(str): Location of Reverification XBlock Returns: Re-verification link """ course_key = CourseKey.from_string(course_id) # Get-or-create the verification checkpoint VerificationCheckpoint.get_or_create_verification_checkpoint( course_key, related_assessment_location) re_verification_link = reverse( 'verify_student_incourse_reverify', args=(unicode(course_key), unicode(related_assessment_location))) return re_verification_link
def test_get_or_create_verification_checkpoint(self, checkpoint): """ Test that a reverification checkpoint is created properly. """ checkpoint_location = u'i4x://{org}/{course}/edx-reverification-block/{checkpoint}'.format( org=self.course.id.org, course=self.course.id.course, checkpoint=checkpoint) # create the 'VerificationCheckpoint' checkpoint verification_checkpoint = VerificationCheckpoint.objects.create( course_id=self.course.id, checkpoint_location=checkpoint_location) self.assertEqual( VerificationCheckpoint.get_or_create_verification_checkpoint( self.course.id, checkpoint_location), verification_checkpoint)
def start_verification(self, course_id, related_assessment_location): """Create re-verification link against a verification checkpoint. Args: course_id(str): A string of course id related_assessment_location(str): Location of Reverification XBlock Returns: Re-verification link """ course_key = CourseKey.from_string(course_id) # Get-or-create the verification checkpoint VerificationCheckpoint.get_or_create_verification_checkpoint(course_key, related_assessment_location) re_verification_link = reverse( 'verify_student_incourse_reverify', args=( unicode(course_key), unicode(related_assessment_location) ) ) return re_verification_link
def test_get_or_create_verification_checkpoint(self, checkpoint): """ Test that a reverification checkpoint is created properly. """ checkpoint_location = u'i4x://{org}/{course}/edx-reverification-block/{checkpoint}'.format( org=self.course.id.org, course=self.course.id.course, checkpoint=checkpoint ) # create the 'VerificationCheckpoint' checkpoint verification_checkpoint = VerificationCheckpoint.objects.create( course_id=self.course.id, checkpoint_location=checkpoint_location ) self.assertEqual( VerificationCheckpoint.get_or_create_verification_checkpoint(self.course.id, checkpoint_location), verification_checkpoint )
def test_get_or_create_integrity_error(self): # Create the checkpoint VerificationCheckpoint.objects.create( course_id=self.course.id, checkpoint_location=self.checkpoint_midterm, ) # Simulate that the get-or-create operation raises an IntegrityError. # This can happen when two processes both try to get-or-create at the same time # when the database is set to REPEATABLE READ. # To avoid IntegrityError situations when calling this method, set the view to # use a READ COMMITTED transaction instead. with patch.object(VerificationCheckpoint.objects, "get_or_create") as mock_get_or_create: mock_get_or_create.side_effect = IntegrityError with self.assertRaises(IntegrityError): _ = VerificationCheckpoint.get_or_create_verification_checkpoint( self.course.id, self.checkpoint_midterm)
def test_get_or_create_integrity_error(self): # Create the checkpoint VerificationCheckpoint.objects.create( course_id=self.course.id, checkpoint_location=self.checkpoint_midterm, ) # Simulate that the get-or-create operation raises an IntegrityError. # This can happen when two processes both try to get-or-create at the same time # when the database is set to REPEATABLE READ. # To avoid IntegrityError situations when calling this method, set the view to # use a READ COMMITTED transaction instead. with patch.object(VerificationCheckpoint.objects, "get_or_create") as mock_get_or_create: mock_get_or_create.side_effect = IntegrityError with self.assertRaises(IntegrityError): _ = VerificationCheckpoint.get_or_create_verification_checkpoint( self.course.id, self.checkpoint_midterm )