mirror of
https://github.com/onionshare/onionshare.git
synced 2025-02-27 09:51:17 -05:00
initial commit of onionshare_test.py
mods
This commit is contained in:
parent
50652aa74b
commit
29f15fb9a5
@ -16,3 +16,68 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from onionshare import onionshare
|
||||||
|
|
||||||
|
|
||||||
|
class MyOnion:
|
||||||
|
def __init__(self, stealth=False):
|
||||||
|
self.auth_string = 'TestHidServAuth'
|
||||||
|
self.stealth = stealth
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def start_onion_service(_):
|
||||||
|
return 'test_service_id.onion'
|
||||||
|
|
||||||
|
|
||||||
|
# pytest > 2.9 only needs pytest.fixture
|
||||||
|
@pytest.fixture()
|
||||||
|
def onionshare_obj():
|
||||||
|
return onionshare.OnionShare(MyOnion())
|
||||||
|
|
||||||
|
|
||||||
|
class TestOnionShare:
|
||||||
|
def test_init(self, onionshare_obj):
|
||||||
|
# test onion? own fixture?
|
||||||
|
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
|
||||||
|
assert onionshare_obj.stay_open 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()
|
||||||
|
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):
|
||||||
|
onionshare_obj.local_only = True
|
||||||
|
onionshare_obj.start_onion_service()
|
||||||
|
assert onionshare_obj.onion_host == '127.0.0.1:{}'.format(
|
||||||
|
onionshare_obj.port)
|
||||||
|
|
||||||
|
def test_cleanup(self, onionshare_obj):
|
||||||
|
# create temporary files/directories and then remove them
|
||||||
|
# use helper function from other file (use conftest.py???)
|
||||||
|
onionshare_obj.cleanup_filenames = [] # add temporary filenames & dirs
|
||||||
|
# remove the files & dirs
|
||||||
|
assert onionshare_obj.cleanup_filenames == []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user