Пример #1
0
 def test_x_send_cannot_read(self, forbidden, access):
     path = "/my/path"
     access.return_value = False
     reply = ContentView.x_send(path)
     access.assert_called_once_with(path, os.R_OK)
     forbidden.assert_called_once_with()
     self.assertEqual(reply, forbidden.return_value)
Пример #2
0
 def test_x_send_mime_type(self, access):
     path = '/my/path.rpm'
     access.return_value = True
     reply = ContentView.x_send(path)
     access.assert_called_once_with(path, os.R_OK)
     self.assertEqual(reply['X-SENDFILE'], path)
     self.assertEqual(reply['Content-Type'], 'application/x-rpm')
Пример #3
0
 def test_x_send_cannot_read(self, forbidden, access):
     path = '/my/path'
     access.return_value = False
     reply = ContentView.x_send(path)
     access.assert_called_once_with(path, os.R_OK)
     forbidden.assert_called_once_with()
     self.assertEqual(reply, forbidden.return_value)
Пример #4
0
 def test_x_send_mime_type(self, access):
     path = "/my/path.rpm"
     access.return_value = True
     reply = ContentView.x_send(path)
     access.assert_called_once_with(path, os.R_OK)
     self.assertEqual(reply["X-SENDFILE"], path)
     self.assertEqual(reply["Content-Type"], "application/x-rpm")
Пример #5
0
 def test_x_send(self, access):
     path = '/my/path'
     access.return_value = True
     reply = ContentView.x_send(path)
     access.assert_called_once_with(path, os.R_OK)
     self.assertEqual(reply['X-SENDFILE'], path)
     self.assertEqual(reply['Content-Type'], 'application/octet-stream')
Пример #6
0
 def test_x_send(self, response, access):
     path = '/my/path'
     response.return_value = {}
     access.return_value = True
     reply = ContentView.x_send(path)
     access.assert_called_once_with(path, os.R_OK)
     response.assert_called_once_with()
     self.assertEqual(response.return_value['X-SENDFILE'], path)
     self.assertEqual(reply, response.return_value)
Пример #7
0
 def test_x_send(self, response, access):
     path = '/my/path'
     response.return_value = {}
     access.return_value = True
     reply = ContentView.x_send(path)
     access.assert_called_once_with(path, os.R_OK)
     response.assert_called_once_with()
     self.assertEqual(response.return_value['X-SENDFILE'], path)
     self.assertEqual(reply, response.return_value)
Пример #8
0
 def test_x_send_mime_type_noencoding(self, access):
     path = '/my/path.xml.gz'
     access.return_value = True
     reply = ContentView.x_send(path)
     access.assert_called_once_with(path, os.R_OK)
     self.assertEqual(reply['X-SENDFILE'], path)
     # If the normal mimetypes module was used, this would be 'text/xml' instead.
     # Most OSes return the 'gzip' version, but some (el6) return 'x-gzip'. Either is fine.
     self.assertTrue(reply['Content-Type'] in ('application/gzip', 'application/x-gzip'))
Пример #9
0
 def test_x_send_mime_type_noencoding(self, access):
     path = '/my/path.xml.gz'
     access.return_value = True
     reply = ContentView.x_send(path)
     access.assert_called_once_with(path, os.R_OK)
     self.assertEqual(reply['X-SENDFILE'], path)
     # If the normal mimetypes module was used, this would be 'text/xml' instead.
     # Most OSes return the 'gzip' version, but some (el6) return 'x-gzip'. Either is fine.
     self.assertTrue(reply['Content-Type'] in ('application/gzip',
                                               'application/x-gzip'))
Пример #10
0
    def test_get_http(self, realpath, allow_access):
        realpath.side_effect = lambda p: '/some/content'
        host = 'localhost'
        path = '/some/content/'
        self.environ['wsgi.url_scheme'] = 'http'

        request = Mock(path_info=path, environ=self.environ)
        request.get_host.return_value = host

        # test
        view = ContentView()
        view.x_send = Mock()
        self.assertRaises(content_views.Http404, view.get, request)
        self.assertEqual(0, allow_access.call_count)
Пример #11
0
    def test_get_http(self, realpath, allow_access):
        realpath.side_effect = lambda p: "/some/content"
        host = "localhost"
        path = "/some/content/"
        self.environ["wsgi.url_scheme"] = "http"

        request = Mock(path_info=path, environ=self.environ)
        request.get_host.return_value = host

        # test
        view = ContentView()
        view.x_send = Mock()
        self.assertRaises(content_views.Http404, view.get, request)
        self.assertEqual(0, allow_access.call_count)