Onionr/tests/default-plugin-tests/wot/test_identity_distance.py

44 lines
1.1 KiB
Python
Raw Permalink Normal View History

2022-08-31 05:30:28 +00:00
import os, uuid
from random import randint
from time import sleep
import secrets
TEST_DIR = 'testdata/%s-%s' % (str(uuid.uuid4())[:6], os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
import unittest
import sys
sys.path.append(".")
2022-09-26 20:06:05 +00:00
sys.path.append('static-data/official-plugins/wot/wot')
2022-08-31 05:30:28 +00:00
sys.path.append("src/")
from identity import Identity, get_distance
2022-08-31 05:30:28 +00:00
def generate_graph(iden: Identity, depth, max_neighbors):
2022-08-31 05:30:28 +00:00
c = 0
if depth == 0:
return
for i in range(randint(0, max_neighbors)):
i = Identity(os.urandom(32), "1" + secrets.token_hex(4))
2022-08-31 05:30:28 +00:00
iden.trusted.add(i)
generate_graph(i, depth - 1, max_neighbors)
class IdentityDistanceTest(unittest.TestCase):
def test_distance(self):
iden = Identity(os.urandom(32), "1" + secrets.token_hex(4))
while True:
generate_graph(iden, 10, 5)
try:
iden2 = list(list(iden.trusted)[0].trusted)[0]
except IndexError:
pass
else:
break
2022-08-31 05:30:28 +00:00
self.assertEqual(get_distance(iden, iden2), 2)
2022-08-31 05:30:28 +00:00
unittest.main()