Onionr/tests/test_database_actions.py

41 lines
1.6 KiB
Python
Raw 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
from urllib.request import pathname2url
2019-07-25 16:14:13 +00:00
from coredb import keydb
from utils import createdirs
createdirs.create_dirs()
2019-02-28 03:02:44 +00:00
class OnionrTests(unittest.TestCase):
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)
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:
self.assertNotIn(address, dbAddresses)
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()