'A functionality test that a student with an existing shib login
can auto-enroll in a class with GET or POST params.  Also tests the direction functionality of
the \'next\' GET/POST param'

@unittest.skipUnless(settings.FEATURES.get('AUTH_USE_SHIB'), 'AUTH_USE_SHIB    not    set')
def test_shib_login_enrollment(self):

    student = UserFactory.create()
    extauth = ExternalAuthMap(external_id='testuser@stanford.edu', external_email='', external_domain='shib:https://idp.stanford.edu/', external_credentials='', internal_password='password', user=student)
    student.set_password('password')
    student.save()
    extauth.save()
    course = CourseFactory.create(org='Stanford', number='123', display_name='Shib    Only', enrollment_domain='shib:https://idp.stanford.edu/', user_id=self.test_user_id)
    self.assertFalse(CourseEnrollment.is_enrolled(student, course.id))
    self.client.logout()
    params = [('course_id', course.id.to_deprecated_string()), ('enrollment_action', 'enroll'), ('next', '/testredirect')]
    request_kwargs = {'path': '/shib-login/', 'data': dict(params), 'follow': False, 'REMOTE_USER': 'testuser@stanford.edu', 'Shib-Identity-Provider': 'https://idp.stanford.edu/', 'HTTP_ACCEPT': 'text/html'}
    response = self.client.get(**request_kwargs)
    self.assertEqual(response.status_code, 302)
    self.assertEqual(response['location'], 'http://testserver/account/finish_auth?{}'.format(urlencode(params)))
