2018-10-11 20:28:47 -04:00
|
|
|
import os
|
|
|
|
import requests
|
|
|
|
from PyQt5 import QtTest
|
2018-10-12 03:53:03 -04:00
|
|
|
from .TorGuiBaseTest import TorGuiBaseTest
|
|
|
|
|
|
|
|
class TorGuiReceiveTest(TorGuiBaseTest):
|
2018-10-11 20:28:47 -04:00
|
|
|
|
2018-10-17 00:21:04 -04:00
|
|
|
def upload_file(self, public_mode, file_to_upload, expected_file):
|
2018-10-11 20:28:47 -04:00
|
|
|
'''Test that we can upload the file'''
|
2018-10-12 03:53:03 -04:00
|
|
|
(socks_address, socks_port) = self.gui.app.onion.get_tor_socks_port()
|
|
|
|
session = requests.session()
|
|
|
|
session.proxies = {}
|
|
|
|
session.proxies['http'] = 'socks5h://{}:{}'.format(socks_address, socks_port)
|
2018-10-17 00:21:04 -04:00
|
|
|
files = {'file[]': open(file_to_upload, 'rb')}
|
2018-10-11 20:28:47 -04:00
|
|
|
if not public_mode:
|
2018-10-12 03:53:03 -04:00
|
|
|
path = 'http://{}/{}/upload'.format(self.gui.app.onion_host, self.gui.receive_mode.web.slug)
|
2018-10-11 20:28:47 -04:00
|
|
|
else:
|
2018-10-12 03:53:03 -04:00
|
|
|
path = 'http://{}/upload'.format(self.gui.app.onion_host)
|
|
|
|
response = session.post(path, files=files)
|
|
|
|
QtTest.QTest.qWait(4000)
|
2018-10-11 20:28:47 -04:00
|
|
|
self.assertTrue(os.path.isfile(expected_file))
|
|
|
|
|
2018-10-15 22:01:44 -04:00
|
|
|
|
|
|
|
# 'Grouped' tests follow from here
|
|
|
|
|
2018-10-11 20:28:47 -04:00
|
|
|
def run_all_receive_mode_tests(self, public_mode, receive_allow_receiver_shutdown):
|
2018-10-15 22:01:44 -04:00
|
|
|
'''Run a full suite of tests in Receive mode'''
|
2018-10-11 20:28:47 -04:00
|
|
|
self.click_mode(self.gui.receive_mode)
|
|
|
|
self.history_is_not_visible(self.gui.receive_mode)
|
|
|
|
self.click_toggle_history(self.gui.receive_mode)
|
|
|
|
self.history_is_visible(self.gui.receive_mode)
|
|
|
|
self.server_working_on_start_button_pressed(self.gui.receive_mode)
|
|
|
|
self.server_status_indicator_says_starting(self.gui.receive_mode)
|
|
|
|
self.settings_button_is_hidden()
|
2018-10-15 22:01:44 -04:00
|
|
|
self.server_is_started(self.gui.receive_mode, startup_time=45000)
|
|
|
|
self.web_server_is_running()
|
2018-10-12 03:53:03 -04:00
|
|
|
self.have_an_onion_service()
|
2018-10-11 20:28:47 -04:00
|
|
|
self.have_a_slug(self.gui.receive_mode, public_mode)
|
|
|
|
self.url_description_shown(self.gui.receive_mode)
|
2018-10-15 22:01:44 -04:00
|
|
|
self.have_copy_url_button(self.gui.receive_mode, public_mode)
|
2018-10-11 20:28:47 -04:00
|
|
|
self.server_status_indicator_says_started(self.gui.receive_mode)
|
|
|
|
self.web_page(self.gui.receive_mode, 'Select the files you want to send, then click', public_mode)
|
2018-10-17 00:21:04 -04:00
|
|
|
self.upload_file(public_mode, '/tmp/test.txt', '/tmp/OnionShare/test.txt')
|
2018-10-11 20:28:47 -04:00
|
|
|
self.history_widgets_present(self.gui.receive_mode)
|
|
|
|
self.counter_incremented(self.gui.receive_mode, 1)
|
2018-10-17 00:21:04 -04:00
|
|
|
self.upload_file(public_mode, '/tmp/test.txt', '/tmp/OnionShare/test-2.txt')
|
2018-10-11 20:28:47 -04:00
|
|
|
self.counter_incremented(self.gui.receive_mode, 2)
|
2018-10-17 00:21:04 -04:00
|
|
|
self.upload_file(public_mode, '/tmp/testdir/test', '/tmp/OnionShare/test')
|
|
|
|
self.counter_incremented(self.gui.receive_mode, 3)
|
|
|
|
self.upload_file(public_mode, '/tmp/testdir/test', '/tmp/OnionShare/test-2')
|
|
|
|
self.counter_incremented(self.gui.receive_mode, 4)
|
2018-10-11 20:28:47 -04:00
|
|
|
self.history_indicator(self.gui.receive_mode, public_mode)
|
|
|
|
self.server_is_stopped(self.gui.receive_mode, False)
|
2018-10-15 22:01:44 -04:00
|
|
|
self.web_server_is_stopped()
|
2018-10-11 20:28:47 -04:00
|
|
|
self.server_status_indicator_says_closed(self.gui.receive_mode, False)
|
|
|
|
self.server_working_on_start_button_pressed(self.gui.receive_mode)
|
2018-10-15 22:01:44 -04:00
|
|
|
self.server_is_started(self.gui.receive_mode, startup_time=45000)
|
2018-10-11 20:28:47 -04:00
|
|
|
self.history_indicator(self.gui.receive_mode, public_mode)
|
|
|
|
|