2015-09-20 00:27:54 +02:00
|
|
|
import os
|
2016-11-07 22:42:27 +01:00
|
|
|
import cStringIO as StringIO
|
2015-09-20 00:27:54 +02:00
|
|
|
|
|
|
|
from Config import config
|
|
|
|
from Db import Db
|
|
|
|
|
|
|
|
|
|
|
|
class TestDb:
|
2016-11-07 22:42:27 +01:00
|
|
|
def testCheckTables(self, db):
|
2015-09-20 00:27:54 +02:00
|
|
|
tables = [row["name"] for row in db.execute("SELECT name FROM sqlite_master WHERE type='table'")]
|
|
|
|
assert "keyvalue" in tables # To store simple key -> value
|
|
|
|
assert "json" in tables # Json file path registry
|
|
|
|
assert "test" in tables # The table defined in dbschema.json
|
|
|
|
|
|
|
|
# Verify test table
|
|
|
|
cols = [col["name"] for col in db.execute("PRAGMA table_info(test)")]
|
|
|
|
assert "test_id" in cols
|
|
|
|
assert "title" in cols
|
|
|
|
|
2015-11-05 23:19:36 +01:00
|
|
|
# Add new table
|
|
|
|
assert "newtest" not in tables
|
|
|
|
db.schema["tables"]["newtest"] = {
|
|
|
|
"cols": [
|
|
|
|
["newtest_id", "INTEGER"],
|
|
|
|
["newtitle", "TEXT"],
|
|
|
|
],
|
|
|
|
"indexes": ["CREATE UNIQUE INDEX newtest_id ON newtest(newtest_id)"],
|
|
|
|
"schema_changed": 1426195822
|
|
|
|
}
|
|
|
|
db.checkTables()
|
|
|
|
tables = [row["name"] for row in db.execute("SELECT name FROM sqlite_master WHERE type='table'")]
|
|
|
|
assert "test" in tables
|
|
|
|
assert "newtest" in tables
|
|
|
|
|
2016-11-07 22:42:27 +01:00
|
|
|
def testQueries(self, db):
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
# Test insert
|
|
|
|
for i in range(100):
|
|
|
|
db.execute("INSERT INTO test ?", {"test_id": i, "title": "Test #%s" % i})
|
|
|
|
|
|
|
|
assert db.execute("SELECT COUNT(*) AS num FROM test").fetchone()["num"] == 100
|
|
|
|
|
|
|
|
# Test single select
|
|
|
|
assert db.execute("SELECT COUNT(*) AS num FROM test WHERE ?", {"test_id": 1}).fetchone()["num"] == 1
|
|
|
|
|
|
|
|
# Test multiple select
|
2016-11-07 22:42:27 +01:00
|
|
|
assert db.execute("SELECT COUNT(*) AS num FROM test WHERE ?", {"test_id": [1, 2, 3]}).fetchone()["num"] == 3
|
|
|
|
assert db.execute(
|
|
|
|
"SELECT COUNT(*) AS num FROM test WHERE ?",
|
|
|
|
{"test_id": [1, 2, 3], "title": "Test #2"}
|
|
|
|
).fetchone()["num"] == 1
|
|
|
|
assert db.execute(
|
|
|
|
"SELECT COUNT(*) AS num FROM test WHERE ?",
|
|
|
|
{"test_id": [1, 2, 3], "title": ["Test #2", "Test #3", "Test #4"]}
|
|
|
|
).fetchone()["num"] == 2
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
|
Version 0.3.5, Rev830, Full Tor mode support with hidden services, Onion stats in Sidebar, GeoDB download fix using Tor, Gray out disabled sites in Stats page, Tor hidden service status in stat page, Benchmark sha256, Skyts tracker out expodie in, 2 new tracker using ZeroNet protocol, Keep SSL cert option between restarts, SSL Certificate pinning support for connections, Site lock support for connections, Certificate pinned connections using implicit SSL, Flood protection whitelist support, Foreign keys support for DB layer, Not support for SQL query helper, 0 length file get bugfix, Pex onion address support, Faster port testing, Faster uPnP port opening, Need connections more often on owned sites, Delay ZeroHello startup message if port check or Tor manager not ready yet, Use lockfiles to avoid double start, Save original socket on proxy monkey patching to get ability to connect localhost directly, Handle atomic write errors, Broken gevent https workaround helper, Rsa crypt functions, Plugin to Bootstrap using ZeroNet protocol
2016-01-05 00:20:52 +01:00
|
|
|
# Test named parameter escaping
|
2016-11-07 22:42:27 +01:00
|
|
|
assert db.execute(
|
|
|
|
"SELECT COUNT(*) AS num FROM test WHERE test_id = :test_id AND title LIKE :titlelike",
|
|
|
|
{"test_id": 1, "titlelike": "Test%"}
|
|
|
|
).fetchone()["num"] == 1
|
|
|
|
|
2017-02-09 01:53:31 +01:00
|
|
|
def testUpdateJson(self, db):
|
2016-11-07 22:42:27 +01:00
|
|
|
f = StringIO.StringIO()
|
|
|
|
f.write("""
|
|
|
|
{
|
|
|
|
"test": [
|
|
|
|
{"test_id": 1, "title": "Test 1 title", "extra col": "Ignore it"}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
""")
|
|
|
|
f.seek(0)
|
2017-02-09 01:53:31 +01:00
|
|
|
assert db.updateJson(db.db_dir + "data.json", f) == True
|
2016-11-07 22:42:27 +01:00
|
|
|
assert db.execute("SELECT COUNT(*) AS num FROM test_importfilter").fetchone()["num"] == 1
|
|
|
|
assert db.execute("SELECT COUNT(*) AS num FROM test").fetchone()["num"] == 1
|