+ now require runtime tests to generate unittest result that is somewhat fresh

+ add runtime test for webpass needing to be set
This commit is contained in:
Kevin Froman 2020-01-29 22:56:47 -06:00
parent 6624a80c68
commit 8a3f84097a
12 changed files with 115 additions and 17 deletions

1
tests/runtime-result.txt Normal file
View file

@ -0,0 +1 @@
1580360010

View file

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import sys, os, time, math
sys.path.append(".")
sys.path.append("src/")
import unittest, uuid
import json
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
SUCCESS_FILE = os.path.dirname(__file__) + '/runtime-result.txt'
from utils import identifyhome, createdirs
from onionrsetup import setup_config
createdirs.create_dirs()
setup_config()
class TestRuntimeFile(unittest.TestCase):
def test_runtime_result(self):
self.assertTrue(os.path.exists(SUCCESS_FILE))
with open(SUCCESS_FILE, 'r') as result_file:
self.assertLess(math.floor(time.time()) - int(result_file.read()), 600)
unittest.main()

View file

@ -0,0 +1,42 @@
#!/usr/bin/env python3
import sys, os
import threading
from gevent import sleep
import requests
sys.path.append(".")
sys.path.append("src/")
import unittest, uuid
import json
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
from utils import identifyhome, createdirs
from onionrsetup import setup_config
createdirs.create_dirs()
setup_config()
from onionrcommands import daemonlaunch
from onionrutils import localcommand, getclientapiserver
import config
class TestWebpass(unittest.TestCase):
def test_needs_webpass(self):
config.set('general.use_bootstrap', False)
threading.Thread(target=daemonlaunch.start).start()
while localcommand.local_command('/ping') != 'pong!':
sleep(1)
self.assertNotEqual(
requests.get('http://' + getclientapiserver.get_client_API_server() + '/ping'),
'pong!'
)
while True:
try:
daemonlaunch.kill_daemon()
except KeyError:
sleep(1)
unittest.main()