Added missing tests and sidebar files

This commit is contained in:
Kevin 2020-08-04 22:35:45 -05:00
parent ab10cea8b6
commit 5930f3bfad
6 changed files with 125 additions and 2 deletions

View File

@ -11,9 +11,12 @@
<link rel="stylesheet" href="/private/main.css">
<link rel="stylesheet" href="/shared/fontawesome-free-5.10.2/css/all.min.css">
<link rel="stylesheet" href="/shared/main/PNotifyBrightTheme.css">
<link rel="stylesheet" href="/shared/bulma-quickview.min.css">
<link rel="stylesheet" href="/gettheme">
<link rel="stylesheet" href="/shared/sidebar/sidebar.css">
<script defer src="/shared/node_modules/pnotify/dist/iife/PNotify.js"></script>
<script defer src="/shared/node_modules/pnotify/dist/iife/PNotifyButtons.js"></script>
<script defer src="/shared/bulma-quickview.js"></script>
<script defer src="/shared/eventsource.js"></script>
<script defer src="/shared/main/particles.js"></script>
<script defer src="/shared/loadabout.js"></script>
@ -30,6 +33,7 @@
<script defer src="/private/js/motd.js"></script>
<script defer src="/shared/navbar.js"></script>
<script defer src="/private/js/windows.js"></script>
<script defer src="/shared/sidebar/sidebar.js"></script>
<script defer src="/shared/main/loadTransport.js"></script>
<script>alert("Content security policy appears to not be working. Your browser security is weak!")</script>
</head>
@ -41,7 +45,7 @@
<p>If you are using random bind IPs (default in non dev mode), Onionr will have a different URL next time.</p>
</div>
</div>
<span id="sidebarContainer"></span>
<nav class="navbar is-dark" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<a class="navbar-item idLink" href="/">
@ -202,7 +206,7 @@
</div>
</div>
</div>
</div>
<div class="columns">
<div class="column">

View File

@ -0,0 +1,17 @@
<div id="quickviewDefault" class="quickview">
<header class="quickview-header">
<p class="title">Quickview title</p>
<span class="delete" data-dismiss="quickview"></span>
</header>
<div class="quickview-body">
<div class="quickview-block">
...
</div>
</div>
<footer class="quickview-footer">
</footer>
</div>
<button class="button is-primary is-hidden sidebarBtn" data-show="quickview" data-target="quickviewDefault">Show quickview</button>

View File

@ -0,0 +1,18 @@
fetch('/shared/sidebar/sidebar.html', {
"method": "get",
headers: {
"token": webpass
}})
.then((resp) => resp.text())
.then(function(resp) {
document.getElementById('sidebarContainer').innerHTML = resp
})
window.addEventListener("keydown", function(event) {
if (event.key === "s"){
let quickviews = bulmaQuickview.attach()
document.getElementsByClassName('sidebarBtn')[0].click()
}
}, true)

View File

@ -0,0 +1,39 @@
#!/usr/bin/env python3
import sys, os
sys.path.append(".")
sys.path.append("src/")
import unittest, uuid
from time import sleep
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 networkmerger
from coredb import keydb
import onionrsetup as setup
from utils import createdirs
from onionrthreads import add_onionr_thread
createdirs.create_dirs()
setup.setup_config()
class OnionrThreadsTests(unittest.TestCase):
def test_onionr_thread(self):
l = []
def _test_func(obj_list):
obj_list.append(1)
add_onionr_thread(_test_func, (l,), 0.05, 0)
sleep(0.05)
self.assertGreaterEqual(len(l), 1)
def test_onionr_thread_initial_sleep(self):
l = []
def _test_func(obj_list):
obj_list.append(1)
add_onionr_thread(_test_func, (l,), 0.05, 0.1)
sleep(0.06)
self.assertEqual(len(l), 0)
unittest.main()

45
tests/test_setupkvvars.py Normal file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env python3
import sys, os
sys.path.append(".")
sys.path.append("src/")
import unittest, uuid
import time
import math
from deadsimplekv import DeadSimpleKV
import setupkvvars
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 networkmerger
from coredb import keydb
import onionrsetup as setup
from utils import createdirs
createdirs.create_dirs()
setup.setup_config()
class SetupKVVarsTest(unittest.TestCase):
def test_set_var_values(self):
kv = DeadSimpleKV()
setupkvvars.setup_kv(kv)
self.assertEqual(kv.get('blockQueue'), {})
self.assertFalse(kv.get('shutdown'))
self.assertEqual(kv.get('onlinePeers'), [])
self.assertEqual(kv.get('offlinePeers'), [])
self.assertEqual(kv.get('peerProfiles'), [])
self.assertEqual(kv.get('connectTimes'), {})
self.assertEqual(kv.get('currentDownloading'), [])
self.assertEqual(kv.get('announceCache'), {})
self.assertEqual(kv.get('newPeers'), [])
self.assertEqual(kv.get('dbTimestamps'), {})
self.assertEqual(kv.get('blocksToUpload'), [])
self.assertEqual(kv.get('cooldownPeer'), {})
self.assertEqual(kv.get('generating_blocks'), [])
self.assertEqual(kv.get('lastNodeSeen'), None)
self.assertAlmostEqual(math.floor(kv.get('startTime')), math.floor(time.time()), places=0)
self.assertTrue(kv.get('isOnline'))
unittest.main()