summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMicah Lee <micah@micahflee.com>2019-11-02 17:01:47 -0700
committerMicah Lee <micah@micahflee.com>2019-11-02 17:01:47 -0700
commit87918c5d89f26bce515879895ed0a4ae736dbd2a (patch)
treed700cc583b6afb626cf822ab01feaceb924f338a /tests
parent598db21dcdea4b98c4a4e5216ff2d80d7cbd4b26 (diff)
downloadonionshare-87918c5d89f26bce515879895ed0a4ae736dbd2a.tar.gz
onionshare-87918c5d89f26bce515879895ed0a4ae736dbd2a.zip
Fix CLI tests, and also fix bug related to autostop_sharing that the tests found
Diffstat (limited to 'tests')
-rw-r--r--tests/test_onionshare.py35
-rw-r--r--tests/test_onionshare_web.py21
2 files changed, 22 insertions, 34 deletions
diff --git a/tests/test_onionshare.py b/tests/test_onionshare.py
index 64b16b1f..0addf6d5 100644
--- a/tests/test_onionshare.py
+++ b/tests/test_onionshare.py
@@ -23,13 +23,13 @@ import pytest
from onionshare import OnionShare
from onionshare.common import Common
+from onionshare.mode_settings import ModeSettings
class MyOnion:
- def __init__(self, stealth=False):
+ def __init__(self):
self.auth_string = "TestHidServAuth"
self.private_key = ""
- self.stealth = stealth
self.scheduled_key = None
@staticmethod
@@ -43,38 +43,27 @@ def onionshare_obj():
return OnionShare(common, MyOnion())
+@pytest.fixture
+def mode_settings_obj():
+ common = Common()
+ return ModeSettings(common)
+
+
class TestOnionShare:
def test_init(self, onionshare_obj):
assert onionshare_obj.hidserv_dir is None
assert onionshare_obj.onion_host is None
- assert onionshare_obj.stealth is None
assert onionshare_obj.cleanup_filenames == []
assert onionshare_obj.local_only is False
- def test_set_stealth_true(self, onionshare_obj):
- onionshare_obj.set_stealth(True)
- assert onionshare_obj.stealth is True
- assert onionshare_obj.onion.stealth is True
-
- def test_set_stealth_false(self, onionshare_obj):
- onionshare_obj.set_stealth(False)
- assert onionshare_obj.stealth is False
- assert onionshare_obj.onion.stealth is False
-
- def test_start_onion_service(self, onionshare_obj):
- onionshare_obj.set_stealth(False)
- onionshare_obj.start_onion_service()
+ def test_start_onion_service(self, onionshare_obj, mode_settings_obj):
+ onionshare_obj.start_onion_service(mode_settings_obj)
assert 17600 <= onionshare_obj.port <= 17650
assert onionshare_obj.onion_host == "test_service_id.onion"
- def test_start_onion_service_stealth(self, onionshare_obj):
- onionshare_obj.set_stealth(True)
- onionshare_obj.start_onion_service()
- assert onionshare_obj.auth_string == "TestHidServAuth"
-
- def test_start_onion_service_local_only(self, onionshare_obj):
+ def test_start_onion_service_local_only(self, onionshare_obj, mode_settings_obj):
onionshare_obj.local_only = True
- onionshare_obj.start_onion_service()
+ onionshare_obj.start_onion_service(mode_settings_obj)
assert onionshare_obj.onion_host == "127.0.0.1:{}".format(onionshare_obj.port)
def test_cleanup(self, onionshare_obj, temp_dir_1024, temp_file_1024):
diff --git a/tests/test_onionshare_web.py b/tests/test_onionshare_web.py
index c3a0807c..2ce2f758 100644
--- a/tests/test_onionshare_web.py
+++ b/tests/test_onionshare_web.py
@@ -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