'Assert that in a course with max student limit set to 1, we can enroll staff and instructor along with
student. To make sure course full check excludes staff and instructors.'

def test_enrollment_limit(self):

    self.assertEqual(self.course_limited.max_student_enrollments_allowed, 1)
    user1 = UserFactory.create(username='tester1', email='tester1@e.com', password='test')
    user2 = UserFactory.create(username='tester2', email='tester2@e.com', password='test')
    staff = UserFactory.create(username='staff', email='staff@e.com', password='test')
    role = CourseStaffRole(self.course_limited.id)
    role.add_users(staff)
    instructor = UserFactory.create(username='instructor', email='instructor@e.com', password='test')
    role = CourseInstructorRole(self.course_limited.id)
    role.add_users(instructor)
    CourseEnrollment.enroll(staff, self.course_limited.id, check_access=True)
    CourseEnrollment.enroll(instructor, self.course_limited.id, check_access=True)
    self.assertTrue(CourseEnrollment.objects.filter(course_id=self.course_limited.id, user=staff).exists())
    self.assertTrue(CourseEnrollment.objects.filter(course_id=self.course_limited.id, user=instructor).exists())
    CourseEnrollment.enroll(user1, self.course_limited.id, check_access=True)
    self.assertTrue(CourseEnrollment.objects.filter(course_id=self.course_limited.id, user=user1).exists())
    with self.assertRaises(CourseFullError):
        CourseEnrollment.enroll(user2, self.course_limited.id, check_access=True)
    self.assertFalse(CourseEnrollment.objects.filter(course_id=self.course_limited.id, user=user2).exists())
