summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMicah Lee <micah@micahflee.com>2018-10-26 15:08:55 -0700
committerMicah Lee <micah@micahflee.com>2018-10-26 15:08:55 -0700
commitf5e0e9dd62c920f6f5b7c98636d8ee156d3ed1ce (patch)
tree26bf744869ff965782fe60acae3a36871075bbe1
parent65b4afeba34c23aa3fe856e4fadbe7f1d20c8a2d (diff)
downloadonionshare-f5e0e9dd62c920f6f5b7c98636d8ee156d3ed1ce.tar.gz
onionshare-f5e0e9dd62c920f6f5b7c98636d8ee156d3ed1ce.zip
Fix tests so they recognize the new receive mode location
-rw-r--r--onionshare/web/receive_mode.py2
-rw-r--r--tests/GuiReceiveTest.py31
2 files changed, 24 insertions, 9 deletions
diff --git a/onionshare/web/receive_mode.py b/onionshare/web/receive_mode.py
index edaf8bbc..3149029f 100644
--- a/onionshare/web/receive_mode.py
+++ b/onionshare/web/receive_mode.py
@@ -61,7 +61,7 @@ class ReceiveModeWeb(object):
# Make sure the receive mode dir exists
now = datetime.now()
date_dir = now.strftime("%Y-%m-%d")
- time_dir = now.strftime("%H.%M:%S")
+ time_dir = now.strftime("%H.%M.%S")
receive_mode_dir = os.path.join(self.common.settings.get('downloads_dir'), date_dir, time_dir)
valid = True
try:
diff --git a/tests/GuiReceiveTest.py b/tests/GuiReceiveTest.py
index a659a79f..eaed8343 100644
--- a/tests/GuiReceiveTest.py
+++ b/tests/GuiReceiveTest.py
@@ -1,10 +1,11 @@
import os
import requests
+from datetime import datetime, timedelta
from PyQt5 import QtCore, QtTest
from .GuiBaseTest import GuiBaseTest
class GuiReceiveTest(GuiBaseTest):
- def upload_file(self, public_mode, file_to_upload, expected_file):
+ def upload_file(self, public_mode, file_to_upload, expected_basename):
'''Test that we can upload the file'''
files = {'file[]': open(file_to_upload, 'rb')}
if not public_mode:
@@ -13,9 +14,23 @@ class GuiReceiveTest(GuiBaseTest):
path = 'http://127.0.0.1:{}/upload'.format(self.gui.app.port)
response = requests.post(path, files=files)
QtTest.QTest.qWait(2000)
- self.assertTrue(os.path.isfile(expected_file))
- def upload_file_should_fail(self, public_mode, expected_file):
+ # Make sure the file is within the last 10 seconds worth of filenames
+ exists = False
+ now = datetime.now()
+ for i in range(10):
+ date_dir = now.strftime("%Y-%m-%d")
+ time_dir = now.strftime("%H.%M.%S")
+ receive_mode_dir = os.path.join(self.gui.common.settings.get('downloads_dir'), date_dir, time_dir)
+ expected_filename = os.path.join(receive_mode_dir, expected_basename)
+ if os.path.exists(expected_filename):
+ exists = True
+ break
+ now = now - timedelta(seconds=1)
+
+ self.assertTrue(exists)
+
+ def upload_file_should_fail(self, public_mode):
'''Test that we can't upload the file when permissions are wrong, and expected content is shown'''
files = {'file[]': open('/tmp/test.txt', 'rb')}
if not public_mode:
@@ -73,14 +88,14 @@ class GuiReceiveTest(GuiBaseTest):
self.run_all_receive_mode_setup_tests(public_mode)
if not public_mode:
self.try_public_paths_in_non_public_mode()
- self.upload_file(public_mode, '/tmp/test.txt', '/tmp/OnionShare/test.txt')
+ self.upload_file(public_mode, '/tmp/test.txt', 'test.txt')
self.history_widgets_present(self.gui.receive_mode)
self.counter_incremented(self.gui.receive_mode, 1)
- self.upload_file(public_mode, '/tmp/test.txt', '/tmp/OnionShare/test-2.txt')
+ self.upload_file(public_mode, '/tmp/test.txt', 'test.txt')
self.counter_incremented(self.gui.receive_mode, 2)
- self.upload_file(public_mode, '/tmp/testdir/test', '/tmp/OnionShare/test')
+ self.upload_file(public_mode, '/tmp/testdir/test', 'test')
self.counter_incremented(self.gui.receive_mode, 3)
- self.upload_file(public_mode, '/tmp/testdir/test', '/tmp/OnionShare/test-2')
+ self.upload_file(public_mode, '/tmp/testdir/test', 'test')
self.counter_incremented(self.gui.receive_mode, 4)
self.history_indicator(self.gui.receive_mode, public_mode)
self.server_is_stopped(self.gui.receive_mode, False)
@@ -94,7 +109,7 @@ class GuiReceiveTest(GuiBaseTest):
'''Attempt to upload (unwritable) files in receive mode and stop the share'''
self.run_all_receive_mode_setup_tests(public_mode)
self.upload_dir_permissions(0o400)
- self.upload_file_should_fail(public_mode, '/tmp/OnionShare/test.txt')
+ self.upload_file_should_fail(public_mode)
self.server_is_stopped(self.gui.receive_mode, True)
self.web_server_is_stopped()
self.server_status_indicator_says_closed(self.gui.receive_mode, False)