mirror of
https://github.com/onionshare/onionshare.git
synced 2024-12-28 16:59:35 -05:00
On a folder name collision, make sure we update the self.receive_mode_dir attribute after creating a unique folder with a suffix. Adjust Receive Mode tests to test for this
This commit is contained in:
parent
3af05dcc20
commit
04fd65de11
@ -297,6 +297,7 @@ class ReceiveModeRequest(Request):
|
|||||||
new_receive_mode_dir = '{}-{}'.format(self.receive_mode_dir, i)
|
new_receive_mode_dir = '{}-{}'.format(self.receive_mode_dir, i)
|
||||||
try:
|
try:
|
||||||
os.makedirs(new_receive_mode_dir, 0o700, exist_ok=False)
|
os.makedirs(new_receive_mode_dir, 0o700, exist_ok=False)
|
||||||
|
self.receive_mode_dir = new_receive_mode_dir
|
||||||
break
|
break
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
@ -5,7 +5,7 @@ from PyQt5 import QtCore, QtTest
|
|||||||
from .GuiBaseTest import GuiBaseTest
|
from .GuiBaseTest import GuiBaseTest
|
||||||
|
|
||||||
class GuiReceiveTest(GuiBaseTest):
|
class GuiReceiveTest(GuiBaseTest):
|
||||||
def upload_file(self, public_mode, file_to_upload, expected_basename):
|
def upload_file(self, public_mode, file_to_upload, expected_basename, identical_files_at_once=False):
|
||||||
'''Test that we can upload the file'''
|
'''Test that we can upload the file'''
|
||||||
files = {'file[]': open(file_to_upload, 'rb')}
|
files = {'file[]': open(file_to_upload, 'rb')}
|
||||||
if not public_mode:
|
if not public_mode:
|
||||||
@ -13,6 +13,9 @@ class GuiReceiveTest(GuiBaseTest):
|
|||||||
else:
|
else:
|
||||||
path = 'http://127.0.0.1:{}/upload'.format(self.gui.app.port)
|
path = 'http://127.0.0.1:{}/upload'.format(self.gui.app.port)
|
||||||
response = requests.post(path, files=files)
|
response = requests.post(path, files=files)
|
||||||
|
if identical_files_at_once:
|
||||||
|
# Send a duplicate upload to test for collisions
|
||||||
|
response = requests.post(path, files=files)
|
||||||
QtTest.QTest.qWait(2000)
|
QtTest.QTest.qWait(2000)
|
||||||
|
|
||||||
# Make sure the file is within the last 10 seconds worth of filenames
|
# Make sure the file is within the last 10 seconds worth of filenames
|
||||||
@ -20,6 +23,9 @@ class GuiReceiveTest(GuiBaseTest):
|
|||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
date_dir = now.strftime("%Y-%m-%d")
|
date_dir = now.strftime("%Y-%m-%d")
|
||||||
|
if identical_files_at_once:
|
||||||
|
time_dir = now.strftime("%H.%M.%S-1")
|
||||||
|
else:
|
||||||
time_dir = now.strftime("%H.%M.%S")
|
time_dir = now.strftime("%H.%M.%S")
|
||||||
receive_mode_dir = os.path.join(self.gui.common.settings.get('data_dir'), date_dir, time_dir)
|
receive_mode_dir = os.path.join(self.gui.common.settings.get('data_dir'), date_dir, time_dir)
|
||||||
expected_filename = os.path.join(receive_mode_dir, expected_basename)
|
expected_filename = os.path.join(receive_mode_dir, expected_basename)
|
||||||
@ -119,6 +125,9 @@ 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)
|
||||||
|
# Test uploading the same file twice at the same time, and make sure no collisions
|
||||||
|
self.upload_file(public_mode, '/tmp/test.txt', 'test.txt', True)
|
||||||
|
self.counter_incremented(self.gui.receive_mode, 6)
|
||||||
self.uploading_zero_files_shouldnt_change_ui(self.gui.receive_mode, public_mode)
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user