Skip to content

Commit

Permalink
Merge pull request #463 from OpenDataServices/426-files-directories
Browse files Browse the repository at this point in the history
[#426] Directories not files should be created in media dir
  • Loading branch information
Bjwebb committed Jul 21, 2016
2 parents 3af41be + 696904d commit d2fde40
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cove/input/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def download(self):
file_extension = possible_extension

file_name = r.url.split('/')[-1].split('?')[0][:100]
if file_name == '':
file_name = 'file'
if file_extension:
if not file_name.endswith(file_extension):
file_name = file_name + '.' + file_extension
Expand Down
15 changes: 15 additions & 0 deletions cove/input/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import pytest
import cove.input.views as v
from cove.input.models import SuppliedData
Expand Down Expand Up @@ -73,3 +74,17 @@ def test_extension_from_content_disposition(rf, httpserver):
supplied_datas = SuppliedData.objects.all()
assert len(supplied_datas) == 1
assert supplied_datas[0].original_file.name.endswith('.csv')


@pytest.mark.django_db
def test_directory_for_empty_filename(rf):
'''
Check that URLs ending in / correctly create a directory, to test against
regressions of https://github.com/OpenDataServices/cove/issues/426
'''
v.input(fake_cove_middleware(rf.post('/', {
'source_url': 'http://example.org/'
})))
supplied_datas = SuppliedData.objects.all()
assert len(supplied_datas) == 1
assert os.path.isdir(supplied_datas[0].upload_dir())

0 comments on commit d2fde40

Please sign in to comment.