mirror of
https://github.com/onionshare/onionshare.git
synced 2025-08-14 17:15:54 -04:00
Fix CLI tests, and also fix bug related to autostop_sharing that the tests found
This commit is contained in:
parent
0431374ef8
commit
16268b5b3e
8 changed files with 60 additions and 69 deletions
|
@ -36,6 +36,7 @@ from onionshare.common import Common
|
|||
from onionshare import strings
|
||||
from onionshare.web import Web
|
||||
from onionshare.settings import Settings
|
||||
from onionshare.mode_settings import ModeSettings
|
||||
|
||||
DEFAULT_ZW_FILENAME_REGEX = re.compile(r"^onionshare_[a-z2-7]{6}.zip$")
|
||||
RANDOM_STR_REGEX = re.compile(r"^[a-z2-7]+$")
|
||||
|
@ -45,9 +46,9 @@ def web_obj(common_obj, mode, num_files=0):
|
|||
""" Creates a Web object, in either share mode or receive mode, ready for testing """
|
||||
common_obj.settings = Settings(common_obj)
|
||||
strings.load_strings(common_obj)
|
||||
web = Web(common_obj, False, mode)
|
||||
mode_settings = ModeSettings(common_obj)
|
||||
web = Web(common_obj, False, mode_settings, mode)
|
||||
web.generate_password()
|
||||
web.stay_open = True
|
||||
web.running = True
|
||||
|
||||
web.app.testing = True
|
||||
|
@ -56,7 +57,7 @@ def web_obj(common_obj, mode, num_files=0):
|
|||
if mode == "share":
|
||||
# Add files
|
||||
files = []
|
||||
for i in range(num_files):
|
||||
for _ in range(num_files):
|
||||
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
|
||||
tmp_file.write(b"*" * 1024)
|
||||
files.append(tmp_file.name)
|
||||
|
@ -94,9 +95,9 @@ class TestWeb:
|
|||
assert res.status_code == 200
|
||||
assert res.mimetype == "application/zip"
|
||||
|
||||
def test_share_mode_close_after_first_download_on(self, common_obj, temp_file_1024):
|
||||
def test_share_mode_autostop_sharing_on(self, common_obj, temp_file_1024):
|
||||
web = web_obj(common_obj, "share", 3)
|
||||
web.stay_open = False
|
||||
web.settings.set("share", "autostop_sharing", True)
|
||||
|
||||
assert web.running == True
|
||||
|
||||
|
@ -109,11 +110,9 @@ class TestWeb:
|
|||
|
||||
assert web.running == False
|
||||
|
||||
def test_share_mode_close_after_first_download_off(
|
||||
self, common_obj, temp_file_1024
|
||||
):
|
||||
def test_share_mode_autostop_sharing_off(self, common_obj, temp_file_1024):
|
||||
web = web_obj(common_obj, "share", 3)
|
||||
web.stay_open = True
|
||||
web.settings.set("share", "autostop_sharing", False)
|
||||
|
||||
assert web.running == True
|
||||
|
||||
|
@ -147,7 +146,7 @@ class TestWeb:
|
|||
|
||||
def test_public_mode_on(self, common_obj):
|
||||
web = web_obj(common_obj, "receive")
|
||||
common_obj.settings.set("public_mode", True)
|
||||
web.settings.set("general", "public", True)
|
||||
|
||||
with web.app.test_client() as c:
|
||||
# Loading / should work without auth
|
||||
|
@ -157,7 +156,7 @@ class TestWeb:
|
|||
|
||||
def test_public_mode_off(self, common_obj):
|
||||
web = web_obj(common_obj, "receive")
|
||||
common_obj.settings.set("public_mode", False)
|
||||
web.settings.set("general", "public", False)
|
||||
|
||||
with web.app.test_client() as c:
|
||||
# Load / without auth
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue