'Test that requesting wiki URLs redirect properly to or out of classes.
An enrolled in student going from /courses/edX/toy/2012_Fall/progress
to /wiki/some/fake/wiki/page/ will redirect to
/courses/edX/toy/2012_Fall/wiki/some/fake/wiki/page/
An unenrolled student going to /courses/edX/toy/2012_Fall/wiki/some/fake/wiki/page/
will be redirected to /wiki/some/fake/wiki/page/'

@patch.dict('django.conf.settings.FEATURES', {'ALLOW_WIKI_ROOT_ACCESS': True})
def test_wiki_redirect(self):

    self.login(self.student, self.password)
    self.enroll(self.toy)
    referer = reverse('progress', kwargs={'course_id': self.toy.id.to_deprecated_string()})
    destination = reverse('wiki:get', kwargs={'path': 'some/fake/wiki/page/'})
    redirected_to = referer.replace('progress', 'wiki/some/fake/wiki/page/')
    resp = self.client.get(destination, HTTP_REFERER=referer)
    self.assertEqual(resp.status_code, 302)
    self.assertEqual(resp['Location'], ('http://testserver' + redirected_to))
    bad_course_wiki_page = redirected_to.replace(self.toy.location.course, 'bad_course')
    resp = self.client.get(bad_course_wiki_page, HTTP_REFERER=referer)
    self.assertEqual(resp.status_code, 302)
    self.assertEqual(resp['Location'], ('http://testserver' + destination))
