Merge pull request #876 from micahflee/receiving_nothing

Don't show empty transfers in the receive mode UI
This commit is contained in:
Micah Lee 2019-01-21 17:17:44 -08:00 committed by GitHub
commit 6af9a8a1cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 20 deletions

View File

@ -67,7 +67,7 @@ class ReceiveModeWeb(object):
receive_mode_dir = os.path.join(self.common.settings.get('data_dir'), date_dir, time_dir) receive_mode_dir = os.path.join(self.common.settings.get('data_dir'), date_dir, time_dir)
valid = True valid = True
try: try:
os.makedirs(receive_mode_dir, 0o700) os.makedirs(receive_mode_dir, 0o700, exist_ok=True)
except PermissionError: except PermissionError:
self.web.add_request(self.web.REQUEST_ERROR_DATA_DIR_CANNOT_CREATE, request.path, { self.web.add_request(self.web.REQUEST_ERROR_DATA_DIR_CANNOT_CREATE, request.path, {
"receive_mode_dir": receive_mode_dir "receive_mode_dir": receive_mode_dir
@ -275,13 +275,8 @@ class ReceiveModeRequest(Request):
strings._("receive_mode_upload_starting").format(self.web.common.human_readable_filesize(self.content_length)) strings._("receive_mode_upload_starting").format(self.web.common.human_readable_filesize(self.content_length))
)) ))
# Tell the GUI # Don't tell the GUI that a request has started until we start receiving files
self.web.add_request(self.web.REQUEST_STARTED, self.path, { self.told_gui_about_request = False
'id': self.upload_id,
'content_length': self.content_length
})
self.web.receive_mode.uploads_in_progress.append(self.upload_id)
self.previous_file = None self.previous_file = None
@ -291,6 +286,16 @@ class ReceiveModeRequest(Request):
writable stream. writable stream.
""" """
if self.upload_request: if self.upload_request:
if not self.told_gui_about_request:
# Tell the GUI about the request
self.web.add_request(self.web.REQUEST_STARTED, self.path, {
'id': self.upload_id,
'content_length': self.content_length
})
self.web.receive_mode.uploads_in_progress.append(self.upload_id)
self.told_gui_about_request = True
self.progress[filename] = { self.progress[filename] = {
'uploaded_bytes': 0, 'uploaded_bytes': 0,
'complete': False 'complete': False
@ -304,12 +309,13 @@ class ReceiveModeRequest(Request):
""" """
super(ReceiveModeRequest, self).close() super(ReceiveModeRequest, self).close()
try: try:
upload_id = self.upload_id if self.told_gui_about_request:
# Inform the GUI that the upload has finished upload_id = self.upload_id
self.web.add_request(self.web.REQUEST_UPLOAD_FINISHED, self.path, { # Inform the GUI that the upload has finished
'id': upload_id self.web.add_request(self.web.REQUEST_UPLOAD_FINISHED, self.path, {
}) 'id': upload_id
self.web.receive_mode.uploads_in_progress.remove(upload_id) })
self.web.receive_mode.uploads_in_progress.remove(upload_id)
except AttributeError: except AttributeError:
pass pass
@ -331,10 +337,11 @@ class ReceiveModeRequest(Request):
), end='') ), end='')
# Update the GUI on the upload progress # Update the GUI on the upload progress
self.web.add_request(self.web.REQUEST_PROGRESS, self.path, { if self.told_gui_about_request:
'id': self.upload_id, self.web.add_request(self.web.REQUEST_PROGRESS, self.path, {
'progress': self.progress 'id': self.upload_id,
}) 'progress': self.progress
})
def file_close_func(self, filename): def file_close_func(self, filename):
""" """

View File

@ -355,13 +355,15 @@ class HistoryItemList(QtWidgets.QScrollArea):
""" """
Update an item. Override this method. Update an item. Override this method.
""" """
self.items[id].update(data) if id in self.items:
self.items[id].update(data)
def cancel(self, id): def cancel(self, id):
""" """
Cancel an item. Override this method. Cancel an item. Override this method.
""" """
self.items[id].cancel() if id in self.items:
self.items[id].cancel()
def reset(self): def reset(self):
""" """

View File

@ -52,6 +52,28 @@ class GuiReceiveTest(GuiBaseTest):
response = requests.get('http://127.0.0.1:{}/close'.format(self.gui.app.port)) response = requests.get('http://127.0.0.1:{}/close'.format(self.gui.app.port))
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
def uploading_zero_files_shouldnt_change_ui(self, mode, public_mode):
'''If you submit the receive mode form without selecting any files, the UI shouldn't get updated'''
if not public_mode:
path = 'http://127.0.0.1:{}/{}/upload'.format(self.gui.app.port, self.gui.receive_mode.web.slug)
else:
path = 'http://127.0.0.1:{}/upload'.format(self.gui.app.port)
# What were the counts before submitting the form?
before_in_progress_count = mode.history.in_progress_count
before_completed_count = mode.history.completed_count
before_number_of_history_items = len(mode.history.item_list.items)
# Click submit without including any files a few times
response = requests.post(path, files={})
response = requests.post(path, files={})
response = requests.post(path, files={})
# The counts shouldn't change
self.assertEqual(mode.history.in_progress_count, before_in_progress_count)
self.assertEqual(mode.history.completed_count, before_completed_count)
self.assertEqual(len(mode.history.item_list.items), before_number_of_history_items)
def run_receive_mode_sender_closed_tests(self, public_mode): def run_receive_mode_sender_closed_tests(self, public_mode):
'''Test that the share can be stopped by the sender in receive mode''' '''Test that the share can be stopped by the sender in receive mode'''
if not public_mode: if not public_mode:
@ -97,6 +119,7 @@ class GuiReceiveTest(GuiBaseTest):
self.counter_incremented(self.gui.receive_mode, 3) self.counter_incremented(self.gui.receive_mode, 3)
self.upload_file(public_mode, '/tmp/testdir/test', 'test') self.upload_file(public_mode, '/tmp/testdir/test', 'test')
self.counter_incremented(self.gui.receive_mode, 4) self.counter_incremented(self.gui.receive_mode, 4)
self.uploading_zero_files_shouldnt_change_ui(self.gui.receive_mode, public_mode)
self.history_indicator(self.gui.receive_mode, public_mode) self.history_indicator(self.gui.receive_mode, public_mode)
self.server_is_stopped(self.gui.receive_mode, False) self.server_is_stopped(self.gui.receive_mode, False)
self.web_server_is_stopped() self.web_server_is_stopped()