def test_clean_success(self): data = { "user": self.test_user.pk, "course": self.course2.pk, "status": constants.participation_status.active, "enroll_time": now(), "time_factor": 1 } form = admin.ParticipationForm(data=data) self.assertTrue(form.is_valid(), form.errors)
def test_clean_roles_course_matched(self): course1_role = factories.ParticipationRoleFactory(course=self.course1) data = { "user": self.test_user.pk, "course": self.course1.pk, "status": constants.participation_status.active, "enroll_time": now(), "time_factor": 1, "roles": [course1_role] } form = admin.ParticipationForm(data=data) self.assertTrue(form.is_valid())
def test_clean_roles_course_not_match(self): course1_role = factories.ParticipationRoleFactory(course=self.course1) data = { "user": self.test_user.pk, "course": self.course2.pk, "status": constants.participation_status.active, "enroll_time": now(), "time_factor": 1, "roles": [course1_role] } form = admin.ParticipationForm(data=data) self.assertFalse(form.is_valid()) expected_error_msg = "Role must belong to same course as participation." self.assertIn(expected_error_msg, str(form.errors))