Beispiel #1
0
 def test_fetch_process_req_filename_from_contentdisposition(self):
     patcher_head = patch('requests.head')
     patcher_get = patch('requests.get')
     patcher_head.start()
     patcher_get.start()
     self.addCleanup(patcher_head.stop)
     self.addCleanup(patcher_get.stop)
     requests.get.return_value.__enter__.return_value.headers = {
         'Content-Disposition': 'filename=cd_test_file.txt'
     }
     (requests.get.return_value.__enter__.return_value.iter_content.
      return_value) = [b'Some test file content...']
     mock_head_resp = MagicMock()
     mock_head_resp.headers = {'Content-Type': 'text/plain'}
     mock_head_resp.status_code = 200
     requests.head.return_value = mock_head_resp
     mock_req = MagicMock()
     mock_req.query_params = {'target': 'http://localhost/test'}
     fv = FetchView()
     result = fv._process_request(mock_req)
     self.assertTrue((type(result) == tuple) and (len(result) == 4),
                     'The return type was not a tuple of the right length!')
     self.assertTrue(
         result[2] == 'cd_test_file.txt',
         ('File name cd_test_file.txt was not correctly extracted from '
          'the request, got [%s]' % result[2]))
Beispiel #2
0
 def test_fetch_process_req_connection_error_get(self):
     patcher_head = patch('requests.head')
     patcher_get = patch('requests.get')
     patcher_head.start()
     patcher_get.start()
     self.addCleanup(patcher_head.stop)
     self.addCleanup(patcher_get.stop)
     mock_head_resp = MagicMock()
     mock_head_resp.headers = {'Content-Type': 'text/plain'}
     mock_head_resp.status_code = 200
     requests.head.return_value = mock_head_resp
     requests.get.side_effect = ConnectionError('test_file')
     mock_req = MagicMock()
     mock_req.query_params = {'target': 'http://localhost/test'}
     fv = FetchView()
     with self.assertRaisesMessage(
             NotFound,
             'Unable to access the requested remote file: test_file'):
         fv._process_request(mock_req)
Beispiel #3
0
"""FilePond server-side URL configuration

Based on the server-side configuration details
provided at: 
https://pqina.nl/filepond/docs/patterns/api/server/#configuration
"""
from django.conf.urls import url
from django_drf_filepond.views import ProcessView, RevertView, LoadView,\
     RestoreView, FetchView

urlpatterns = [
    url(r'^process/$', ProcessView.as_view(), name='process'),
    url(r'^revert/$', RevertView.as_view(), name='revert'),
    url(r'^load/$', LoadView.as_view(), name='load'),
    url(r'^restore/$', RestoreView.as_view(), name='restore'),
    url(r'^fetch/$', FetchView.as_view(), name='fetch')
]