added peerprofiles and filepaths tests
This commit is contained in:
parent
4f6f83f383
commit
376b2cc2d6
9 changed files with 103 additions and 10 deletions
16
tests/test_filepaths.py
Normal file
16
tests/test_filepaths.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
import sys, os
|
||||
sys.path.append(".")
|
||||
sys.path.append("onionr/")
|
||||
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
|
||||
import filepaths
|
||||
from utils import identifyhome
|
||||
|
||||
class TestFilePaths(unittest.TestCase):
|
||||
def test_filepaths_main(self):
|
||||
home = identifyhome.identify_home()
|
||||
self.assertTrue(filepaths.home.startswith(home))
|
||||
|
||||
unittest.main()
|
66
tests/test_peerprofiles.py
Normal file
66
tests/test_peerprofiles.py
Normal file
|
@ -0,0 +1,66 @@
|
|||
import sys, os
|
||||
sys.path.append(".")
|
||||
sys.path.append("onionr/")
|
||||
import unittest, uuid
|
||||
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 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)
|
||||
return base64.b32encode(rand_bytes).decode().lower() + '.onion'
|
||||
|
||||
test_peers = []
|
||||
for x in range(100):
|
||||
p = rand_fake_adder_generator()
|
||||
assert stringvalidators.validate_transport(p)
|
||||
test_peers.append(p)
|
||||
|
||||
class TestPeerProfiles(unittest.TestCase):
|
||||
def test_invalid_init(self):
|
||||
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
|
||||
for x in range(2):
|
||||
s += 1
|
||||
p.addScore(1)
|
||||
self.assertEqual(p.score, s)
|
||||
|
||||
def test_inc_score_with_db(self):
|
||||
p = peerprofiles.PeerProfiles(test_peers.pop())
|
||||
s = 0
|
||||
for x in range(2):
|
||||
p.last_updated['score'] = epoch.get_epoch() - peerprofiles.UPDATE_DELAY
|
||||
s += 1
|
||||
p.addScore(1)
|
||||
self.assertEqual(p.score, keydb.transportinfo.get_address_info(p.address, 'success'))
|
||||
|
||||
def test_inc_score_with_sync_Delay(self):
|
||||
p = peerprofiles.PeerProfiles(test_peers.pop())
|
||||
s = 0
|
||||
for x in range(2):
|
||||
s += 1
|
||||
p.addScore(1)
|
||||
if x == 0:
|
||||
self.assertEqual(p.score, keydb.transportinfo.get_address_info(p.address, 'success'))
|
||||
else:
|
||||
self.assertNotEqual(p.score, keydb.transportinfo.get_address_info(p.address, 'success'))
|
||||
|
||||
unittest.main()
|
Loading…
Add table
Add a link
Reference in a new issue