'Tests the redirects when visiting course-specific URL with @login_required.
Should vary by course depending on its enrollment_domain'

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

    TARGET_URL = reverse('courseware', args=[self.course.id.to_deprecated_string()])
    noshib_response = self.client.get(TARGET_URL, follow=True, HTTP_ACCEPT='text/html')
    self.assertEqual(noshib_response.redirect_chain[(-1)], ('http://testserver/login?next={url}'.format(url=TARGET_URL), 302))
    self.assertContains(noshib_response, u'Sign    in    or    Register    |    {platform_name}'.format(platform_name=settings.PLATFORM_NAME))
    self.assertEqual(noshib_response.status_code, 200)
    TARGET_URL_SHIB = reverse('courseware', args=[self.shib_course.id.to_deprecated_string()])
    shib_response = self.client.get(**{'path': TARGET_URL_SHIB, 'follow': True, 'REMOTE_USER': self.extauth.external_id, 'Shib-Identity-Provider': 'https://idp.stanford.edu/', 'HTTP_ACCEPT': 'text/html'})
    self.assertEqual(shib_response.redirect_chain[(-3)], ('http://testserver/shib-login/?next={url}'.format(url=TARGET_URL_SHIB), 302))
    self.assertEqual(shib_response.redirect_chain[(-2)], ('http://testserver{url}'.format(url=TARGET_URL_SHIB), 302))
    self.assertEqual(shib_response.status_code, 200)
