Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable upload of different sound files with the same filename #1806

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions accounts/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ def test_handle_uploaded_file_html(self):
self.assertEqual(resp.status_code, 200)
self.assertEqual(os.path.exists(settings.UPLOADS_PATH + '/%i/%s' % (user.id, filename)), False)

@override_uploads_path_with_temp_directory
@mock.patch('general.tasks.process_before_description.delay')
def test_handle_uploaded_duplicate_filenames_html(self, patched_method):
user = User.objects.create_user("testuser", password="testpass")
self.client.force_login(user)

filename = "file.wav"
d_filename = "file(1).wav"
f = SimpleUploadedFile(filename, b"file_content")
f1 = SimpleUploadedFile(filename, b"file_content_1")
resp = self.client.post("/home/upload/html/", {'file': [f, f1]})
self.assertEqual(resp.status_code, 200)
self.assertEqual(os.path.exists(settings.UPLOADS_PATH + '/%i/%s' % (user.id, filename)), True)
self.assertEqual(os.path.exists(settings.UPLOADS_PATH + '/%i/%s' % (user.id, d_filename)), True)

@override_uploads_path_with_temp_directory
def test_select_uploaded_files_to_describe(self):
# Create audio files
Expand Down
15 changes: 15 additions & 0 deletions accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,21 @@ def upload(request, no_flash=False):
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
submitted_files = request.FILES.getlist('files')
if not submitted_files:
#this allows upload_tests to work, requests use the dict key in singular
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm, this comment is a bit strange :S Could this be because in line 73 of test_upload.py you set "file" in singular?

submitted_files = request.FILES.getlist('file')
duplicated_filenames = list()
for file_ in submitted_files:
#check for duplicated names and add an identifier, otherwise, different files with the same
#name will be overwritten in the description queue
if file_.name in duplicated_filenames:
name_counter = duplicated_filenames.count(file_.name)
duplicated_filenames.append(file_.name)
name, extension = os.path.splitext(file_.name)
file_.name = "%s(%d)%s" % (name, name_counter, extension)
else:
duplicated_filenames.append(file_.name)

if handle_uploaded_file(request.user.id, file_):
uploaded_file = file_
successes += 1
Expand All @@ -1303,6 +1317,7 @@ def upload(request, no_flash=False):
'all_file_extensions': settings.ALLOWED_AUDIOFILE_EXTENSIONS,
'uploads_enabled': settings.UPLOAD_AND_DESCRIPTION_ENABLED
}
#print(tvars)
return render(request, 'accounts/upload.html', tvars)


Expand Down
6 changes: 3 additions & 3 deletions monitor/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_monitor_queries_stats_ajax_error(self, mock_get):
resp = self.client.get(reverse('monitor-queries-stats-ajax'))

self.assertEqual(resp.status_code, 500)
mock_get.assert_called_with('http://graylog/graylog/api/search/universal/relative/terms', auth=mock.ANY, params=mock.ANY)
mock_get.assert_called_with('http://graylog/api/search/universal/relative/terms', auth=mock.ANY, params=mock.ANY)

@override_settings(GRAYLOG_DOMAIN='http://graylog')
@mock.patch('requests.get')
Expand All @@ -29,7 +29,7 @@ def test_monitor_queries_stats_ajax_bad_data(self, mock_get):
resp = self.client.get(reverse('monitor-queries-stats-ajax'))

self.assertEqual(resp.status_code, 500)
mock_get.assert_called_with('http://graylog/graylog/api/search/universal/relative/terms', auth=mock.ANY, params=mock.ANY)
mock_get.assert_called_with('http://graylog/api/search/universal/relative/terms', auth=mock.ANY, params=mock.ANY)

@override_settings(GRAYLOG_DOMAIN='http://graylog')
@mock.patch('requests.get')
Expand All @@ -43,4 +43,4 @@ def test_monitor_queries_stats_ajax_ok(self, mock_get):

self.assertEqual(resp.status_code, 200)
self.assertJSONEqual(resp.content, {'response': 'ok'})
mock_get.assert_called_with('http://graylog/graylog/api/search/universal/relative/terms', auth=mock.ANY, params=mock.ANY)
mock_get.assert_called_with('http://graylog/api/search/universal/relative/terms', auth=mock.ANY, params=mock.ANY)