'Create CCX. Follow redirect to coach dashboard, confirm we see
the coach dashboard for the new CCX.'

def test_create_ccx(self, ccx_name='New    CCX'):

    self.make_coach()
    url = reverse('create_ccx', kwargs={'course_id': unicode(self.course.id)})
    response = self.client.post(url, {'name': ccx_name})
    self.assertEqual(response.status_code, 302)
    url = response.get('location')
    response = self.client.get(url)
    self.assertEqual(response.status_code, 200)
    path = urlparse.urlparse(url).path
    resolver = resolve(path)
    ccx_key = resolver.kwargs['course_id']
    course_key = CourseKey.from_string(ccx_key)
    self.assertTrue(CourseEnrollment.is_enrolled(self.coach, course_key))
    self.assertTrue(re.search('id="ccx-schedule"', response.content))
    ccx = CustomCourseForEdX.objects.get()
    course_enrollments = get_override_for_ccx(ccx, self.course, 'max_student_enrollments_allowed')
    self.assertEqual(course_enrollments, settings.CCX_MAX_STUDENTS_ALLOWED)
    role = CourseStaffRole(course_key)
    self.assertTrue(role.has_user(self.coach))
    list_staff_master_course = list_with_level(self.course, 'staff')
    list_instructor_master_course = list_with_level(self.course, 'instructor')
    self.assertTrue(are_permissions_roles_seeded(course_key))
    self.assertTrue(has_forum_access(self.coach.username, course_key, FORUM_ROLE_ADMINISTRATOR))
    with ccx_course(course_key) as course_ccx:
        list_staff_ccx_course = list_with_level(course_ccx, 'staff')
        self.assertEqual((len(list_staff_master_course) + 1), len(list_staff_ccx_course))
        self.assertIn(list_staff_master_course[0].email, [ccx_staff.email for ccx_staff in list_staff_ccx_course])
        self.assertIn(self.coach, list_staff_ccx_course)
        list_instructor_ccx_course = list_with_level(course_ccx, 'instructor')
        self.assertEqual(len(list_instructor_ccx_course), len(list_instructor_master_course))
        self.assertEqual(list_instructor_ccx_course[0].email, list_instructor_master_course[0].email)
