'Enrolls a list of students up to the enrollment limit.
This test is specific to one of the enrollment views: the reason is because
the view used in this test can perform bulk enrollments.'

def test_ccx_invite_enroll_up_to_limit(self):

    self.make_coach()
    ccx = self.make_ccx(max_students_allowed=2)
    ccx_course_key = CCXLocator.from_course_locator(self.course.id, ccx.id)
    staff = self.make_staff()
    instructor = self.make_instructor()
    students = ([instructor, staff, self.coach] + [UserFactory.create(is_staff=False) for _ in range(3)])
    url = reverse('ccx_invite', kwargs={'course_id': ccx_course_key})
    data = {'enrollment-button': 'Enroll', 'student-ids': u','.join([student.email for student in students])}
    response = self.client.post(url, data=data, follow=True)
    self.assertEqual(response.status_code, 200)
    self.assertTrue(CourseEnrollment.objects.filter(course_id=ccx_course_key, user=instructor).exists())
    self.assertTrue(CourseEnrollment.objects.filter(course_id=ccx_course_key, user=staff).exists())
    self.assertTrue(CourseEnrollment.objects.filter(course_id=ccx_course_key, user=self.coach).exists())
    self.assertTrue(CourseEnrollment.objects.filter(course_id=ccx_course_key, user=students[3]).exists())
    self.assertTrue(CourseEnrollment.objects.filter(course_id=ccx_course_key, user=students[4]).exists())
    self.assertFalse(CourseEnrollment.objects.filter(course_id=ccx_course_key, user=students[5]).exists())
