Browse Source

fix tests

master
Kevin Froman 2 years ago
parent
commit
adba4be099
18 changed files with 78 additions and 36 deletions
  1. +2
    -2
      scripts/disable-dev-config.py
  2. +3
    -4
      static-data/default_config.json
  3. +1
    -1
      tests/runtime-result.txt
  4. +10
    -6
      tests/test_database_actions.py
  5. +5
    -3
      tests/test_default_config_json.py
  6. +4
    -2
      tests/test_keymanager.py
  7. +6
    -3
      tests/test_networkmerger.py
  8. +6
    -2
      tests/test_onionr_threads.py
  9. +5
    -2
      tests/test_onionrusers.py
  10. +6
    -4
      tests/test_peerprofiles.py
  11. +1
    -1
      tests/test_runtime_result.py
  12. +4
    -1
      tests/test_setupkvvars.py
  13. +4
    -2
      tests/test_storagecounter.py
  14. +4
    -2
      tests/test_timeinsert.py
  15. +4
    -0
      tests/test_upload_session.py
  16. +4
    -0
      tests/test_vanity.py
  17. +5
    -1
      tests/test_waitforsetvars.py
  18. +4
    -0
      tests/test_zfill.py

+ 2
- 2
scripts/disable-dev-config.py View File

@ -18,8 +18,8 @@ conf['general']['display_header'] = True
conf['general']['security_level'] = 0
conf['general']['use_bootstrap_list'] = True
conf['onboarding']['done'] = False
conf['general']['minimum_block_pow'] = 5
conf['general']['minimum_send_pow'] = 5
conf['general']['minimum_block_pow'] = 6
conf['general']['minimum_send_pow'] = 6
conf['log']['file']['remove_on_exit'] = True
conf['transports']['lan'] = True
conf['transports']['tor'] = True


+ 3
- 4
static-data/default_config.json View File

