'Test that going from a course page to a wiki page when not enrolled
redirects a user to the course about page'

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

    self.login(self.instructor, self.password)
    self.enroll(self.toy)
    self.create_course_page(self.toy)
    self.logout()
    self.login(self.student, self.password)
    course_wiki_page = reverse('wiki:get', kwargs={'path': (self.toy.wiki_slug + '/')})
    referer = reverse('courseware', kwargs={'course_id': self.toy.id.to_deprecated_string()})
    resp = self.client.get(course_wiki_page, follow=False, HTTP_REFERER=referer)
    self.assertEqual(resp.status_code, 302)
    resp = self.client.get(course_wiki_page, follow=True, HTTP_REFERER=referer)
    (target_url, __) = resp.redirect_chain[(-1)]
    self.assertTrue(target_url.endswith(reverse('about_course', args=[self.toy.id.to_deprecated_string()])))
