def test_private_files_not_found(self): request = self.request(self.private_url, user=self.eric) with self.assertRaises(Http404) as exc: _serve_symlink_docs( request, project=self.private, filename="/en/latest/usage.html", privacy_level="private" ) self.assertTrue("private_web_root" in exc.exception.message) self.assertTrue("public_web_root" not in exc.exception.message)
def test_private_files_not_found(self): request = self.request(self.private_url, user=self.eric) with self.assertRaises(Http404) as exc: _serve_symlink_docs(request, project=self.private, filename='/en/latest/usage.html', privacy_level='private') self.assertTrue('private_web_root' in str(exc.exception)) self.assertTrue('public_web_root' not in str(exc.exception))
def test_public_python_media_serving(self): with mock.patch("readthedocs.core.views.serve.serve") as serve_mock: with mock.patch("readthedocs.core.views.serve.os.path.exists", return_value=True): request = self.request(self.public_url, user=self.eric) _serve_symlink_docs( request, project=self.public, filename="/en/latest/usage.html", privacy_level="public" ) serve_mock.assert_called_with( request, "en/latest/usage.html", settings.SITE_ROOT + "/public_web_root/public" )
def test_private_python_media_serving(self): with mock.patch('readthedocs.core.views.serve.serve') as serve_mock: with mock.patch('readthedocs.core.views.serve.os.path.exists', return_value=True): request = self.request(self.private_url, user=self.eric) _serve_symlink_docs(request, project=self.private, filename='/en/latest/usage.html', privacy_level='private') serve_mock.assert_called_with( request, 'en/latest/usage.html', settings.SITE_ROOT + '/private_web_root/private', )
def test_public_nginx_serving(self): with mock.patch("readthedocs.core.views.serve.os.path.exists", return_value=True): request = self.request(self.public_url, user=self.eric) r = _serve_symlink_docs( request, project=self.public, filename="/en/latest/usage.html", privacy_level="public" ) self.assertEqual(r.status_code, 200) self.assertEqual(r._headers["x-accel-redirect"][1], "/public_web_root/public/en/latest/usage.html")
def test_private_nginx_serving_unicode_filename(self): with mock.patch('readthedocs.core.views.serve.os.path.exists', return_value=True): request = self.request(self.private_url, user=self.eric) r = _serve_symlink_docs(request, project=self.private, filename='/en/latest/úñíčódé.html', privacy_level='private') self.assertEqual(r.status_code, 200) self.assertEqual( r._headers['x-accel-redirect'][1], '/private_web_root/private/en/latest/%C3%BA%C3%B1%C3%AD%C4%8D%C3%B3d%C3%A9.html', )
def test_public_nginx_serving(self): with mock.patch('readthedocs.core.views.serve.os.path.exists', return_value=True): request = self.request(self.public_url, user=self.eric) r = _serve_symlink_docs(request, project=self.public, filename='/en/latest/usage.html', privacy_level='public') self.assertEqual(r.status_code, 200) self.assertEqual( r._headers['x-accel-redirect'][1], '/public_web_root/public/en/latest/usage.html', )