def test_skip_not_active(self): dropped_participation = factories.ParticipationFactory( course=self.course, status=constants.participation_status.dropped) with self.assertRaises(grades.ParticipantNotFound) as cm: grades.find_participant_from_user_attr( self.course, "username", dropped_participation.user.username) expected_error_msg = ("no participant found with username '%s'" % dropped_participation.user.username) self.assertIn(expected_error_msg, str(cm.exception))
def test_not_found_across_course(self): # This ensure course is filtered another_participation = factories.ParticipationFactory( course=factories.CourseFactory(identifier="another-course")) with self.assertRaises(grades.ParticipantNotFound) as cm: grades.find_participant_from_user_attr( self.course, "username", another_participation.user.username) expected_error_msg = ("no participant found with username '%s'" % another_participation.user.username) self.assertIn(expected_error_msg, str(cm.exception))
def test_not_found_by_username_case_sensitive(self): if (self.student_participation.user.institutional_id == self.student_participation.user.institutional_id.upper()): raise unittest.SkipTest( "The created user should have lower cased character to " "make the test meaningful.") upper_user_name = self.student_participation.user.username.upper() with self.assertRaises(grades.ParticipantNotFound) as cm: grades.find_participant_from_user_attr(self.course, "username", upper_user_name) expected_error_msg = ("no participant found with username '%s'" % upper_user_name) self.assertIn(expected_error_msg, str(cm.exception))
def test_multiple_found(self): exist_inst_id = self.student_participation.user.institutional_id another_student_participation = factories.ParticipationFactory( course=self.course, user=factories.UserFactory(institutional_id=exist_inst_id.upper())) with self.assertRaises(grades.ParticipantNotFound) as cm: grades.find_participant_from_user_attr( self.course, "institutional_id", another_student_participation.user.institutional_id) expected_error_msg = ( "more than one participant found with Institutional ID '%s'" % another_student_participation.user.institutional_id) self.assertIn(expected_error_msg, str(cm.exception))
def test_found_iexact_by_inst_id(self): if (self.student_participation.user.institutional_id == self.student_participation.user.institutional_id.upper()): raise unittest.SkipTest( "The created user should have lower cased character to " "make the test meaningful.") self.assertEqual( grades.find_participant_from_user_attr( self.course, "institutional_id", self.student_participation.user.institutional_id.upper()), self.student_participation)
def test_found_exact_by_username(self): self.assertEqual( grades.find_participant_from_user_attr( self.course, "username", self.student_participation.user.username), self.student_participation)
def test_found_strip_inst_id(self): self.assertEqual( grades.find_participant_from_user_attr( self.course, "institutional_id", " %s " % self.student_participation.user.institutional_id), self.student_participation)