Ejemplo n.º 1
0
    def test_admin_model_form_create(self):
        """
        Test CourseEnrollmentAdminForm creation.
        """
        self.assertEqual(CourseEnrollment.objects.count(), 0)

        form = CourseEnrollmentForm({
            'user': self.user.id,
            'course': six.text_type(self.course.id),
            'is_active': True,
            'mode': 'audit',
        })
        self.assertTrue(form.is_valid())
        enrollment = form.save()
        self.assertEqual(CourseEnrollment.objects.count(), 1)
        self.assertEqual(CourseEnrollment.objects.first(), enrollment)
Ejemplo n.º 2
0
 def test_admin_model_form_update(self):
     """
     Test CourseEnrollmentAdminForm update.
     """
     enrollment = CourseEnrollment.get_or_create_enrollment(
         self.user, self.course.id)
     count = CourseEnrollment.objects.count()
     form = CourseEnrollmentForm(
         {
             'user': self.user.id,
             'course': six.text_type(self.course.id),
             'is_active': False,
             'mode': 'audit'
         },
         instance=enrollment)
     self.assertTrue(form.is_valid())
     course_enrollment = form.save()
     self.assertEqual(count, CourseEnrollment.objects.count())
     self.assertFalse(course_enrollment.is_active)
     self.assertEqual(enrollment.id, course_enrollment.id)