@ -14,8 +14,8 @@
"hide_created_blocks": true,
"insert_deniable_blocks": true,
"max_block_age": 2678400,
"minimum_block_pow": 5,
"minimum_send_pow": 5,
"minimum_block_pow": 6,
"minimum_send_pow": 6,
"public_key": "",
"random_bind_ip": true,
"security_level": 0,
@ -45,8 +45,7 @@
"minimum_score": -100
},
"plugins": {
"disabled": [
],
"disabled": [],
"enabled": []
},
"statistics": {


+ 1
- 1
tests/runtime-result.txt View File

@ -1 +1 @@
1603867091
1606002757

+ 10
- 6
tests/test_database_actions.py View File

@ -6,12 +6,16 @@ import unittest, uuid, sqlite3
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
from urllib.request import pathname2url
from coredb import keydb
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from urllib.request import pathname2url
from coredb import keydb
class OnionrTests(unittest.TestCase):
def test_address_add(self):
testAddresses = ['facebookcorewwwi.onion', '56kmnycrvepfarolhnx6t2dvmldfeyg7jdymwgjb7jjzg47u2lqw2sad.onion', '5bvb5ncnfr4dlsfriwczpzcvo65kn7fnnlnt2ln7qvhzna2xaldq.b32.i2p']
for address in testAddresses:
@ -19,7 +23,7 @@ class OnionrTests(unittest.TestCase):
dbAddresses = keydb.listkeys.list_adders()
for address in testAddresses:
self.assertIn(address, dbAddresses)
invalidAddresses = [None, '', ' ', '\t', '\n', ' test ', 24, 'fake.onion', 'fake.b32.i2p']
for address in invalidAddresses:
try:
@ -28,8 +32,8 @@ class OnionrTests(unittest.TestCase):
pass
dbAddresses = keydb.listkeys.list_adders()
for address in invalidAddresses:
self.assertNotIn(address, dbAddresses)
self.assertNotIn(address, dbAddresses)
def test_address_info(self):
adder = 'nytimes3xbfgragh.onion'
keydb.addkeys.add_address(adder)


+ 5
- 3
tests/test_default_config_json.py View File

@ -5,10 +5,12 @@ import unittest, uuid, json
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
import onionrblocks
from utils import createdirs
from utils import readstatic
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from utils import readstatic
import onionrblocks
class OnionrConfig(unittest.TestCase):
def test_default_file(self):
json.loads(readstatic.read_static('default_config.json'))
@ -45,7 +47,7 @@ class OnionrConfig(unittest.TestCase):
self.assertEqual(conf['peers']['max_connect'], 1000)
self.assertEqual(conf['peers']['max_stored_peers'], 10000000)
self.assertEqual(conf['peers']['minimum_score'], -100)
self.assertEqual(conf['plugins']['disabled'], ['chat'])
self.assertEqual(conf['plugins']['disabled'], [])
self.assertEqual(conf['plugins']['enabled'], [])
self.assertEqual(conf['timers']['getBlocks'], 10)
self.assertEqual(conf['timers']['lookupBlocks'], 25)


+ 4
- 2
tests/test_keymanager.py View File

@ -8,10 +8,12 @@ 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 createdirs
createdirs.create_dirs()
from coredb import keydb
import onionrsetup as setup, keymanager, filepaths
from onionrutils import stringvalidators
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
setup.setup_config()
pub_key = keymanager.KeyManager().getPubkeyList()[0]
class KeyManagerTest(unittest.TestCase):
@ -35,5 +37,5 @@ class KeyManagerTest(unittest.TestCase):
manager.removeKey(new_key)
with open(filepaths.keys_file, 'r') as keyfile:
self.assertNotIn(new_key, keyfile.read())
unittest.main()

+ 6
- 3
tests/test_networkmerger.py View File

@ -7,11 +7,14 @@ import unittest, uuid
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 createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from utils import networkmerger
from coredb import keydb
import onionrsetup as setup
from utils import createdirs
createdirs.create_dirs()
setup.setup_config()
class NetworkMergerTest(unittest.TestCase):
def test_valid_merge(self):
@ -21,7 +24,7 @@ class NetworkMergerTest(unittest.TestCase):
self.assertIn('mporbyyjhmz2c62shctbi3ngrslne5lpcyav6uzhxok45iblodhgjoad.onion', added)
self.assertNotIn('inwalidkcorewwi.onion', added)
self.assertIn('facebookcorewwwi.onion', added)
def test_invalid_mergeself(self):
adders = 'facebookc0rewwi.onion,sdfsdfsdf.onion, ssdf324, null, \n'
networkmerger.mergeAdders(adders)


+ 6
- 2
tests/test_onionr_threads.py View File

@ -8,12 +8,16 @@ from time import sleep
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 createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from utils import networkmerger
from coredb import keydb
import onionrsetup as setup
from utils import createdirs
from onionrthreads import add_onionr_thread
createdirs.create_dirs()
setup.setup_config()
class OnionrThreadsTests(unittest.TestCase):


+ 5
- 2
tests/test_onionrusers.py View File

@ -7,14 +7,17 @@ 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 createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
import onionrexceptions
from onionrusers import onionrusers
from onionrusers import contactmanager
import onionrcrypto as crypto
from coredb import keydb
from utils import identifyhome, createdirs
createdirs.create_dirs()
from utils import identifyhome
class OnionrUserTests(unittest.TestCase):
'''
Tests both the onionrusers class and the contactmanager (which inherits it)


+ 6
- 4
tests/test_peerprofiles.py View File

@ -7,13 +7,15 @@ import base64
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 createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from onionrpeers import peerprofiles
import onionrexceptions
from coredb import keydb
from utils import createdirs
from onionrutils import stringvalidators, epoch
TEST_PEER = '3n5wclq4w4pfkcfmjcpqrjluctpm2tzt7etfblavf42cntv6hrerkzyb.onion'
createdirs.create_dirs()
def rand_fake_adder_generator():
rand_bytes = os.urandom(35)
@ -30,11 +32,11 @@ class TestPeerProfiles(unittest.TestCase):
self.assertRaises(onionrexceptions.InvalidAddress, peerprofiles.PeerProfiles, "invalid")
def test_valid_init(self):
peerprofiles.PeerProfiles(test_peers.pop())
def test_load_score(self):
p = peerprofiles.PeerProfiles(test_peers.pop())
self.assertEqual(p.score, 0)
def test_inc_score(self):
p = peerprofiles.PeerProfiles(test_peers.pop())
s = 0


+ 1
- 1
tests/test_runtime_result.py View File

@ -19,7 +19,7 @@ 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()), 1800)
self.assertLess(math.floor(time.time()) - int(result_file.read()), 3800)
unittest.main()

+ 4
- 1
tests/test_setupkvvars.py View File

@ -12,11 +12,14 @@ import setupkvvars
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 createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from utils import networkmerger
from coredb import keydb
import onionrsetup as setup
from utils import createdirs
createdirs.create_dirs()
setup.setup_config()
class SetupKVVarsTest(unittest.TestCase):


+ 4
- 2
tests/test_storagecounter.py View File

@ -6,11 +6,13 @@ from time import sleep
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
os.environ["ONIONR_HOME"] = TEST_DIR
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
import config
import logger
from utils import createdirs
import onionrsetup as setup
from utils import createdirs
import onionrblocks
import filepaths
import onionrexceptions


+ 4
- 2
tests/test_timeinsert.py View File

@ -6,12 +6,14 @@ import unittest, uuid
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 createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from onionrblocks import time_insert
from onionrblocks import onionrblockapi
from onionrsetup import setup_config, setup_default_plugins
from utils import createdirs
createdirs.create_dirs()
setup_config()
setup_default_plugins()


+ 4
- 0
tests/test_upload_session.py View File

@ -7,6 +7,10 @@ TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
import hashlib
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from communicatorutils import uploadblocks
def hash_generator():


+ 4
- 0
tests/test_vanity.py View File

@ -6,6 +6,10 @@ TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
import unittest
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
import vanityonionr
import niceware


+ 5
- 1
tests/test_waitforsetvars.py View File

@ -5,6 +5,10 @@ import unittest, uuid, time, threading
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
os.environ["ONIONR_HOME"] = TEST_DIR
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from etc import waitforsetvar
def set_test_var_delay(obj, delay=0):
@ -23,7 +27,7 @@ class TestWaitForSetVar(unittest.TestCase):
threading.Thread(target=set_test_var_delay, args=[test_object, -1]).start()
waitforsetvar.wait_for_set_var(test_object, 'test_var')
self.assertTrue(test_object.test_var)
def test_zero_wait(self):
test_object = lambda: None
threading.Thread(target=set_test_var_delay, args=[test_object, 0]).start()


+ 4
- 0
tests/test_zfill.py View File

@ -5,6 +5,10 @@ print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
sys.path.append(".")
sys.path.append("src/")
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from utils import reconstructhash


Loading…
Cancel
Save