'Tests the enrollment of a list of students who are not users yet.
It tests 2 different views that use slightly different parameters,
but that perform the same task.'

@ddt.data(('ccx_invite', True, 1, 'student-ids', ('enrollment-button', 'Enroll'), 'nobody@nowhere.com'), ('ccx_invite', False, 0, 'student-ids', ('enrollment-button', 'Enroll'), 'nobody@nowhere.com'), ('ccx_invite', True, 0, 'student-ids', ('enrollment-button', 'Enroll'), 'nobody'), ('ccx_invite', False, 0, 'student-ids', ('enrollment-button', 'Enroll'), 'nobody'), ('ccx_manage_student', True, 0, 'student-id', ('student-action', 'add'), 'dummy_student_id'), ('ccx_manage_student', False, 0, 'student-id', ('student-action', 'add'), 'dummy_student_id'), ('ccx_manage_student', True, 1, 'student-id', ('student-action', 'add'), 'xyz@gmail.com'), ('ccx_manage_student', False, 0, 'student-id', ('student-action', 'add'), 'xyz@gmail.com'))
@ddt.unpack
def test_enroll_non_user_student(self, view_name, send_email, outbox_count, student_form_input_name, button_tuple, identifier):

    self.make_coach()
    ccx = self.make_ccx()
    course_key = CCXLocator.from_course_locator(self.course.id, ccx.id)
    outbox = self.get_outbox()
    self.assertEqual(outbox, [])
    url = reverse(view_name, kwargs={'course_id': course_key})
    data = {button_tuple[0]: button_tuple[1], student_form_input_name: u','.join([identifier])}
    if send_email:
        data['email-students'] = 'Notify-students-by-email'
    response = self.client.post(url, data=data, follow=True)
    self.assertEqual(response.status_code, 200)
    self.assertEqual(len(response.redirect_chain), 1)
    self.assertIn(302, response.redirect_chain[0])
    self.assertEqual(len(outbox), outbox_count)
    if ((view_name == 'ccx_manage_student') and (not is_email(identifier))):
        self.assertContains(response, 'Could    not    find    a    user    with    name    or    email    ', status_code=200)
    if is_email(identifier):
        if send_email:
            self.assertIn(identifier, outbox[0].recipients())
        self.assertTrue(CourseEnrollmentAllowed.objects.filter(course_id=course_key, email=identifier).exists())
    else:
        self.assertFalse(CourseEnrollmentAllowed.objects.filter(course_id=course_key, email=identifier).exists())
