Add more unit tests
parent
cc4687021a
commit
ee59b12238
|
@ -6,5 +6,6 @@ onionr/*.pyc
|
||||||
onionr/*.log
|
onionr/*.log
|
||||||
onionr/data/hs/hostname
|
onionr/data/hs/hostname
|
||||||
onionr/data/*
|
onionr/data/*
|
||||||
|
onionr/data-backup/*
|
||||||
onionr/gnupg/*
|
onionr/gnupg/*
|
||||||
run.sh
|
run.sh
|
||||||
|
|
14
Makefile
14
Makefile
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
sudo pip3 install -r requirements.txt
|
sudo pip3 install -r requirements.txt
|
||||||
sudo rm -rf /usr/share/onionr/
|
|
||||||
sudo rm -f /usr/bin/onionr
|
|
||||||
|
|
||||||
install:
|
install:
|
||||||
|
sudo rm -rf /usr/share/onionr/
|
||||||
|
sudo rm -f /usr/bin/onionr
|
||||||
sudo cp -rp ./onionr /usr/share/onionr
|
sudo cp -rp ./onionr /usr/share/onionr
|
||||||
sudo sh -c "echo \"#!/bin/sh\ncd /usr/share/onionr/\n./onionr.py \\\"\\\$$@\\\"\" > /usr/bin/onionr"
|
sudo sh -c "echo \"#!/bin/sh\ncd /usr/share/onionr/\n./onionr.py \\\"\\\$$@\\\"\" > /usr/bin/onionr"
|
||||||
sudo chmod +x /usr/bin/onionr
|
sudo chmod +x /usr/bin/onionr
|
||||||
|
@ -16,12 +16,14 @@ uninstall:
|
||||||
sudo rm -f /usr/bin/onionr
|
sudo rm -f /usr/bin/onionr
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@cd onionr; ./tests.py
|
@rm -rf onionr/data-backup
|
||||||
|
@mv onionr/data onionr/data-backup | true > /dev/null 2>&1
|
||||||
|
-@cd onionr; ./tests.py
|
||||||
|
@rm -rf onionr/data
|
||||||
|
@mv onionr/data-backup onionr/data | true > /dev/null 2>&1
|
||||||
|
|
||||||
reset:
|
reset:
|
||||||
echo "RESETING ONIONR"
|
|
||||||
rm -f onionr/data/blocks/*.dat | true > /dev/null 2>&1
|
rm -f onionr/data/blocks/*.dat | true > /dev/null 2>&1
|
||||||
rm -f onionr/data/peers.db | true > /dev/null 2>&1
|
rm -f onionr/data/peers.db | true > /dev/null 2>&1
|
||||||
rm -f onionr/data/blocks.db | true > /dev/null 2>&1
|
rm -f onionr/data/blocks.db | true > /dev/null 2>&1
|
||||||
rm -rf onionr/data/address.db | true > /dev/null 2>&1
|
rm -f onionr/data/address.db | true > /dev/null 2>&1
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,10 @@ def set(key, value = None, savefile = False):
|
||||||
'''
|
'''
|
||||||
|
|
||||||
global _config
|
global _config
|
||||||
_config[key] = value
|
if value is None:
|
||||||
|
del _config[key]
|
||||||
|
else:
|
||||||
|
_config[key] = value
|
||||||
|
|
||||||
if savefile:
|
if savefile:
|
||||||
save()
|
save()
|
||||||
|
|
|
@ -173,8 +173,6 @@ def exists(name):
|
||||||
Return value indicates whether or not the plugin exists
|
Return value indicates whether or not the plugin exists
|
||||||
'''
|
'''
|
||||||
|
|
||||||
check()
|
|
||||||
|
|
||||||
return os.path.isdir(get_plugins_folder(str(name).lower()))
|
return os.path.isdir(get_plugins_folder(str(name).lower()))
|
||||||
|
|
||||||
def get_enabled_plugins():
|
def get_enabled_plugins():
|
||||||
|
@ -226,6 +224,11 @@ def check():
|
||||||
|
|
||||||
if not os.path.exists(os.path.dirname(get_plugins_folder())):
|
if not os.path.exists(os.path.dirname(get_plugins_folder())):
|
||||||
logger.debug('Generating plugin data folder...')
|
logger.debug('Generating plugin data folder...')
|
||||||
os.path.mkdirs(os.path.dirname(get_plugins_folder()))
|
os.makedirs(os.path.dirname(get_plugins_folder()))
|
||||||
|
|
||||||
|
if not exists('test'):
|
||||||
|
os.makedirs(get_plugins_folder('test'))
|
||||||
|
with open(get_plugins_folder('test') + '/main.py', 'a') as main:
|
||||||
|
main.write("print('Running')\n\ndef on_test(onionr = None, data = None):\n print('received test event!')\n return True\n\ndef on_start(onionr = None, data = None):\n print('start event called')\n\ndef on_stop(onionr = None, data = None):\n print('stop event called')\n\ndef on_enable(onionr = None, data = None):\n print('enable event called')\n\ndef on_disable(onionr = None, data = None):\n print('disable event called')\n")
|
||||||
|
enable('test')
|
||||||
return
|
return
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
'''
|
'''
|
||||||
import unittest, sys, os, base64, tarfile, shutil, simplecrypt, logger
|
import unittest, sys, os, base64, tarfile, shutil, simplecrypt, logger, btc
|
||||||
|
|
||||||
class OnionrTests(unittest.TestCase):
|
class OnionrTests(unittest.TestCase):
|
||||||
def testPython3(self):
|
def testPython3(self):
|
||||||
|
@ -25,9 +25,9 @@ class OnionrTests(unittest.TestCase):
|
||||||
self.assertTrue(True)
|
self.assertTrue(True)
|
||||||
|
|
||||||
def testNone(self):
|
def testNone(self):
|
||||||
logger.debug('--------------------------')
|
logger.debug('-'*26 + '\n')
|
||||||
logger.info('Running simple program run test...')
|
logger.info('Running simple program run test...')
|
||||||
# Test just running ./onionr with no arguments
|
|
||||||
blank = os.system('./onionr.py --version')
|
blank = os.system('./onionr.py --version')
|
||||||
if blank != 0:
|
if blank != 0:
|
||||||
self.assertTrue(False)
|
self.assertTrue(False)
|
||||||
|
@ -35,8 +35,9 @@ class OnionrTests(unittest.TestCase):
|
||||||
self.assertTrue(True)
|
self.assertTrue(True)
|
||||||
|
|
||||||
def testPeer_a_DBCreation(self):
|
def testPeer_a_DBCreation(self):
|
||||||
logger.debug('--------------------------')
|
logger.debug('-'*26 + '\n')
|
||||||
logger.info('Running peer db creation test...')
|
logger.info('Running peer db creation test...')
|
||||||
|
|
||||||
if os.path.exists('data/peers.db'):
|
if os.path.exists('data/peers.db'):
|
||||||
os.remove('data/peers.db')
|
os.remove('data/peers.db')
|
||||||
import core
|
import core
|
||||||
|
@ -48,8 +49,9 @@ class OnionrTests(unittest.TestCase):
|
||||||
self.assertTrue(False)
|
self.assertTrue(False)
|
||||||
|
|
||||||
def testPeer_b_addPeerToDB(self):
|
def testPeer_b_addPeerToDB(self):
|
||||||
logger.debug('--------------------------')
|
logger.debug('-'*26 + '\n')
|
||||||
logger.info('Running peer db insertion test...')
|
logger.info('Running peer db insertion test...')
|
||||||
|
|
||||||
import core
|
import core
|
||||||
myCore = core.Core()
|
myCore = core.Core()
|
||||||
if not os.path.exists('data/peers.db'):
|
if not os.path.exists('data/peers.db'):
|
||||||
|
@ -62,8 +64,10 @@ class OnionrTests(unittest.TestCase):
|
||||||
def testData_b_Encrypt(self):
|
def testData_b_Encrypt(self):
|
||||||
self.assertTrue(True)
|
self.assertTrue(True)
|
||||||
return
|
return
|
||||||
logger.debug('--------------------------')
|
|
||||||
|
logger.debug('-'*26 + '\n')
|
||||||
logger.info('Running data dir encrypt test...')
|
logger.info('Running data dir encrypt test...')
|
||||||
|
|
||||||
import core
|
import core
|
||||||
myCore = core.Core()
|
myCore = core.Core()
|
||||||
myCore.dataDirEncrypt('password')
|
myCore.dataDirEncrypt('password')
|
||||||
|
@ -75,8 +79,10 @@ class OnionrTests(unittest.TestCase):
|
||||||
def testData_a_Decrypt(self):
|
def testData_a_Decrypt(self):
|
||||||
self.assertTrue(True)
|
self.assertTrue(True)
|
||||||
return
|
return
|
||||||
logger.debug('--------------------------')
|
|
||||||
|
logger.debug('-'*26 + '\n')
|
||||||
logger.info('Running data dir decrypt test...')
|
logger.info('Running data dir decrypt test...')
|
||||||
|
|
||||||
import core
|
import core
|
||||||
myCore = core.Core()
|
myCore = core.Core()
|
||||||
myCore.dataDirDecrypt('password')
|
myCore.dataDirDecrypt('password')
|
||||||
|
@ -85,9 +91,42 @@ class OnionrTests(unittest.TestCase):
|
||||||
else:
|
else:
|
||||||
self.assertTrue(False)
|
self.assertTrue(False)
|
||||||
|
|
||||||
def testPlugins(self):
|
def testConfig(self):
|
||||||
logger.debug('--------------------------')
|
logger.debug('-'*26 + '\n')
|
||||||
logger.info('Running simple plugin system test...')
|
logger.info('Running simple configuration test...')
|
||||||
|
|
||||||
|
import config
|
||||||
|
|
||||||
|
config.check()
|
||||||
|
config.reload()
|
||||||
|
configdata = str(config.get_config())
|
||||||
|
|
||||||
|
config.set('testval', 1337)
|
||||||
|
if not config.get('testval', None) is 1337:
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
||||||
|
config.set('testval')
|
||||||
|
if not config.get('testval', None) is None:
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
||||||
|
config.save()
|
||||||
|
config.reload()
|
||||||
|
|
||||||
|
if not str(config.get_config()) == configdata:
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
||||||
|
self.assertTrue(True)
|
||||||
|
|
||||||
|
def testBitcoinNode(self):
|
||||||
|
logger.debug('-'*26 + '\n')
|
||||||
|
logger.info('Running bitcoin node test...')
|
||||||
|
|
||||||
|
sbitcoin = btc.OnionrBTC()
|
||||||
|
|
||||||
|
def testPluginReload(self):
|
||||||
|
logger.debug('-'*26 + '\n')
|
||||||
|
logger.info('Running simple plugin reload test...')
|
||||||
|
|
||||||
import onionrplugins
|
import onionrplugins
|
||||||
try:
|
try:
|
||||||
onionrplugins.reload('test')
|
onionrplugins.reload('test')
|
||||||
|
@ -95,9 +134,36 @@ class OnionrTests(unittest.TestCase):
|
||||||
except:
|
except:
|
||||||
self.assertTrue(False)
|
self.assertTrue(False)
|
||||||
|
|
||||||
|
def testPluginStopStart(self):
|
||||||
|
logger.debug('-'*26 + '\n')
|
||||||
|
logger.info('Running simple plugin restart test...')
|
||||||
|
|
||||||
|
import onionrplugins
|
||||||
|
try:
|
||||||
|
onionrplugins.start('test')
|
||||||
|
onionrplugins.stop('test')
|
||||||
|
self.assertTrue(True)
|
||||||
|
except:
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
||||||
|
def testPluginEvent(self):
|
||||||
|
logger.debug('-'*26 + '\n')
|
||||||
|
logger.info('Running plugin event test...')
|
||||||
|
|
||||||
|
import onionrplugins as plugins, onionrevents as events
|
||||||
|
|
||||||
|
plugins.start('test')
|
||||||
|
if not events.call(plugins.get_plugin('test'), 'test'):
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
||||||
|
events.event('test', data = {'tests': self})
|
||||||
|
|
||||||
|
self.assertTrue(True)
|
||||||
|
|
||||||
def testQueue(self):
|
def testQueue(self):
|
||||||
logger.debug('--------------------------')
|
logger.debug('-'*26 + '\n')
|
||||||
logger.info('Running daemon queue test...')
|
logger.info('Running daemon queue test...')
|
||||||
|
|
||||||
# test if the daemon queue can read/write data
|
# test if the daemon queue can read/write data
|
||||||
import core
|
import core
|
||||||
myCore = core.Core()
|
myCore = core.Core()
|
||||||
|
@ -117,8 +183,9 @@ class OnionrTests(unittest.TestCase):
|
||||||
logger.info('Succesfully added and read command')
|
logger.info('Succesfully added and read command')
|
||||||
|
|
||||||
def testHashValidation(self):
|
def testHashValidation(self):
|
||||||
logger.debug('--------------------------')
|
logger.debug('-'*26 + '\n')
|
||||||
logger.info('Running hash validation test...')
|
logger.info('Running hash validation test...')
|
||||||
|
|
||||||
import core
|
import core
|
||||||
myCore = core.Core()
|
myCore = core.Core()
|
||||||
if not myCore._utils.validateHash("$324dfgfdg") and myCore._utils.validateHash("f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2") and not myCore._utils.validateHash("f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd$"):
|
if not myCore._utils.validateHash("$324dfgfdg") and myCore._utils.validateHash("f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2") and not myCore._utils.validateHash("f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd$"):
|
||||||
|
@ -127,8 +194,9 @@ class OnionrTests(unittest.TestCase):
|
||||||
self.assertTrue(False)
|
self.assertTrue(False)
|
||||||
|
|
||||||
def testAddAdder(self):
|
def testAddAdder(self):
|
||||||
logger.debug('--------------------------')
|
logger.debug('-'*26 + '\n')
|
||||||
logger.info('Running address add+remove test')
|
logger.info('Running address add+remove test')
|
||||||
|
|
||||||
import core
|
import core
|
||||||
myCore = core.Core()
|
myCore = core.Core()
|
||||||
if not os.path.exists('data/address.db'):
|
if not os.path.exists('data/address.db'):
|
||||||
|
@ -140,4 +208,5 @@ class OnionrTests(unittest.TestCase):
|
||||||
self.assertTrue(False)
|
self.assertTrue(False)
|
||||||
else:
|
else:
|
||||||
self.assertTrue(False)
|
self.assertTrue(False)
|
||||||
|
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in New Issue