onionr/tests/test_database_actions.py

45 lines
1.7 KiB
Python
Raw Permalink Normal View History

2019-02-28 03:02:44 +00:00
#!/usr/bin/env python3
import sys, os
sys.path.append(".")
2019-11-21 09:26:23 +00:00
sys.path.append("src/")
2019-02-28 03:02:44 +00:00
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
2019-07-25 16:14:13 +00:00
from utils import createdirs
createdirs.create_dirs()
2020-11-22 00:43:59 +00:00
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
from urllib.request import pathname2url
from coredb import keydb
2019-02-28 03:02:44 +00:00
class OnionrTests(unittest.TestCase):
2020-11-22 00:43:59 +00:00
2019-02-28 03:02:44 +00:00
def test_address_add(self):
testAddresses = ['facebookcorewwwi.onion', '56kmnycrvepfarolhnx6t2dvmldfeyg7jdymwgjb7jjzg47u2lqw2sad.onion', '5bvb5ncnfr4dlsfriwczpzcvo65kn7fnnlnt2ln7qvhzna2xaldq.b32.i2p']
for address in testAddresses:
2019-07-25 16:14:13 +00:00
keydb.addkeys.add_address(address)
dbAddresses = keydb.listkeys.list_adders()
2019-02-28 03:02:44 +00:00
for address in testAddresses:
self.assertIn(address, dbAddresses)
2020-11-22 00:43:59 +00:00
2019-02-28 03:02:44 +00:00
invalidAddresses = [None, '', ' ', '\t', '\n', ' test ', 24, 'fake.onion', 'fake.b32.i2p']
for address in invalidAddresses:
try:
2019-07-25 16:14:13 +00:00
keydb.addkeys.add_address(address)
2019-02-28 03:02:44 +00:00
except TypeError:
pass
2019-07-25 16:14:13 +00:00
dbAddresses = keydb.listkeys.list_adders()
2019-02-28 03:02:44 +00:00
for address in invalidAddresses:
2020-11-22 00:43:59 +00:00
self.assertNotIn(address, dbAddresses)
2019-02-28 03:02:44 +00:00
def test_address_info(self):
adder = 'nytimes3xbfgragh.onion'
2019-07-25 16:14:13 +00:00
keydb.addkeys.add_address(adder)
self.assertNotEqual(keydb.transportinfo.get_address_info(adder, 'success'), 1000)
keydb.transportinfo.set_address_info(adder, 'success', 1000)
self.assertEqual(keydb.transportinfo.get_address_info(adder, 'success'), 1000)
2019-02-28 03:02:44 +00:00
2019-09-13 02:22:25 +00:00
unittest.main()