mirror of
https://github.com/onionshare/onionshare.git
synced 2024-12-26 15:59:48 -05:00
Replace .format with python 3.6 f-strings in tests
This commit is contained in:
parent
25b2f389db
commit
098625621c
@ -129,7 +129,7 @@ class GuiBaseTest(object):
|
||||
if type(mode) == ReceiveMode:
|
||||
# Upload a file
|
||||
files = {"file[]": open("/tmp/test.txt", "rb")}
|
||||
url = "http://127.0.0.1:{}/upload".format(self.gui.app.port)
|
||||
url = f"http://127.0.0.1:{self.gui.app.port}/upload"
|
||||
if public_mode:
|
||||
r = requests.post(url, files=files)
|
||||
else:
|
||||
@ -142,7 +142,7 @@ class GuiBaseTest(object):
|
||||
|
||||
if type(mode) == ShareMode:
|
||||
# Download files
|
||||
url = "http://127.0.0.1:{}/download".format(self.gui.app.port)
|
||||
url = f"http://127.0.0.1:{self.gui.app.port}/download"
|
||||
if public_mode:
|
||||
r = requests.get(url)
|
||||
else:
|
||||
@ -201,7 +201,7 @@ class GuiBaseTest(object):
|
||||
def web_server_is_running(self):
|
||||
"""Test that the web server has started"""
|
||||
try:
|
||||
r = requests.get("http://127.0.0.1:{}/".format(self.gui.app.port))
|
||||
r = requests.get(f"http://127.0.0.1:{self.gui.app.port}/")
|
||||
self.assertTrue(True)
|
||||
except requests.exceptions.ConnectionError:
|
||||
self.assertTrue(False)
|
||||
@ -230,15 +230,11 @@ class GuiBaseTest(object):
|
||||
)
|
||||
clipboard = self.gui.qtapp.clipboard()
|
||||
if public_mode:
|
||||
self.assertEqual(
|
||||
clipboard.text(), "http://127.0.0.1:{}".format(self.gui.app.port)
|
||||
)
|
||||
self.assertEqual(clipboard.text(), f"http://127.0.0.1:{self.gui.app.port}")
|
||||
else:
|
||||
self.assertEqual(
|
||||
clipboard.text(),
|
||||
"http://onionshare:{}@127.0.0.1:{}".format(
|
||||
mode.server_status.web.password, self.gui.app.port
|
||||
),
|
||||
f"http://onionshare:{mode.server_status.web.password}@127.0.0.1:{self.gui.app.port}",
|
||||
)
|
||||
|
||||
def server_status_indicator_says_started(self, mode):
|
||||
@ -257,7 +253,7 @@ class GuiBaseTest(object):
|
||||
def web_page(self, mode, string, public_mode):
|
||||
"""Test that the web page contains a string"""
|
||||
|
||||
url = "http://127.0.0.1:{}/".format(self.gui.app.port)
|
||||
url = f"http://127.0.0.1:{self.gui.app.port}/"
|
||||
if public_mode:
|
||||
r = requests.get(url)
|
||||
else:
|
||||
@ -293,7 +289,7 @@ class GuiBaseTest(object):
|
||||
QtTest.QTest.qWait(2000)
|
||||
|
||||
try:
|
||||
r = requests.get("http://127.0.0.1:{}/".format(self.gui.app.port))
|
||||
r = requests.get(f"http://127.0.0.1:{self.gui.app.port}/")
|
||||
self.assertTrue(False)
|
||||
except requests.exceptions.ConnectionError:
|
||||
self.assertTrue(True)
|
||||
|
@ -19,7 +19,7 @@ class GuiReceiveTest(GuiBaseTest):
|
||||
QtTest.QTest.qWait(2000)
|
||||
|
||||
files = {"file[]": open(file_to_upload, "rb")}
|
||||
url = "http://127.0.0.1:{}/upload".format(self.gui.app.port)
|
||||
url = f"http://127.0.0.1:{self.gui.app.port}/upload"
|
||||
if public_mode:
|
||||
r = requests.post(url, files=files)
|
||||
if identical_files_at_once:
|
||||
@ -68,7 +68,7 @@ class GuiReceiveTest(GuiBaseTest):
|
||||
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")}
|
||||
url = "http://127.0.0.1:{}/upload".format(self.gui.app.port)
|
||||
url = f"http://127.0.0.1:{self.gui.app.port}/upload"
|
||||
if public_mode:
|
||||
r = requests.post(url, files=files)
|
||||
else:
|
||||
@ -88,9 +88,9 @@ class GuiReceiveTest(GuiBaseTest):
|
||||
os.chmod("/tmp/OnionShare", mode)
|
||||
|
||||
def try_without_auth_in_non_public_mode(self):
|
||||
r = requests.post("http://127.0.0.1:{}/upload".format(self.gui.app.port))
|
||||
r = requests.post(f"http://127.0.0.1:{self.gui.app.port}/upload")
|
||||
self.assertEqual(r.status_code, 401)
|
||||
r = requests.get("http://127.0.0.1:{}/close".format(self.gui.app.port))
|
||||
r = requests.get(f"http://127.0.0.1:{self.gui.app.port}/close")
|
||||
self.assertEqual(r.status_code, 401)
|
||||
|
||||
# 'Grouped' tests follow from here
|
||||
|
@ -105,7 +105,7 @@ class GuiShareTest(GuiBaseTest):
|
||||
|
||||
def download_share(self, public_mode):
|
||||
"""Test that we can download the share"""
|
||||
url = "http://127.0.0.1:{}/download".format(self.gui.app.port)
|
||||
url = f"http://127.0.0.1:{self.gui.app.port}/download"
|
||||
if public_mode:
|
||||
r = requests.get(url)
|
||||
else:
|
||||
@ -126,8 +126,8 @@ class GuiShareTest(GuiBaseTest):
|
||||
|
||||
def individual_file_is_viewable_or_not(self, public_mode, stay_open):
|
||||
"""Test whether an individual file is viewable (when in stay_open mode) and that it isn't (when not in stay_open mode)"""
|
||||
url = "http://127.0.0.1:{}".format(self.gui.app.port)
|
||||
download_file_url = "http://127.0.0.1:{}/test.txt".format(self.gui.app.port)
|
||||
url = f"http://127.0.0.1:{self.gui.app.port}"
|
||||
download_file_url = f"http://127.0.0.1:{self.gui.app.port}/test.txt"
|
||||
if public_mode:
|
||||
r = requests.get(url)
|
||||
else:
|
||||
@ -175,7 +175,7 @@ class GuiShareTest(GuiBaseTest):
|
||||
|
||||
def hit_401(self, public_mode):
|
||||
"""Test that the server stops after too many 401s, or doesn't when in public_mode"""
|
||||
url = "http://127.0.0.1:{}/".format(self.gui.app.port)
|
||||
url = f"http://127.0.0.1:{self.gui.app.port}/"
|
||||
|
||||
for _ in range(20):
|
||||
password_guess = self.gui.common.build_password()
|
||||
|
@ -67,7 +67,7 @@ class GuiWebsiteTest(GuiShareTest):
|
||||
|
||||
def view_website(self, public_mode):
|
||||
"""Test that we can download the share"""
|
||||
url = "http://127.0.0.1:{}/".format(self.gui.app.port)
|
||||
url = f"http://127.0.0.1:{self.gui.app.port}/"
|
||||
if public_mode:
|
||||
r = requests.get(url)
|
||||
else:
|
||||
@ -83,7 +83,7 @@ class GuiWebsiteTest(GuiShareTest):
|
||||
|
||||
def check_csp_header(self, public_mode, csp_header_disabled):
|
||||
"""Test that the CSP header is present when enabled or vice versa"""
|
||||
url = "http://127.0.0.1:{}/".format(self.gui.app.port)
|
||||
url = f"http://127.0.0.1:{self.gui.app.port}/"
|
||||
if public_mode:
|
||||
r = requests.get(url)
|
||||
else:
|
||||
|
@ -79,28 +79,24 @@ class TorGuiBaseTest(GuiBaseTest):
|
||||
(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)
|
||||
session.proxies["http"] = f"socks5h://{socks_address}:{socks_port}"
|
||||
|
||||
if type(mode) == ReceiveMode:
|
||||
# Upload a file
|
||||
files = {"file[]": open("/tmp/test.txt", "rb")}
|
||||
if not public_mode:
|
||||
path = "http://{}/{}/upload".format(
|
||||
self.gui.app.onion_host, mode.web.password
|
||||
)
|
||||
path = f"http://{self.gui.app.onion_host}/{mode.web.password}/upload"
|
||||
else:
|
||||
path = "http://{}/upload".format(self.gui.app.onion_host)
|
||||
path = f"http://{self.gui.app.onion_host}/upload"
|
||||
response = session.post(path, files=files)
|
||||
QtTest.QTest.qWait(4000)
|
||||
|
||||
if type(mode) == ShareMode:
|
||||
# Download files
|
||||
if public_mode:
|
||||
path = "http://{}/download".format(self.gui.app.onion_host)
|
||||
path = f"http://{self.gui.app.onion_host}/download"
|
||||
else:
|
||||
path = "http://{}/{}/download".format(
|
||||
self.gui.app.onion_host, mode.web.password
|
||||
)
|
||||
path = f"http://{self.gui.app.onion_host}/{mode.web.password}/download"
|
||||
response = session.get(path)
|
||||
QtTest.QTest.qWait(4000)
|
||||
|
||||
@ -124,11 +120,11 @@ class TorGuiBaseTest(GuiBaseTest):
|
||||
s.settimeout(60)
|
||||
s.connect((self.gui.app.onion_host, 80))
|
||||
if not public_mode:
|
||||
path = "/{}".format(mode.server_status.web.password)
|
||||
path = f"/{mode.server_status.web.password}"
|
||||
else:
|
||||
path = "/"
|
||||
http_request = "GET {} HTTP/1.0\r\n".format(path)
|
||||
http_request += "Host: {}\r\n".format(self.gui.app.onion_host)
|
||||
http_request = f"GET {path} HTTP/1.0\r\n"
|
||||
http_request += f"Host: {self.gui.app.onion_host}\r\n"
|
||||
http_request += "\r\n"
|
||||
s.sendall(http_request.encode("utf-8"))
|
||||
with open("/tmp/webpage", "wb") as file_to_write:
|
||||
@ -151,15 +147,11 @@ class TorGuiBaseTest(GuiBaseTest):
|
||||
)
|
||||
clipboard = self.gui.qtapp.clipboard()
|
||||
if public_mode:
|
||||
self.assertEqual(
|
||||
clipboard.text(), "http://{}".format(self.gui.app.onion_host)
|
||||
)
|
||||
self.assertEqual(clipboard.text(), f"http://{self.gui.app.onion_host}")
|
||||
else:
|
||||
self.assertEqual(
|
||||
clipboard.text(),
|
||||
"http://{}/{}".format(
|
||||
self.gui.app.onion_host, mode.server_status.web.password
|
||||
),
|
||||
f"http://{self.gui.app.onion_host}/{mode.server_status.web.password}",
|
||||
)
|
||||
|
||||
# Stealth tests
|
||||
|
@ -10,14 +10,12 @@ class TorGuiReceiveTest(TorGuiBaseTest):
|
||||
(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)
|
||||
session.proxies["http"] = f"socks5h://{socks_address}:{socks_port}"
|
||||
files = {"file[]": open(file_to_upload, "rb")}
|
||||
if not public_mode:
|
||||
path = "http://{}/{}/upload".format(
|
||||
self.gui.app.onion_host, self.gui.receive_mode.web.password
|
||||
)
|
||||
path = f"http://{self.gui.app.onion_host}/{self.gui.receive_mode.web.password}/upload"
|
||||
else:
|
||||
path = "http://{}/upload".format(self.gui.app.onion_host)
|
||||
path = f"http://{self.gui.app.onion_host}/upload"
|
||||
response = session.post(path, files=files)
|
||||
QtTest.QTest.qWait(4000)
|
||||
self.assertTrue(os.path.isfile(expected_file))
|
||||
|
@ -12,15 +12,13 @@ class TorGuiShareTest(TorGuiBaseTest, GuiShareTest):
|
||||
(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)
|
||||
session.proxies["http"] = f"socks5h://{socks_address}:{socks_port}"
|
||||
|
||||
# Download files
|
||||
if public_mode:
|
||||
path = "http://{}/download".format(self.gui.app.onion_host)
|
||||
path = f"http://{self.gui.app.onion_host}/download"
|
||||
else:
|
||||
path = "http://{}/{}/download".format(
|
||||
self.gui.app.onion_host, self.gui.share_mode.web.password
|
||||
)
|
||||
path = f"http://{self.gui.app.onion_host}/{self.gui.share_mode.web.password}/download"
|
||||
response = session.get(path, stream=True)
|
||||
QtTest.QTest.qWait(4000)
|
||||
|
||||
|
@ -166,7 +166,7 @@ class TestWeb:
|
||||
assert res.status_code == 401
|
||||
|
||||
# But static resources should work without auth
|
||||
res = c.get("{}/css/style.css".format(web.static_url_path))
|
||||
res = c.get(f"{web.static_url_path}/css/style.css")
|
||||
res.get_data()
|
||||
assert res.status_code == 200
|
||||
|
||||
@ -186,11 +186,7 @@ class TestZipWriterDefault:
|
||||
@pytest.mark.parametrize(
|
||||
"test_input",
|
||||
(
|
||||
"onionshare_{}.zip".format(
|
||||
"".join(
|
||||
random.choice("abcdefghijklmnopqrstuvwxyz234567") for _ in range(6)
|
||||
)
|
||||
)
|
||||
f"onionshare_{''.join(random.choice('abcdefghijklmnopqrstuvwxyz234567') for _ in range(6))}.zip"
|
||||
for _ in range(50)
|
||||
),
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user