+ added more tests

* fixed chdir home bug
* fixed some tests creating normal data dir
This commit is contained in:
Kevin Froman 2020-03-04 00:59:29 -06:00
parent 665cb0c732
commit 60d2ebfaed
20 changed files with 139 additions and 55 deletions

View file

@ -25,7 +25,10 @@ class OnionrTests(unittest.TestCase):
def test_export(self):
testargs = ["onionr.py", "flowsend", "tests", "hello"]
with patch.object(sys, 'argv', testargs):
parser.register()
try:
parser.register()
except SystemExit:
pass
bl = blockmetadb.get_block_list()[0]
testargs = ["onionr.py", "export-block", bl]
with patch.object(sys, 'argv', testargs):

View file

@ -7,10 +7,13 @@ TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
os.environ["ONIONR_HOME"] = TEST_DIR
print(f'running integration test for {__file__}')
with Popen(['./onionr.sh'], stdout=PIPE) as onionr_proc:
output = onionr_proc.stdout.read().decode()
if onionr_proc.returncode != 0:
raise ValueError('Raised non zero exit ' + str(onionr_proc.returncode))
try:
with Popen(['./onionr.sh'], stdout=PIPE) as onionr_proc:
output = onionr_proc.stdout.read().decode()
except SystemExit:
pass
if onionr_proc.returncode != 10:
raise ValueError('Raised non 10 exit ' + str(onionr_proc.returncode))
if output != '':
if 'Run with --help to see available commands' not in output:
raise ValueError('No command run returned non-blank output')

View file

@ -25,7 +25,10 @@ class OnionrTests(unittest.TestCase):
def test_vanity(self):
testargs = ["onionr.py"]
with patch.object(sys, 'argv', testargs):
parser.register()
try:
parser.register()
except SystemExit:
pass
testargs = ["onionr.py", "add-vanity", "jolt"]
with patch.object(sys, 'argv', testargs):
parser.register()

View file

@ -1 +1 @@
1583020786
1583304780

View file

@ -4,6 +4,10 @@ sys.path.append(".")
sys.path.append("src/")
import unittest, uuid, hashlib
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
import onionrblocks
import onionrstorage
from utils import createdirs
@ -24,7 +28,7 @@ class OnionrBlockTests(unittest.TestCase):
bl = onionrblocks.insert(message)
self.assertTrue(bl.startswith('0'))
self.assertIn(bytesconverter.str_to_bytes(message), onionrstorage.getData(bl))
def test_encrypted_insert(self):
setup_test()
message = 'hello world2'

View file

@ -11,10 +11,6 @@ from onionrcommands import parser
import onionrsetup as setup
from netcontroller.torcontrol import customtorrc
class OnionrTests(unittest.TestCase):
def test_no_command(self):
testargs = ["onionr.py"]
with patch.object(sys, 'argv', testargs):
parser.register()
def test_version_command(self):
testargs = ["onionr.py", "version"]
with patch.object(sys, 'argv', testargs):

View file

@ -0,0 +1,25 @@
#!/usr/bin/env python3
import sys, os
sys.path.append(".")
sys.path.append("src/")
import unittest, uuid
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 identifyhome, createdirs
from onionrsetup import setup_config
from coredb import blockmetadb
from onionrexceptions import BlockMetaEntryExists
createdirs.create_dirs()
setup_config()
class TestDuplicateMetaEntry(unittest.TestCase):
def test_no_duplicate(self):
bl_hash = '0c88c7d4515363310f0a2522706c49f3f21def5f6fd69af1f91a1849239e7ea6'
blockmetadb.add_to_block_DB(bl_hash)
self.assertRaises(
BlockMetaEntryExists, blockmetadb.add_to_block_DB, bl_hash)
unittest.main()

View file

@ -1,7 +1,10 @@
#!/usr/bin/env python3
import sys, os
import sys, os, uuid
sys.path.append(".")
sys.path.append("src/")
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
import unittest, uuid
from utils import identifyhome

View file

@ -1,10 +1,19 @@
#!/usr/bin/env python3
import unittest, sys
import sys, os
sys.path.append(".")
sys.path.append("src/")
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 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()
class TestTimeInsert(unittest.TestCase):
def test_time_insert_none(self):

View file

@ -1,6 +1,10 @@
import sys, os
import uuid
sys.path.append(".")
sys.path.append("src/")
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
import unittest
import vanityonionr

View file

@ -1,5 +1,8 @@
#!/usr/bin/env python3
import unittest, sys
import unittest, sys, uuid, os
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
sys.path.append(".")
sys.path.append("src/")
@ -11,7 +14,7 @@ class ZFill_Hash(unittest.TestCase):
self.assertEqual(reconstructhash.reconstruct_hash(h), b"0000" + h)
h = b"4d20d791cbc293999b97cc627aa011692d317dede3d0fbd390c763210b0d"
self.assertEqual(reconstructhash.reconstruct_hash(h, 62), b"00" + h)
def test_deconstruct(self):
h = b"0000e918d24999ad9b0ff00c1d414f36b74afc93871a0ece4bd452f82b56af87"
h_no = b"e918d24999ad9b0ff00c1d414f36b74afc93871a0ece4bd452f82b56af87"