Пример #1
0
def test_uploader_update_data_dict_cleared():
    """Test that the uploader updates the data when 'clear' is set
    """
    backend = uploader.get_configured_storage()
    up = uploader.AssetUploader(backend, 'group', 'original.png')
    data_dict = {
        'url': 'original.png',
        'clear': '1',
        'file': FileStorage(name='file')
    }
    up.update_data_dict(data_dict, 'url', 'file', 'clear')
    assert data_dict['url'] == ''
Пример #2
0
def test_uploader_update_data_dict_no_upload():
    """Test that the uploader doesn't change the URL if no upload was done
    """
    backend = uploader.get_configured_storage()
    up = uploader.AssetUploader(backend, 'group', 'original.png')
    data_dict = {
        'url': 'original.png',
        'clear': '',
        'file': FileStorage(name='file')
    }
    up.update_data_dict(data_dict, 'url', 'file', 'clear')
    assert data_dict['url'] == 'original.png'
Пример #3
0
def test_uploader_update_data_dict_no_upload_no_previous_file():
    """Test that the uploader updates the data dict properly
    """
    backend = uploader.get_configured_storage()
    up = uploader.AssetUploader(backend, 'group')
    data_dict = {
        'url':
        'foo.png',
        'clear':
        '',
        'file':
        FileStorage(name='file', filename='foo.png', stream=BytesIO(b'hello'))
    }
    up.update_data_dict(data_dict, 'url', 'file', 'clear')
    assert data_dict['url'].startswith('http://localhost:5000/uploads/group/')
    assert data_dict['url'].endswith('-foo.png')
Пример #4
0
def test_uploader_property():
    backend = uploader.get_configured_storage()
    up = uploader.AssetUploader(backend, 'group', 'bar.png')
    data_dict = {
        'url':
        'foo.png',
        'clear':
        '',
        'file':
        FieldStorage(fp=BytesIO(b'hello'),
                     headers={
                         "content-disposition":
                         'form-data; name="file"; filename="foo.png"'
                     })
    }
    up.update_data_dict(data_dict, 'url', 'file', 'clear')
    assert up.filename.endswith('-foo.png')
Пример #5
0
def test_uploader_update_data_dict_existing_file_cgi():
    """Test that the uploader updates the data dict properly when a file already exists

    This test simulates CKAN 2.8 (Pylons / cgi) based upload
    """
    backend = uploader.get_configured_storage()
    up = uploader.AssetUploader(backend, 'group', 'bar.png')
    data_dict = {
        'url':
        'foo.png',
        'clear':
        '',
        'file':
        FieldStorage(fp=BytesIO(b'hello'),
                     headers={
                         "content-disposition":
                         'form-data; name="file"; filename="foo.png"'
                     })
    }
    up.update_data_dict(data_dict, 'url', 'file', 'clear')
    assert data_dict['url'].startswith('http://localhost:5000/uploads/group/')
    assert data_dict['url'].endswith('-foo.png')
Пример #6
0
 def get_uploader(self, upload_to, old_filename):
     return uploader.AssetUploader(
         object_type=upload_to,
         old_filename=old_filename,
         storage=uploader.get_configured_storage())